SlideShare a Scribd company logo
1 of 51
Download to read offline
Profiling Go Programs
November 6, 2013

John Graham-Cumming

www.cloudflare.com!
The Golden Rule
•  Premature optimization is the root of all evil – Hoare


•  My version...
•  Don’t waste programmer cycles saving the wrong CPU cycles
•  (applies to memory as well)

•  Measure, measure, measure
•  Then you can optimize 

www.cloudflare.com!
Some Go Measurement Tools
•  Timing
•  Shell time command
•  time.Now(), time.Duration()
•  pprof.StartCPUProfile(f), pprof.StopCPUProfile()
•  go tool pprof http://localhost:6060/debug/pprof/
profile
•  Memory
•  Shell ps command
•  runtime.ReadMemStats(&m)
•  runtime.WriteHeapProfile(w)
•  go tool pprof http://localhost:6060/debug/pprof/
heap

www.cloudflare.com!
CPU PROFILING

www.cloudflare.com!
Example: badly implemented LRU Cache
package lru1
import “time”
type Item struct {
key string
value string
last time.Time
}
type Cache struct {
cap int
data map[string]*Item
}
func NewCache(cap int) (*Cache) {
return &Cache{cap, make(map[string]*Item)}
}
www.cloudflare.com!
Example: badly implemented LRU Cache
func (c *Cache) makeSpace() {
old := &Item{last: time.Now()}
var key string
for k, v := range c.data {
if v.last.Before(old.last) {
old = v
key = k
}
}
delete(c.data, key)
}
func (c *Cache) Put(key, value string) {
if len(c.data) == c.cap {
c.makeSpace()
}
c.data[key] = &Item{value, time.Now()}
}
www.cloudflare.com!
Example: badly implemented LRU Cache
func (c *Cache) Get(key string) (*Item) {
if c.data[key] != nil {
c.data[key].last = time.Now()
}
return c.data[key]
}

www.cloudflare.com!
Bad LRU Cache
•  Use it to cache relationship between email addresses and

their domain’s MX record
•  Feed in 10M email addresses in arrival order; cache
10,000 MX records
% time ./lrutest1 < top10M
9929964 total 2565368 misses
82.39s user 25.22s system 99% cpu 1:47.61 total

•  So 1m48s

www.cloudflare.com!
Let’s profile it!
•  Use the pprof profiler
func main() {
f, _ := os.Create("lrutest1.cpuprofile")
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
...
}

•  Creates lrutest1.cpuprofile
•  go tool pprof lrutest1 lrutest1.cpuprofile

www.cloudflare.com!
pprof command-line
% go tool pprof lrutest1 lrutest1.cpuprofile
Welcome to pprof! For help, type 'help'.
(pprof) top
Total: 10440 samples
3826 36.6% 36.6%
3826 36.6% hash_next
2252 21.6% 58.2%
9004 86.2% lru1.(*Cache).makeSpace
2130 20.4% 78.6%
2920 28.0% runtime.mapiter2
623
6.0% 84.6%
623
6.0% runtime.memcopy64
248
2.4% 87.0%
3916 37.5% runtime.mapiternext
242
2.3% 89.3%
777
7.4% strings.genSplit
168
1.6% 90.9%
168
1.6% runtime.strcopy
151
1.4% 92.3%
151
1.4% strings.Count
64
0.6% 93.0%
195
1.9% scanblock
62
0.6% 93.5%
390
3.7% runtime.mallocgc

www.cloudflare.com!
pprof command-line
(pprof) top -cum
Total: 10440 samples
0
0.0%
0.0%
23
0.2%
0.2%
0
0.0%
0.2%
1
0.0%
0.2%
2252 21.6% 21.8%
248
2.4% 24.2%
3826 36.6% 60.8%
2130 20.4% 81.2%
14
0.1% 81.4%
242
2.3% 83.7%

www.cloudflare.com!

10146
10146
10146
9067
9004
3916
3826
2920
786
777

97.2%
97.2%
97.2%
86.8%
86.2%
37.5%
36.6%
28.0%
7.5%
7.4%

gosched0
main.main
runtime.main
lru1.(*Cache).Put
lru1.(*Cache).makeSpace
runtime.mapiternext
hash_next
runtime.mapiter2
strings.Split
strings.genSplit
pprof web view

www.cloudflare.com!
Live profiling
•  net/http/pprof
import _ “net/http/pprof”
go func() {
log.Println(http.ListenAndServe("127.0.0.1:6161", nil))
}()

•  /pprof/debug/heap
•  /pprof/debug/profile

