Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rc: Add commands to set GC Percent & Memory Limit (1.19+)
Signed-off-by: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com>
- Loading branch information
1 parent
617c5d5
commit 0c56c46
Showing
4 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} |