Skip to content

Commit 94159d3

Browse files
committed
Set Go garbage collection target percentage to 400%
After removal of memory_ballast extension in v0.97.0, the Go garbage collection is running more aggressively, which increased CPU usage and leads to reduced throughput of the collector. This change reduces the frequency of garbage collection cycles to improves performance of the collector for typical workloads. As a result, the collector will report higher memory usage, but it will be bound to the same configured limits. If you want to revert to the previous behavior, set the `GOGC` environment variable to `100`.
1 parent a43ec90 commit 94159d3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Unreleased
44

5+
### 💡 Enhancements 💡
6+
7+
- (Splunk) Set Go garbage collection target percentage to 400% ([#5034](https://github.com/signalfx/splunk-otel-collector/pull/5034))
8+
After removal of memory_ballast extension in v0.97.0, the Go garbage collection is running more aggressively, which
9+
increased CPU usage and leads to reduced throughput of the collector. This change reduces the frequency of garbage
10+
collection cycles to improves performance of the collector for typical workloads. As a result, the collector will
11+
report higher memory usage, but it will be bound to the same configured limits. If you want to revert to the previous
12+
behavior, set the `GOGC` environment variable to `100`.
13+
514
### 🧰 Bug fixes 🧰
615

716
- (Splunk) `receiver/discovery`: Do not emit entity events for discovered endpoints that are not evaluated yet

internal/settings/settings.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
HecLogIngestURLEnvVar = "SPLUNK_HEC_URL"
4444
ListenInterfaceEnvVar = "SPLUNK_LISTEN_INTERFACE"
4545
GoMemLimitEnvVar = "GOMEMLIMIT"
46+
GoGCEnvVar = "GOGC"
4647
// nolint:gosec
4748
HecTokenEnvVar = "SPLUNK_HEC_TOKEN" // this isn't a hardcoded token
4849
IngestURLEnvVar = "SPLUNK_INGEST_URL"
@@ -59,6 +60,7 @@ const (
5960

6061
DefaultMemoryLimitPercentage = 90
6162
DefaultMemoryTotalMiB = 512
63+
DefaultGoGC = 400
6264
DefaultListenInterface = "0.0.0.0"
6365
DefaultAgentConfigLinux = "/etc/otel/collector/agent_config.yaml"
6466
featureGates = "feature-gates"
@@ -371,6 +373,11 @@ func checkRuntimeParams(settings *Settings) error {
371373
setSoftMemoryLimit(memTotalSize)
372374
}
373375

376+
if _, ok := os.LookupEnv(GoGCEnvVar); !ok {
377+
debug.SetGCPercent(DefaultGoGC)
378+
log.Printf("Set garbage collection target percentage (GOGC) to %d", DefaultGoGC)
379+
}
380+
374381
return nil
375382
}
376383

0 commit comments

Comments
 (0)