www.cloudflare.com!
Live command-line profiling
% go tool pprof http://127.0.0.1:6161/debug/pprof/profile
Read http://127.0.0.1:6161/debug/pprof/symbol
Be patient...
Wrote profile to [...]
Welcome to pprof! For help, type 'help'.
(pprof) top
Total: 2948 samples
1146 38.9% 38.9%
1146 38.9% hash_next
642 21.8% 60.7%
2618 88.8% lru1.(*Cache).makeSpace
582 19.7% 80.4%
806 27.3% runtime.mapiter2
176
6.0% 86.4%
176
6.0% runtime.memcopy64
86
2.9% 89.3%
1194 40.5% runtime.mapiternext
51
1.7% 91.0%
176
6.0% strings.genSplit
48
1.6% 92.6%
48
1.6% runtime.strcopy
43
1.5% 94.1%
43
1.5% runtime.futex
43
1.5% 95.6%
43
1.5% strings.Count
14
0.5% 96.0%
85
2.9% runtime.makeslice
(pprof)

www.cloudflare.com!
Live browser profiling

www.cloudflare.com!
Full goroutine stack dump

www.cloudflare.com!
Running goroutines

www.cloudflare.com!
Better LRU implementation
package lru2
import "container/list”
type Item struct {
key string
value string
}
type Cache struct {
cap int
data map[string]*list.Element
l *list.List
}
func NewCache(cap int) (*Cache) {
return &Cache{cap, make(map[string]*list.Element),
list.New()}
}
www.cloudflare.com!
Better LRU implementation
func (c *Cache) Get(key string) (*Item) {
if c.data[key] != nil {
c.l.MoveToFront(c.data[key])
return c.data[key].Value.(*Item)
}
return nil
}
func (c *Cache) Put(key, value string) {
if len(c.data) == c.cap {
delete(c.data, c.l.Back().Value.(*Item).key)
c.l.Remove(c.l.Back())
}
c.data[key] = c.l.PushFront(&Item{key, value})
}

www.cloudflare.com!
Better LRU Cache
•  Use it to cache relationship between email addresses and

their domain’s MX record
•  Feed in 10M email addresses in arrival order; cache
10,000 MX records
% time ./lrutest2 < top10M
9929964 total 2565368 misses
12.19s user 1.14s system 105% cpu 12.652 total

•  So 12.3s

www.cloudflare.com!
pprof command-line
% go tool pprof lrutest2 lrutest2.cpuprofile
Welcome to pprof! For help, type 'help'.
(pprof) top
Total: 1221 samples
212 17.4% 17.4%
833 68.2% strings.genSplit
167 13.7% 31.0%
167 13.7% strings.Count
74
6.1% 37.1%
77
6.3% sweepspan
71
5.8% 42.9%
206 16.9% scanblock
61
5.0% 47.9%
61
5.0% markonly
61
5.0% 52.9%
435 35.6% runtime.mallocgc
51
4.2% 57.1%
51
4.2% flushptrbuf
51
4.2% 61.3%
90
7.4% runtime.mapaccess1_faststr
49
4.0% 65.3%
49
4.0% runtime.futex
41
3.4% 68.6%
41
3.4% runtime.aeshashbody

www.cloudflare.com!
pprof web view

www.cloudflare.com!
Let’s try random eviction
package lru3
import "math/rand"
import "fmt"
type Item struct {
key string
value string
}
type Cache struct {
cap int
data map[string]*Item
keys []string
}
func NewCache(cap int) (*Cache) {
return &Cache{cap, make(map[string]*Item),
make([]string, 0, cap)}
}
www.cloudflare.com!
Let’s try random eviction
func (c *Cache) Get(key string) (*Item) {
return c.data[key]
}
func (c *Cache) Put(key, value string) {
if len(c.keys) == c.cap {
evict := rand.Intn(c.cap)
delete(c.data, c.keys[evict])
c.keys = append(c.keys[:evict],
c.keys[evict+1:]...)
}
c.keys = append(c.keys, key)
c.data[key] = &Item{key, value}
}

www.cloudflare.com!
Random Eviction
•  Same speed for a different algorithm
% time ./lrutest3 < top10M
9929964 total 2820060 misses
11.76s user 1.02s system 105% cpu 12.130 total

•  So 12.1s
% go tool pprof lrutest3 lrutest3.cpuprofile
(pprof) top
Total: 1171 samples
203 17.3% 17.3%
770 65.8% strings.genSplit
146 12.5% 29.8%
146 12.5% strings.Count
101
8.6% 38.4%
101
8.6% runtime.memmove
70
6.0% 44.4%
77
6.6% sweepspan
61
5.2% 49.6%
380 32.5% runtime.mallocgc
60
5.1% 54.7%
146 12.5% scanblock
54
4.6% 59.4%
54
4.6% markonly
www.cloudflare.com!
pprof web view

www.cloudflare.com!
web Put

www.cloudflare.com!
Eliminate slice operation
package lru4
import "math/rand"
type Item struct {
key string
value string
}
type Cache struct {
cap int
data map[string]*Item
keys []string
}
func NewCache(cap int) (*Cache) {
return &Cache{cap, make(map[string]*Item),
make([]string, cap)}
}
www.cloudflare.com!
Eliminate slice operation
func (c *Cache) Get(key string) (*Item) {
return c.data[key]
}
func (c *Cache) Put(key, value string) {
slot := len(c.data)
if len(c.data) == c.cap {
slot = rand.Intn(c.cap)
delete(c.data, c.keys[slot])
}
c.keys[slot] = key
c.data[key] = &Item{key, value}
}

