Go GC Settings Bryan Boreham (@bboreham) Hi, Im Bryan Boreham At - - PowerPoint PPT Presentation

go gc settings
SMART_READER_LITE
LIVE PREVIEW

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 1

Go GC Settings

Bryan Boreham (@bboreham)

slide-2
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
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
SLIDE 4

CPU memory architecture

4

CPU RAM RAM Level 2 Cache Level 1 Cache

(Not to scale)

Logic

slide-5
SLIDE 5

Caches in use

5

CPU RAM RAM Level 2 Cache Level 1 Cache Logic

slide-6
SLIDE 6

After GC has run

6

CPU RAM RAM Level 2 Cache Level 1 Cache Logic

slide-7
SLIDE 7

Stack vs Heap

7

http://www.clipartpanda.com/clipart_images/stack-files-max-39545601 Photo: JohnNyberg, rgbstock.com

slide-8
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
SLIDE 9

GOGC

Go GC Options

9

slide-10
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
SLIDE 11

Situation: large stable data set

11

slide-12
SLIDE 12

(at the cost of CPU)

Lower GOGC to save RAM

12

slide-13
SLIDE 13

Situation: high GC rate, small heap

13

slide-14
SLIDE 14

Raise GOGC to save CPU

14

slide-15
SLIDE 15

GOGC=1000

15

slide-16
SLIDE 16

What’s happening here? (no load, GOGC=100)

16

slide-17
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
SLIDE 18

GOGC=off

What if we turn off GC completely?

18

slide-19
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
SLIDE 20

SetMaxHeap GOGCMIN

The future?

20

https://twitter.com/ashleymcnamara

slide-21
SLIDE 21

THANK YOU!

21

https://twitter.com/ashleymcnamara

@bboreham

slide-22
SLIDE 22

More information

22

Good explanation of GOGC and other settings https://dave.cheney.net/tag/gogc Really detailed history https://blog.golang.org/ismmkeynote