1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

rc: Add commands to set GC Percent & Memory Limit (1.19+)

Signed-off-by: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com>
This commit is contained in:
Anagh Kumar Baranwal
2022-10-27 16:46:31 +05:30
committed by Nick Craig-Wood
parent 617c5d5e1b
commit 0c56c46523
4 changed files with 131 additions and 3 deletions

12
lib/debug/common.go Normal file
View File

@@ -0,0 +1,12 @@
// Package debug contains functions for dealing with runtime/debug functions across go versions
package debug
import (
"runtime/debug"
)
// SetGCPercent calls the runtime/debug.SetGCPercent function to set the garbage
// collection percentage.
func SetGCPercent(percent int) int {
return debug.SetGCPercent(percent)
}

14
lib/debug/go1.19.go Normal file
View File

@@ -0,0 +1,14 @@
//go:build go1.19
// +build go1.19
package debug
import (
"runtime/debug"
)
// SetMemoryLimit calls the runtime/debug.SetMemoryLimit function to set the
// soft-memory limit.
func SetMemoryLimit(limit int64) (int64, error) {
return debug.SetMemoryLimit(limit), nil
}

View File

@@ -0,0 +1,14 @@
//go:build !go1.19
// +build !go1.19
package debug
import (
"fmt"
"runtime"
)
// SetMemoryLimit is a no-op on Go version < 1.19.
func SetMemoryLimit(limit int64) (int64, error) {
return limit, fmt.Errorf("not implemented on Go version below 1.19: %s", runtime.Version())
}