www.cloudflare.com!
Eliminate slice operation
•  Slightly faster
% time ./lrutest4 < top10M
9929964 total 2819425 misses
6.51s user 4.83s system 105% cpu 10.787 total

•  So 10.8s

www.cloudflare.com!
Slice operations now gone

www.cloudflare.com!
web Put

www.cloudflare.com!
Also...
•  What’s blocking on synchronization primitives?



•  What’s causing the creation of OS threads?

www.cloudflare.com!
MEMORY RECYCLING

www.cloudflare.com!
Memory Statistics
•  Read with runtime.ReadMemStats(&m)
•  The MemStats struct has tons of members
•  Useful ones for looking at heap
•  HeapInuse - # bytes in the heap allocated to things
•  HeapIdle - # bytes in heap waiting to be used
•  HeapSys - # bytes obtained from OS
•  HeapReleased - # bytes released to OS


www.cloudflare.com!
Test garbage making program
func makeBuffer() []byte {
return make([]byte, rand.Intn(5000000)+5000000)
}
func main() {
pool := make([][]byte, 20)
makes := 0
for {
b := makeBuffer()
makes += 1
i := rand.Intn(len(pool))
pool[i] = b
time.Sleep(time.Second)
}
}
www.cloudflare.com!
What happens

www.cloudflare.com!
debug.FreeOSMemory()

www.cloudflare.com!
Use a buffered channel
func main() {!
pool := make([][]byte, 20)!
idle:= make(chan []byte, 5)!
!
makes := 0!
for {!
var b []byte!
select {!
case b = <-idle:!
default:!
makes += 1!
b = makeBuffer()!
}!
!
!
!
!

i := rand.Intn(len(pool))!
if pool[i] != nil {!
select {!
case idle<- pool[i]:!
pool[i] = nil!
default:!
}!
}!
pool[i] = b!
time.Sleep(time.Second)!
}!

}
www.cloudflare.com!
select for non-blocking receive
A buffered
channel makes a
simple queue
idle:= make(chan []byte, 5)!
!
select {!
case b = <-idle:

!
default:!
Try to get from the
makes += 1!
idle queue
b = makeBuffer()!
}!

Idle queue
empty? Make a
new buffer
www.cloudflare.com!
select for non-blocking send
A buffered
channel makes a
simple queue
idle:= make(chan []byte, 5)!
!
select {!
case buffer <- pool[i]:!
pool[i] = nil!
!
Try to return buffer
default:!
to the idle queue
}!

Idle queue full?
GC will have to
deal with the
buffer
www.cloudflare.com!
What happens

www.cloudflare.com!
More realistic: 20 goroutines
func main() {!
pool := make([][]byte, 200)!
!
for i := 0; i < 10; i++ {!
go func(offset int) {!
for {!
b := makeBuffer()!
j := offset+rand.Intn(20)!
pool[j] = b!
!
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))!
}!
}(i*20)!
}!
}!

www.cloudflare.com!
What happens

www.cloudflare.com!
Shared across goroutines
func main() {!
buffer := make(chan []byte, 5)!
!
pool := make([][]byte, 200)!
for i := 0; i < 10; i++ {!
go func(offset int) {!
for {!
var b []byte!
select {!
case b = <-buffer:!
default: b = makeBuffer()!
}!
j := offset+rand.Intn(20)!
if pool[j] != nil {!
select {!
case buffer <- pool[j]: pool[j] = nil!
default:!
}!
}!
pool[j] = b!
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))!
}!
}(i*20)!
}!
!
www.cloudflare.com!
What Happens

www.cloudflare.com!
More realistic example
•  Alter code to
•  Always try to give back a random buffer from the pool
•  50% of the time get a new one
•  Should create more garbage

www.cloudflare.com!
Idle length 5

www.cloudflare.com!
Idle length 20

www.cloudflare.com!
Idle length 50

www.cloudflare.com!
Also
•  This works for things other than []byte
•  Can be done with arbitrary types
•  Just need some way to reset
•  There’s a proposal to add something like this to the Go

package library
•  sync.Cache/sync.Pool
•  Follow https://code.google.com/p/go/issues/detail?id=4720

www.cloudflare.com!

More Related Content

What's hot

Orchestrating workflows Apache Airflow on GCP & AWS
Orchestrating workflows Apache Airflow on GCP & AWSOrchestrating workflows Apache Airflow on GCP & AWS
Orchestrating workflows Apache Airflow on GCP & AWSDerrick Qin
 
Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Flink Forward
 
Airflow - a data flow engine
Airflow - a data flow engineAirflow - a data flow engine
Airflow - a data flow engineWalter Liu
 
Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Brian Brazil
 
