Skip to content

Commit

Permalink
Added support for memory ballast (#327)
Browse files Browse the repository at this point in the history
* Added support for memory ballast

---------

Co-authored-by: sbylica-splunk <[email protected]>
  • Loading branch information
foram-splunk and sbylica-splunk authored Apr 12, 2024
1 parent d926f37 commit 7a8d95e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:__

Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
3 changes: 3 additions & 0 deletions splunknozzle/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions splunknozzle/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -110,6 +111,7 @@ var _ = Describe("Config", func() {

Expect(c.TraceLogging).To(BeTrue())
Expect(c.Debug).To(BeTrue())
Expect(c.MemoryBallastSize).To(Equal(512))
})

It("check defaults", func() {
Expand Down Expand Up @@ -141,6 +143,7 @@ var _ = Describe("Config", func() {

Expect(c.TraceLogging).To(BeFalse())
Expect(c.Debug).To(BeFalse())
Expect(c.MemoryBallastSize).To(Equal(0))
})
})

Expand Down Expand Up @@ -187,6 +190,7 @@ var _ = Describe("Config", func() {
"--enable-event-tracing",
"--debug",
"--splunk-metric-index=metric",
"--memory-ballast-size=512",
}
os.Args = args
})
Expand Down Expand Up @@ -230,6 +234,8 @@ var _ = Describe("Config", func() {

Expect(c.Debug).To(BeTrue())
Expect(c.TraceLogging).To(BeTrue())
Expect(c.MemoryBallastSize).To(Equal(512))

Expect(c.Version).To(Equal(version))
Expect(c.Branch).To(Equal(branch))
Expect(c.Commit).To(Equal(commit))
Expand Down
5 changes: 5 additions & 0 deletions tile/tile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 7a8d95e

Please sign in to comment.