From af75456193f519f83f0eb5bfdc97c4530dc03244 Mon Sep 17 00:00:00 2001 From: foram-splunk Date: Tue, 27 Sep 2022 15:53:00 +0530 Subject: [PATCH 1/2] Added support for memory ballast --- README.md | 1 + main.go | 5 +++++ splunknozzle/config.go | 3 +++ splunknozzle/config_test.go | 9 +++++++++ tile/tile.yml | 5 +++++ 5 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 5782d279..6bb3320e 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ This is recommended for dev environments only. * `SELECTED_MONITORING_METRICS`: Name of the metrics that you want to monitor and add using comma seprated values. List of the metrics that are supported in the metrics modules are given below * `REFRESH_SPLUNK_CONNECTION`: If set to true, PCF will periodically refresh connection to Splunk (how often depends on KEEP_ALIVE_TIMER value). If set to false connection will be kept alive and reused. (Default: false) * `KEEP_ALIVE_TIMER`: Time after which connection to Splunk will be refreshed, if REFRESH_SPLUNK_CONNECTION is set to true (in s/m/h. For example, 3600s or 60m or 1h). (Default: 30s) +* `MEMORY_BALLAST_SIZE`: Size of memory allocated to reduce GC cycles. Default is 0, Size should be less than the total memory. __About app cache params:__ diff --git a/main.go b/main.go index b14ea70a..5998208b 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,11 @@ func main() { signal.Notify(shutdownChan, syscall.SIGINT, syscall.SIGTERM) config := splunknozzle.NewConfigFromCmdFlags(version, branch, commit, buildos) + if config.MemoryBallastSize > 0 { + ballast := make([]byte, config.MemoryBallastSize<<20) + _ = ballast + } + if config.AppCacheTTL == 0 && config.OrgSpaceCacheTTL > 0 { logger.Info("Apps are not being cached. When apps are not cached, the org and space caching TTL is ineffective") } diff --git a/splunknozzle/config.go b/splunknozzle/config.go index d0ec491f..32e823d3 100644 --- a/splunknozzle/config.go +++ b/splunknozzle/config.go @@ -60,6 +60,7 @@ type Config struct { StatusMonitorInterval time.Duration `json:"mem-queue-monitor-interval"` SelectedMonitoringMetrics string `json:"selected-monitoring-metrics"` SplunkMetricIndex string `json:"splunk-metric-index"` + MemoryBallastSize int `json:"memory-ballast-size"` } func NewConfigFromCmdFlags(version, branch, commit, buildos string) *Config { @@ -150,6 +151,8 @@ func NewConfigFromCmdFlags(version, branch, commit, buildos string) *Config { OverrideDefaultFromEnvar("SELECTED_MONITORING_METRICS").Default("nozzle.queue.percentage,splunk.events.dropped.count,splunk.events.sent.count,firehose.events.dropped.count,firehose.events.received.count,splunk.events.throughput,nozzle.usage.ram,nozzle.usage.cpu,nozzle.cache.memory.hit,nozzle.cache.memory.miss,nozzle.cache.remote.hit,nozzle.cache.remote.miss,nozzle.cache.boltdb.hit,nozzle.cache.boltdb.miss").StringVar(&c.SelectedMonitoringMetrics) kingpin.Flag("splunk-metric-index", "Splunk metric index"). OverrideDefaultFromEnvar("SPLUNK_METRIC_INDEX").StringVar(&c.SplunkMetricIndex) + kingpin.Flag("memory-ballast-size", "Size of ballast in MB"). + OverrideDefaultFromEnvar("MEMORY_BALLAST_SIZE").Default("0").IntVar(&c.MemoryBallastSize) kingpin.Parse() c.ApiEndpoint = strings.TrimSpace(c.ApiEndpoint) diff --git a/splunknozzle/config_test.go b/splunknozzle/config_test.go index 13ae0efc..08ca1c90 100644 --- a/splunknozzle/config_test.go +++ b/splunknozzle/config_test.go @@ -65,6 +65,7 @@ var _ = Describe("Config", func() { os.Setenv("ENABLE_EVENT_TRACING", "true") os.Setenv("DEBUG", "true") os.Setenv("DROP_WARN_THRESHOLD", "100") + os.Setenv("MEMORY_BALLAST_SIZE", "512") c := NewConfigFromCmdFlags(version, branch, commit, buildos) @@ -110,6 +111,8 @@ var _ = Describe("Config", func() { Expect(c.TraceLogging).To(BeTrue()) Expect(c.Debug).To(BeTrue()) + Expect(c.DropWarnThreshold).To(Equal(100)) + Expect(c.MemoryBallastSize).To(Equal(512)) }) It("check defaults", func() { @@ -141,6 +144,8 @@ var _ = Describe("Config", func() { Expect(c.TraceLogging).To(BeFalse()) Expect(c.Debug).To(BeFalse()) + Expect(c.DropWarnThreshold).To(Equal(1000)) + Expect(c.MemoryBallastSize).To(Equal(0)) }) }) @@ -187,6 +192,7 @@ var _ = Describe("Config", func() { "--enable-event-tracing", "--debug", "--splunk-metric-index=metric", + "--memory-ballast-size=512", } os.Args = args }) @@ -230,6 +236,9 @@ var _ = Describe("Config", func() { Expect(c.Debug).To(BeTrue()) Expect(c.TraceLogging).To(BeTrue()) + Expect(c.DropWarnThreshold).To(Equal(10)) + Expect(c.MemoryBallastSize).To(Equal(512)) + Expect(c.Version).To(Equal(version)) Expect(c.Branch).To(Equal(branch)) Expect(c.Commit).To(Equal(commit)) diff --git a/tile/tile.yml b/tile/tile.yml index a6bd763e..b71144e2 100644 --- a/tile/tile.yml +++ b/tile/tile.yml @@ -272,6 +272,11 @@ forms: label: Keep alive timer description: Interval used to close and refresh connection to Splunk optional: true + - name: memory_ballast_size + type: integer + label: Memory Ballast Size + default: 0 + description: Size of memory allocated to reduce GC cycles. Default is 0, Size should be less than the total memory. migration: | if (typeof properties['properties']['.properties.add_app_info']['value'] == "boolean") { From a432116ec5a24c336c5f32aa805d3bacd4fbea2b Mon Sep 17 00:00:00 2001 From: sbylica-splunk Date: Tue, 9 Apr 2024 09:55:19 +0200 Subject: [PATCH 2/2] Fix --- splunknozzle/config_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/splunknozzle/config_test.go b/splunknozzle/config_test.go index 08ca1c90..bc37869f 100644 --- a/splunknozzle/config_test.go +++ b/splunknozzle/config_test.go @@ -111,7 +111,6 @@ var _ = Describe("Config", func() { Expect(c.TraceLogging).To(BeTrue()) Expect(c.Debug).To(BeTrue()) - Expect(c.DropWarnThreshold).To(Equal(100)) Expect(c.MemoryBallastSize).To(Equal(512)) }) @@ -144,7 +143,6 @@ var _ = Describe("Config", func() { Expect(c.TraceLogging).To(BeFalse()) Expect(c.Debug).To(BeFalse()) - Expect(c.DropWarnThreshold).To(Equal(1000)) Expect(c.MemoryBallastSize).To(Equal(0)) }) }) @@ -236,7 +234,6 @@ var _ = Describe("Config", func() { Expect(c.Debug).To(BeTrue()) Expect(c.TraceLogging).To(BeTrue()) - Expect(c.DropWarnThreshold).To(Equal(10)) Expect(c.MemoryBallastSize).To(Equal(512)) Expect(c.Version).To(Equal(version))