Performance Tuning EC2 Instances
Performance Tuning EC2 InstancesPerformance Tuning EC2 Instances
Performance Tuning EC2 InstancesBrendan Gregg
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19cMaria Colgan
 
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptxJosé Lin
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTanel Poder
 
Performance Troubleshooting Using Apache Spark Metrics
Performance Troubleshooting Using Apache Spark MetricsPerformance Troubleshooting Using Apache Spark Metrics
Performance Troubleshooting Using Apache Spark MetricsDatabricks
 
Monitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusMonitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusGrafana Labs
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?Mydbops
 
Prometheus Overview
Prometheus OverviewPrometheus Overview
Prometheus OverviewBrian Brazil
 
Tfa collector docv121210
Tfa collector docv121210Tfa collector docv121210
Tfa collector docv121210Hanh Nguyen Duy
 
Kubernetes Networking with Cilium - Deep Dive
Kubernetes Networking with Cilium - Deep DiveKubernetes Networking with Cilium - Deep Dive
Kubernetes Networking with Cilium - Deep DiveMichal Rostecki
 
GitOps with Amazon EKS Anywhere by Dan Budris
GitOps with Amazon EKS Anywhere by Dan BudrisGitOps with Amazon EKS Anywhere by Dan Budris
GitOps with Amazon EKS Anywhere by Dan BudrisWeaveworks
 
Prometheus - basics
Prometheus - basicsPrometheus - basics
Prometheus - basicsJuraj Hantak
 
Extreme Linux Performance Monitoring and Tuning
Extreme Linux Performance Monitoring and TuningExtreme Linux Performance Monitoring and Tuning
Extreme Linux Performance Monitoring and TuningMilind Koyande
 

What's hot (20)

Orchestrating workflows Apache Airflow on GCP & AWS
Orchestrating workflows Apache Airflow on GCP & AWSOrchestrating workflows Apache Airflow on GCP & AWS
Orchestrating workflows Apache Airflow on GCP & AWS
 
Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...
 
Apache airflow
Apache airflowApache airflow
Apache airflow
 
Airflow - a data flow engine
Airflow - a data flow engineAirflow - a data flow engine
Airflow - a data flow engine
 
Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)
 
Airflow introduction
Airflow introductionAirflow introduction
Airflow introduction
 
Performance Tuning EC2 Instances
Performance Tuning EC2 InstancesPerformance Tuning EC2 Instances
Performance Tuning EC2 Instances
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19c
 
Alfresco tuning part1
Alfresco tuning part1Alfresco tuning part1
Alfresco tuning part1
 
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
 
Performance Troubleshooting Using Apache Spark Metrics
Performance Troubleshooting Using Apache Spark MetricsPerformance Troubleshooting Using Apache Spark Metrics
Performance Troubleshooting Using Apache Spark Metrics
 
Monitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusMonitoring Kubernetes with Prometheus
Monitoring Kubernetes with Prometheus
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?
 
Prometheus Overview
Prometheus OverviewPrometheus Overview
Prometheus Overview
 
Tfa collector docv121210
Tfa collector docv121210Tfa collector docv121210
Tfa collector docv121210
 
Kubernetes Networking with Cilium - Deep Dive
Kubernetes Networking with Cilium - Deep DiveKubernetes Networking with Cilium - Deep Dive
Kubernetes Networking with Cilium - Deep Dive
 
GitOps with Amazon EKS Anywhere by Dan Budris
GitOps with Amazon EKS Anywhere by Dan BudrisGitOps with Amazon EKS Anywhere by Dan Budris
GitOps with Amazon EKS Anywhere by Dan Budris
 
Prometheus - basics
Prometheus - basicsPrometheus - basics
Prometheus - basics
 
Extreme Linux Performance Monitoring and Tuning
Extreme Linux Performance Monitoring and TuningExtreme Linux Performance Monitoring and Tuning
Extreme Linux Performance Monitoring and Tuning
 

Viewers also liked

Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxSignalFx
 
Profiling go code a beginners tutorial
Profiling go code   a beginners tutorialProfiling go code   a beginners tutorial
Profiling go code a beginners tutorialSamuel Lampa
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyAerospike
 
Running Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without ParachuteRunning Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without ParachuteCloudflare
 
Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014Cloudflare
 
Secure 2013 Poland
Secure 2013 PolandSecure 2013 Poland
Secure 2013 PolandCloudflare
 
Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Cloudflare
 
CloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudflare
 
Overview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for youOverview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for youCloudflare
 
WordPress London Meetup January 2012
WordPress London Meetup January 2012WordPress London Meetup January 2012
WordPress London Meetup January 2012Cloudflare
 
Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season Cloudflare
 
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber AttacksHow to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber AttacksCloudflare
 
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNSRunning a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNSCloudflare
 
A Channel Compendium
A Channel CompendiumA Channel Compendium
A Channel CompendiumCloudflare
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Cloudflare
 
