-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main: Tweak runtime GC params for Go 1.19.
Go 1.19 introduced the ability to specify a soft upper memory limit to help deal with transient memory spikes without needing to set the GC percent to an artificially low value. This takes advantage of that to impose an upper memory limit that leaves plenty of headroom for the minimum recommended value while taking into account the max utxo cache size configuration option and increase the GC percent to the default value of 100% which allows the mem usage to expand more in between each GC cycle which in turn significantly reduces the number of GC cycles that need to be performed, particularly while performing the initial chain sync. The end result is much less CPU time spent doing garbage collection and thus reduces the amount of time it takes to perform the initial chain sync by about 10%. The update also has the nice side benefit that the `GOGC` environment variable can be used if an advanced sysadmin really wanted to tune it since it is no longer being overridden.
- Loading branch information
Showing
5 changed files
with
85 additions
and
7 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
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,20 @@ | ||
// Copyright (c) 2022 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.19 | ||
// +build go1.19 | ||
|
||
package limits | ||
|
||
import "runtime/debug" | ||
|
||
// SupportsMemoryLimit indicates that a runtime enforced soft memory limit is | ||
// supported starting with Go 1.19. | ||
const SupportsMemoryLimit = true | ||
|
||
// SetMemoryLimit configures the runtime to use the provided limit as a soft | ||
// memory limit starting with Go 1.19. | ||
func SetMemoryLimit(limit int64) { | ||
debug.SetMemoryLimit(limit) | ||
} |
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,17 @@ | ||
// Copyright (c) 2022 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build !go1.19 | ||
// +build !go1.19 | ||
|
||
package limits | ||
|
||
// SupportsMemoryLimit indicates that a runtime enforced soft memory limit is | ||
// not supported for versions of Go prior to version 1.19. | ||
const SupportsMemoryLimit = false | ||
|
||
// SetMemoryLimit is a no-op on versions of Go prior to version 1.19 since the | ||
// the ability is not supported on those versions. | ||
func SetMemoryLimit(_ int64) { | ||
} |
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