Go GC Settings Bryan Boreham (@bboreham) Hi, Im Bryan Boreham At - - PowerPoint PPT Presentation
Go GC Settings Bryan Boreham (@bboreham) Hi, Im Bryan Boreham At - - PowerPoint PPT Presentation
Go GC Settings Bryan Boreham (@bboreham) Hi, Im Bryan Boreham At Weaveworks, I work on Open Source DevOps tools doing system visualisation, monitoring and CI/CD I also contribute to Container Network Interface, Kubernetes, Prometheus
SLIDE 1
SLIDE 2
At Weaveworks, I work on Open Source DevOps tools doing system visualisation, monitoring and CI/CD I also contribute to Container Network Interface, Kubernetes, Prometheus Program optimisation is my video-game.
Hi, I’m Bryan Boreham
2
@bboreham
SLIDE 3
Why care about Garbage?
3
https://www.redbubble.com/people/clgtart/
(this is the point where Bryan moans about never having enough RAM)
SLIDE 4
CPU memory architecture
4
CPU RAM RAM Level 2 Cache Level 1 Cache
(Not to scale)
Logic
SLIDE 5
Caches in use
5
CPU RAM RAM Level 2 Cache Level 1 Cache Logic
SLIDE 6
After GC has run
6
CPU RAM RAM Level 2 Cache Level 1 Cache Logic
SLIDE 7
Stack vs Heap
7
http://www.clipartpanda.com/clipart_images/stack-files-max-39545601 Photo: JohnNyberg, rgbstock.com
SLIDE 8
GC Options
8
- Xmsn
- Xmxn
- XX:-UseConcMarkSweepGC
- XX:-UseParallelGC
- XX:-UseParallelOldGC
- XX:-UseSerialGC
- XX:+UseG1GC
- XX:+UseGCOverheadLimit
- XX:MaxGCPauseMillis=n
- XX:InitiatingHeapOccupancyPercent=n
- XX:MaxTenuringThreshold=n
- XX:+ScavengeBeforeFullGC
- XX:ParallelGCThreads=n
- XX:ConcGCThreads=n
- XX:G1ReservePercent=n
- XX:G1HeapRegionSize=n
- XX:MaxHeapFreeRatio=n
- XX:MaxNewSize=size
- XX:MaxPermSize=n
- XX:MinHeapFreeRatio=n
- XX:NewSize=n
- XX:NewRatio=n
- XX:SurvivorRatio=n
- XX:TargetSurvivorRatio=n
- XX:+HandlePromotionFailure
SLIDE 9
GOGC
Go GC Options
9
SLIDE 10
Server: github.com/stefanprodan/k8s-podinfo
- microservice skeleton
Client: github.com/rakyll/hey
- HTTP load generator
hey -z 2m -c 10 -q 20 ".../metrics"
Test set-up
10
SLIDE 11
Situation: large stable data set
11
SLIDE 12
(at the cost of CPU)
Lower GOGC to save RAM
12
SLIDE 13
Situation: high GC rate, small heap
13
SLIDE 14
Raise GOGC to save CPU
14
SLIDE 15
GOGC=1000
15
SLIDE 16
What’s happening here? (no load, GOGC=100)
16
SLIDE 17
/usr/local/go/src/runtime/proc.go line 4310(!): // If we go this long without a garbage collection, // one is forced to run. var forcegcperiod int64 = 2 * 60 * 1e9
There is another setting!
17
SLIDE 18
GOGC=off
What if we turn off GC completely?
18
SLIDE 19
$ go clean -cache $ time go build real 0m7.331s user 0m12.152s sys 0m0.660s
Building podinfo
19
$ go clean -cache $ export GOGC=off $ time go build real 0m5.412s user 0m8.460s sys 0m0.704s
SLIDE 20
SetMaxHeap GOGCMIN
The future?
20
https://twitter.com/ashleymcnamara
SLIDE 21
THANK YOU!
21
https://twitter.com/ashleymcnamara
@bboreham
SLIDE 22
More information
22