Hardening Microservices Security: Building a Layered Defense Strategy
Hardening Microservices Security: Building a Layered Defense StrategyHardening Microservices Security: Building a Layered Defense Strategy
Hardening Microservices Security: Building a Layered Defense StrategyCloudflare
 
Latest Trends in Web Application Security
Latest Trends in Web Application SecurityLatest Trends in Web Application Security
Latest Trends in Web Application SecurityCloudflare
 

Viewers also liked (20)

Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
 
Profiling go code a beginners tutorial
Profiling go code   a beginners tutorialProfiling go code   a beginners tutorial
Profiling go code a beginners tutorial
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
 
Running Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without ParachuteRunning Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without Parachute
 
Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014
 
Secure 2013 Poland
Secure 2013 PolandSecure 2013 Poland
Secure 2013 Poland
 
Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Sullivan red october-oscon-2014
Sullivan red october-oscon-2014
 
CloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - Webinar
 
Go Containers
Go ContainersGo Containers
Go Containers
 
Overview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for youOverview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for you
 
SortaSQL
SortaSQLSortaSQL
SortaSQL
 
WordPress London Meetup January 2012
WordPress London Meetup January 2012WordPress London Meetup January 2012
WordPress London Meetup January 2012
 
Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season
 
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber AttacksHow to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
 
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNSRunning a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
 
Botconf ppt
Botconf   pptBotconf   ppt
Botconf ppt
 
A Channel Compendium
A Channel CompendiumA Channel Compendium
A Channel Compendium
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014
 
Hardening Microservices Security: Building a Layered Defense Strategy
Hardening Microservices Security: Building a Layered Defense StrategyHardening Microservices Security: Building a Layered Defense Strategy
Hardening Microservices Security: Building a Layered Defense Strategy
 
Latest Trends in Web Application Security
Latest Trends in Web Application SecurityLatest Trends in Web Application Security
Latest Trends in Web Application Security
 

Similar to Go Profiling - John Graham-Cumming

2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdfUtabeUtabe
 
YOW2020 Linux Systems Performance
YOW2020 Linux Systems PerformanceYOW2020 Linux Systems Performance
YOW2020 Linux Systems PerformanceBrendan Gregg
 
OSMC 2012 | Neues in Nagios 4.0 by Andreas Ericsson
OSMC 2012 | Neues in Nagios 4.0 by Andreas EricssonOSMC 2012 | Neues in Nagios 4.0 by Andreas Ericsson
OSMC 2012 | Neues in Nagios 4.0 by Andreas EricssonNETWAYS
 
marko_go_in_badoo
marko_go_in_badoomarko_go_in_badoo
marko_go_in_badooMarko Kevac
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupBadoo Development
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to GoCloudflare
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaCharles Nutter
 
Code instrumentation
Code instrumentationCode instrumentation
Code instrumentationBryan Reinero
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
Continuous Go Profiling & Observability
Continuous Go Profiling & ObservabilityContinuous Go Profiling & Observability
Continuous Go Profiling & ObservabilityScyllaDB
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존동수 장
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio
 
Guide to alfresco monitoring
Guide to alfresco monitoringGuide to alfresco monitoring
Guide to alfresco monitoringMiguel Rodriguez
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealTzung-Bi Shih
 
Down the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoDown the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoRemco Wendt
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak PROIDEA
 
Node Interactive Debugging Node.js In Production
Node Interactive Debugging Node.js In ProductionNode Interactive Debugging Node.js In Production
Node Interactive Debugging Node.js In ProductionYunong Xiao
 

Similar to Go Profiling - John Graham-Cumming (20)

2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf
 
YOW2020 Linux Systems Performance
YOW2020 Linux Systems PerformanceYOW2020 Linux Systems Performance
YOW2020 Linux Systems Performance
 
OSMC 2012 | Neues in Nagios 4.0 by Andreas Ericsson
OSMC 2012 | Neues in Nagios 4.0 by Andreas EricssonOSMC 2012 | Neues in Nagios 4.0 by Andreas Ericsson
OSMC 2012 | Neues in Nagios 4.0 by Andreas Ericsson
 
marko_go_in_badoo
marko_go_in_badoomarko_go_in_badoo
marko_go_in_badoo
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
 
Code instrumentation
Code instrumentationCode instrumentation
Code instrumentation
 
php & performance
 php & performance php & performance
php & performance
 
Continuous Go Profiling & Observability
Continuous Go Profiling & ObservabilityContinuous Go Profiling & Observability
Continuous Go Profiling & Observability
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존Java/Spring과 Node.js의공존
Java/Spring과 Node.js의공존
 
Go memory
Go memoryGo memory
Go memory
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0
 
Guide to alfresco monitoring
Guide to alfresco monitoringGuide to alfresco monitoring
Guide to alfresco monitoring
 
Global Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the SealGlobal Interpreter Lock: Episode I - Break the Seal
Global Interpreter Lock: Episode I - Break the Seal
 
