Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell...

20
Go GC: Latency Problem Solved Rick Hudson Google Engineer GopherCon Denver July 8, 2015

Transcript of Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell...

Page 1: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Go GC: Latency Problem SolvedRick HudsonGoogle Engineer

GopherCon DenverJuly 8, 2015

Page 2: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

My Codefendants: The Cambridge Runtime Gang

https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Sato_Tadanobu_with_a_goban.jpeg/500px-Sato_Tadanobu_with_a_goban.jpeg

Page 3: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Making Go Go: Establish A Virtuous Cycle

News Flash:2X Transistors != 2X Frequency

More transistors == more cores Only if software uses more cores

Long term Establish a virtuous cycle

Short term Increase Go Adoption

Software++

Hardware++

Hardware++

HW++

HW++

Software++

Software++

Software++

#1 Barrier: GC Latency

Page 4: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

When is the best time to do a GC?

When nobody is looking.

Using camera to track eye movement When subject looks away do a GC.

Recovering

https://upload.wikimedia.org/wikipedia/commons/3/35/Computer_Workstation_Variables.jpg

Page 5: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Waiting

Pop up a network wait icon

https://commons.wikimedia.org/wiki/File:WIFI_icon.svg#globalusage

Page 6: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Or Trade Throughput for Reduced GC

Latency

Page 7: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Latency

Nanosecond 1: Grace Hopper Nanosecond 11.8 inchesMicrosecond 5.4: Time light travels 1 mile in vacuumMillisecond 1: Read 1 MB sequentially from SSD 20: Read 1 MB from disk 50: Perceptual Causality (cursor response threshold) 50+: Various network delays 300: Eye blink

Page 8: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Go isn’t Java: GC Related Go Differences

JavaTens of Java ThreadsSynchronization via objects/locksRuntime written in C

Objects linked with pointers

GoThousands of Goroutines Synchronization via channels Runtime written in Go

Leverages Go same as usersControl of spatial locality

Objects can be embeddedInterior pointers (&foo.field)

Let’s Build a GC for Go

Page 9: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

GC 101Scan Phase

Heap

Stacks/RegistersGlobals

Page 10: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Mark Phase

Stacks/RegistersGlobals

Righteous Concurrent GC struggles with Evil Application changing pointers

Page 11: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Sweep Phase

Stacks/RegistersGlobals

Page 12: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

GC Algorithm Phases

Off

Stack scan

Mark

Mark termination

Sweep

Off

Correctness proofs in literature (see me)

WB

on

STW

GC disabledPointer writes are just memory writes: *slot = ptr

Collect pointers from globals and goroutine stacksStacks scanned at preemption points

Mark objects and follow pointers until pointer queue is emptyWrite barrier tracks pointer changes by mutator

Rescan globals/changed stacks, finish marking, shrink stacks, …Literature contains non-STW algorithms: keeping it simple for now

Reclaim unmarked objects as neededAdjust GC pacing for next cycle

Rinse and repeat

Page 13: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

1.4 Stop the World

GCGC

Application Application

Page 14: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Application

Application Application

Assist

GC

Application

Assist

GC

1 ms 3 ms

1.5 Concurrent GC

Page 15: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Garbage Benchmark

9

8

7

6

5

4

3

2

1

0

GC

Pau

se (L

ower

is b

ette

r)

S

econ

ds

Heap Size (Gigabytes)

Page 16: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

1.5 Garbage Benchmark Latency

Heap Size (Megabytes)

GC

Pau

se (

Low

er is

Bet

ter)

Mill

isec

onds

1.5 GC Pauses

Page 17: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

GOGC=200

Heap Size (Megabytes)

Splay: Increasing Heap Size == Better Performance E

xecu

tion

Tim

e (L

ower

is B

ette

r)

Page 18: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

JSON: Increasing Heap Size == Better Performance

Heap Size (Megabytes)

GOGC=200

Exe

cutio

n Ti

me

(Low

er is

Bet

ter)

Page 19: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Google Confidential and Proprietary

Onward

Tell people that GC is not a barrier with Go’s low latency GC

Tune for even lower latency, higher throughput, more predictabilityFind the sweet spot.

1.6 work will be use case driven: Let’s talk.

Increase Go Adoption Establish Virtuous Cycle

Page 20: Latency Problem Solved Go GC - Talkstalks.golang.org/2015/go-gc.pdf · 2019. 10. 10. · Tell people that GC is not a barrier with Go’s low latency GC Tune for even lower latency,

Questions