Down the rabbit hole, profiling in Django
Down the rabbit hole, profiling in DjangoDown the rabbit hole, profiling in Django
Down the rabbit hole, profiling in Django
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Node Interactive Debugging Node.js In Production
Node Interactive Debugging Node.js In ProductionNode Interactive Debugging Node.js In Production
Node Interactive Debugging Node.js In Production
 

More from Cloudflare

Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Cloudflare
 
Close your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareClose your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareCloudflare
 
Why you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceWhy you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceCloudflare
 
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarDon't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarCloudflare
 
Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Cloudflare
 
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...Cloudflare
 
Zero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastZero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastCloudflare
 
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...Cloudflare
 
Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Cloudflare
 
Scaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceScaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceCloudflare
 
Application layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataApplication layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataCloudflare
 
Recent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondRecent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondCloudflare
 
Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cloudflare
 
Strengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersStrengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersCloudflare
 
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksKentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksCloudflare
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaCloudflare
 
It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?Cloudflare
 
Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cloudflare
 
Bring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsBring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsCloudflare
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformationCloudflare
 

More from Cloudflare (20)

Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)
 
Close your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareClose your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with Cloudflare
 
Why you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceWhy you should replace your d do s hardware appliance
Why you should replace your d do s hardware appliance
 
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarDon't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
 
Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021
 
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
 
Zero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastZero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fast
 
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
 
Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...
 
Scaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceScaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-service
 
Application layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataApplication layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare data
 
Recent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondRecent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respond
 
Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)
 
Strengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersStrengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providers
 
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksKentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North America
 
It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?
 
Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)
 
Bring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsBring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teams
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformation
 

Recently uploaded

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 

Recently uploaded (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 

Go Profiling - John Graham-Cumming

  • 1. Profiling Go Programs November 6, 2013 John Graham-Cumming www.cloudflare.com!
  • 2. The Golden Rule •  Premature optimization is the root of all evil – Hoare •  My version... •  Don’t waste programmer cycles saving the wrong CPU cycles •  (applies to memory as well) •  Measure, measure, measure •  Then you can optimize www.cloudflare.com!
  • 3. Some Go Measurement Tools •  Timing •  Shell time command •  time.Now(), time.Duration() •  pprof.StartCPUProfile(f), pprof.StopCPUProfile() •  go tool pprof http://localhost:6060/debug/pprof/ profile •  Memory •  Shell ps command •  runtime.ReadMemStats(&m) •  runtime.WriteHeapProfile(w) •  go tool pprof http://localhost:6060/debug/pprof/ heap www.cloudflare.com!
  • 5. Example: badly implemented LRU Cache package lru1 import “time” type Item struct { key string value string last time.Time } type Cache struct { cap int data map[string]*Item } func NewCache(cap int) (*Cache) { return &Cache{cap, make(map[string]*Item)} } www.cloudflare.com!
  • 6. Example: badly implemented LRU Cache func (c *Cache) makeSpace() { old := &Item{last: time.Now()} var key string for k, v := range c.data { if v.last.Before(old.last) { old = v key = k } } delete(c.data, key) } func (c *Cache) Put(key, value string) { if len(c.data) == c.cap { c.makeSpace() } c.data[key] = &Item{value, time.Now()} } www.cloudflare.com!
  • 7. Example: badly implemented LRU Cache func (c *Cache) Get(key string) (*Item) { if c.data[key] != nil { c.data[key].last = time.Now() } return c.data[key] } www.cloudflare.com!
  • 8. Bad LRU Cache •  Use it to cache relationship between email addresses and their domain’s MX record •  Feed in 10M email addresses in arrival order; cache 10,000 MX records % time ./lrutest1 < top10M 9929964 total 2565368 misses 82.39s user 25.22s system 99% cpu 1:47.61 total •  So 1m48s www.cloudflare.com!
  • 9. Let’s profile it! •  Use the pprof profiler func main() { f, _ := os.Create("lrutest1.cpuprofile") pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() ... } •  Creates lrutest1.cpuprofile •  go tool pprof lrutest1 lrutest1.cpuprofile www.cloudflare.com!
  • 10. pprof command-line % go tool pprof lrutest1 lrutest1.cpuprofile Welcome to pprof! For help, type 'help'. (pprof) top Total: 10440 samples 3826 36.6% 36.6% 3826 36.6% hash_next 2252 21.6% 58.2% 9004 86.2% lru1.(*Cache).makeSpace 2130 20.4% 78.6% 2920 28.0% runtime.mapiter2 623 6.0% 84.6% 623 6.0% runtime.memcopy64 248 2.4% 87.0% 3916 37.5% runtime.mapiternext 242 2.3% 89.3% 777 7.4% strings.genSplit 168 1.6% 90.9% 168 1.6% runtime.strcopy 151 1.4% 92.3% 151 1.4% strings.Count 64 0.6% 93.0% 195 1.9% scanblock 62 0.6% 93.5% 390 3.7% runtime.mallocgc www.cloudflare.com!
  • 11. pprof command-line (pprof) top -cum Total: 10440 samples 0 0.0% 0.0% 23 0.2% 0.2% 0 0.0% 0.2% 1 0.0% 0.2% 2252 21.6% 21.8% 248 2.4% 24.2% 3826 36.6% 60.8% 2130 20.4% 81.2% 14 0.1% 81.4% 242 2.3% 83.7% www.cloudflare.com! 10146 10146 10146 9067 9004 3916 3826 2920 786 777 97.2% 97.2% 97.2% 86.8% 86.2% 37.5% 36.6% 28.0% 7.5% 7.4% gosched0 main.main runtime.main lru1.(*Cache).Put lru1.(*Cache).makeSpace runtime.mapiternext hash_next runtime.mapiter2 strings.Split strings.genSplit
  • 13. Live profiling •  net/http/pprof import _ “net/http/pprof” go func() { log.Println(http.ListenAndServe("127.0.0.1:6161", nil)) }() •  /pprof/debug/heap •  /pprof/debug/profile www.cloudflare.com!
  • 14. Live command-line profiling % go tool pprof http://127.0.0.1:6161/debug/pprof/profile Read http://127.0.0.1:6161/debug/pprof/symbol Be patient... Wrote profile to [...] Welcome to pprof! For help, type 'help'. (pprof) top Total: 2948 samples 1146 38.9% 38.9% 1146 38.9% hash_next 642 21.8% 60.7% 2618 88.8% lru1.(*Cache).makeSpace 582 19.7% 80.4% 806 27.3% runtime.mapiter2 176 6.0% 86.4% 176 6.0% runtime.memcopy64 86 2.9% 89.3% 1194 40.5% runtime.mapiternext 51 1.7% 91.0% 176 6.0% strings.genSplit 48 1.6% 92.6% 48 1.6% runtime.strcopy 43 1.5% 94.1% 43 1.5% runtime.futex 43 1.5% 95.6% 43 1.5% strings.Count 14 0.5% 96.0% 85 2.9% runtime.makeslice (pprof) www.cloudflare.com!
  • 16. Full goroutine stack dump www.cloudflare.com!
  • 18. Better LRU implementation package lru2 import "container/list” type Item struct { key string value string } type Cache struct { cap int data map[string]*list.Element l *list.List } func NewCache(cap int) (*Cache) { return &Cache{cap, make(map[string]*list.Element), list.New()} } www.cloudflare.com!
  • 19. Better LRU implementation func (c *Cache) Get(key string) (*Item) { if c.data[key] != nil { c.l.MoveToFront(c.data[key]) return c.data[key].Value.(*Item) } return nil } func (c *Cache) Put(key, value string) { if len(c.data) == c.cap { delete(c.data, c.l.Back().Value.(*Item).key) c.l.Remove(c.l.Back()) } c.data[key] = c.l.PushFront(&Item{key, value}) } www.cloudflare.com!
  • 20. Better LRU Cache •  Use it to cache relationship between email addresses and their domain’s MX record •  Feed in 10M email addresses in arrival order; cache 10,000 MX records % time ./lrutest2 < top10M 9929964 total 2565368 misses 12.19s user 1.14s system 105% cpu 12.652 total •  So 12.3s www.cloudflare.com!
  • 21. pprof command-line % go tool pprof lrutest2 lrutest2.cpuprofile Welcome to pprof! For help, type 'help'. (pprof) top Total: 1221 samples 212 17.4% 17.4% 833 68.2% strings.genSplit 167 13.7% 31.0% 167 13.7% strings.Count 74 6.1% 37.1% 77 6.3% sweepspan 71 5.8% 42.9% 206 16.9% scanblock 61 5.0% 47.9% 61 5.0% markonly 61 5.0% 52.9% 435 35.6% runtime.mallocgc 51 4.2% 57.1% 51 4.2% flushptrbuf 51 4.2% 61.3% 90 7.4% runtime.mapaccess1_faststr 49 4.0% 65.3% 49 4.0% runtime.futex 41 3.4% 68.6% 41 3.4% runtime.aeshashbody www.cloudflare.com!
  • 23. Let’s try random eviction package lru3 import "math/rand" import "fmt" type Item struct { key string value string } type Cache struct { cap int data map[string]*Item keys []string } func NewCache(cap int) (*Cache) { return &Cache{cap, make(map[string]*Item), make([]string, 0, cap)} } www.cloudflare.com!
  • 24. Let’s try random eviction func (c *Cache) Get(key string) (*Item) { return c.data[key] } func (c *Cache) Put(key, value string) { if len(c.keys) == c.cap { evict := rand.Intn(c.cap) delete(c.data, c.keys[evict]) c.keys = append(c.keys[:evict], c.keys[evict+1:]...) } c.keys = append(c.keys, key) c.data[key] = &Item{key, value} } www.cloudflare.com!
  • 25. Random Eviction •  Same speed for a different algorithm % time ./lrutest3 < top10M 9929964 total 2820060 misses 11.76s user 1.02s system 105% cpu 12.130 total •  So 12.1s % go tool pprof lrutest3 lrutest3.cpuprofile (pprof) top Total: 1171 samples 203 17.3% 17.3% 770 65.8% strings.genSplit 146 12.5% 29.8% 146 12.5% strings.Count 101 8.6% 38.4% 101 8.6% runtime.memmove 70 6.0% 44.4% 77 6.6% sweepspan 61 5.2% 49.6% 380 32.5% runtime.mallocgc 60 5.1% 54.7% 146 12.5% scanblock 54 4.6% 59.4% 54 4.6% markonly www.cloudflare.com!
  • 28. Eliminate slice operation package lru4 import "math/rand" type Item struct { key string value string } type Cache struct { cap int data map[string]*Item keys []string } func NewCache(cap int) (*Cache) { return &Cache{cap, make(map[string]*Item), make([]string, cap)} } www.cloudflare.com!
  • 29. Eliminate slice operation func (c *Cache) Get(key string) (*Item) { return c.data[key] } func (c *Cache) Put(key, value string) { slot := len(c.data) if len(c.data) == c.cap { slot = rand.Intn(c.cap) delete(c.data, c.keys[slot]) } c.keys[slot] = key c.data[key] = &Item{key, value} } www.cloudflare.com!
  • 30. Eliminate slice operation •  Slightly faster % time ./lrutest4 < top10M 9929964 total 2819425 misses 6.51s user 4.83s system 105% cpu 10.787 total •  So 10.8s www.cloudflare.com!
  • 31. Slice operations now gone www.cloudflare.com!
  • 33. Also... •  What’s blocking on synchronization primitives? •  What’s causing the creation of OS threads? www.cloudflare.com!
  • 35. Memory Statistics •  Read with runtime.ReadMemStats(&m) •  The MemStats struct has tons of members •  Useful ones for looking at heap •  HeapInuse - # bytes in the heap allocated to things •  HeapIdle - # bytes in heap waiting to be used •  HeapSys - # bytes obtained from OS •  HeapReleased - # bytes released to OS www.cloudflare.com!
  • 36. Test garbage making program func makeBuffer() []byte { return make([]byte, rand.Intn(5000000)+5000000) } func main() { pool := make([][]byte, 20) makes := 0 for { b := makeBuffer() makes += 1 i := rand.Intn(len(pool)) pool[i] = b time.Sleep(time.Second) } } www.cloudflare.com!
  • 39. Use a buffered channel func main() {! pool := make([][]byte, 20)! idle:= make(chan []byte, 5)! ! makes := 0! for {! var b []byte! select {! case b = <-idle:! default:! makes += 1! b = makeBuffer()! }! ! ! ! ! i := rand.Intn(len(pool))! if pool[i] != nil {! select {! case idle<- pool[i]:! pool[i] = nil! default:! }! }! pool[i] = b! time.Sleep(time.Second)! }! } www.cloudflare.com!
  • 40. select for non-blocking receive A buffered channel makes a simple queue idle:= make(chan []byte, 5)! ! select {! case b = <-idle:
 ! default:! Try to get from the makes += 1! idle queue b = makeBuffer()! }! Idle queue empty? Make a new buffer www.cloudflare.com!
  • 41. select for non-blocking send A buffered channel makes a simple queue idle:= make(chan []byte, 5)! ! select {! case buffer <- pool[i]:! pool[i] = nil! ! Try to return buffer default:! to the idle queue }! Idle queue full? GC will have to deal with the buffer www.cloudflare.com!
  • 43. More realistic: 20 goroutines func main() {! pool := make([][]byte, 200)! ! for i := 0; i < 10; i++ {! go func(offset int) {! for {! b := makeBuffer()! j := offset+rand.Intn(20)! pool[j] = b! ! time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))! }! }(i*20)! }! }! www.cloudflare.com!
  • 45. Shared across goroutines func main() {! buffer := make(chan []byte, 5)! ! pool := make([][]byte, 200)! for i := 0; i < 10; i++ {! go func(offset int) {! for {! var b []byte! select {! case b = <-buffer:! default: b = makeBuffer()! }! j := offset+rand.Intn(20)! if pool[j] != nil {! select {! case buffer <- pool[j]: pool[j] = nil! default:! }! }! pool[j] = b! time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))! }! }(i*20)! }! ! www.cloudflare.com!
  • 47. More realistic example •  Alter code to •  Always try to give back a random buffer from the pool •  50% of the time get a new one •  Should create more garbage www.cloudflare.com!
  • 51. Also •  This works for things other than []byte •  Can be done with arbitrary types •  Just need some way to reset •  There’s a proposal to add something like this to the Go package library •  sync.Cache/sync.Pool •  Follow https://code.google.com/p/go/issues/detail?id=4720 www.cloudflare.com!