SlideShare ist ein Scribd-Unternehmen logo
1 von 33
Downloaden Sie, um offline zu lesen
Go: debugging and
troubleshooting tips
Jack Lindamood
Engineer @ SignalFx
cep221@gmail.com
● Thinking about
deploying go
● Tend to write bugs
● Want to make
troubleshooting
easier
Target audience
Logs
● Logging built in
● Stdout vs file
● Structured logging?
● Where do logs go?
○ Scribe
○ logstash
○ etc
Built in logging
Singleton optional pattern
import “log”
log.Printf("User %d", 123)
import “log”
var Logger *log.Logger
…
Logger.Printf(“User %d”,
123)
Singleton Optional Pattern
type Logger struct {
// …
}
var std = New(...)
func Println(s string) {
std.Println(s)
}
Structured Logging
import "github.com/Sirupsen/logrus"
logrus.WithField(“userID”, 123).Info(“Request”)
https://github.com/inconshreveable/log15
log.Info(“Request”, “userID”, 123)
Why not both?
var Logger StdLogger = log.New(ioutil.Discard, "[Sarama] ", log.LstdFlags)
// StdLogger is used to log error messages.
type StdLogger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
Println(v ...interface{})
}
func abc() {
log.Info("<- abc()")
defer log.Info("-> abc()")
// ...
}
Logging/defer pattern
PProf help
● Goroutines
● Heap
● CPU usage
● Running command line
PProf enabled
import _ "net/http/pprof"
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
// ... OR ...
handler.PathPrefix("/debug/pprof/cmdline").HandlerFunc(pprof.Cmdline)
/debug/pprof/goroutine
1 @ 0x96d3c8 0x96d1a3 0x968ae4 0x80543e 0x805650 0x4ef85a 0x5cca6e
0x4f1cbe 0x4ef31e 0x46ee91
1 @ 0x43dfd3 0x44c6d4 0x44bc32 0x4034ac 0x402279 0x43dbf0 0x46ee91
...
/debug/pprof/goroutine?debug=1
6 @ 0x43dfd3 0x4380fe 0x4375c0 0x499dda 0x499e46 0x49bb8a 0x4af6f4 0x502c07 0x50f110
0x6587a9 0x6589cc 0x4ffe07 0x46ee91
# 0x4375c0 net.runtime_pollWait+0x60 /usr/local/go/src/runtime/netpoll.go:
157
# 0x499dda net.(*pollDesc).Wait+0x3a /usr/local/go/src/net/fd_poll_runtime.
go:73
# 0x499e46 net.(*pollDesc).WaitRead+0x36 /usr/local/go/src/net/fd_poll_runtime.
go:78
# 0x49bb8a net.(*netFD).Read+0x23a /usr/local/go/src/net/fd_unix.go:232
# 0x4af6f4 net.(*conn).Read+0xe4 /usr/local/go/src/net/net.go:172
# 0x502c07 net/http.noteEOFReader.Read+0x67 /usr/local/go/src/net/http/transport.
go:1370
# 0x50f110 net/http.(*noteEOFReader).Read+0xd0 <autogenerated>:126
# 0x6587a9 bufio.(*Reader).fill+0x1e9 /usr/local/go/src/bufio/bufio.go:97
/debug/pprof/goroutine?debug=2
goroutine 37 [chan receive, 58 minutes]:
github.com/Shopify/sarama.(*asyncProducer).topicDispatcher(0xc820015140)
/opt/jenkins/workspace/prod/Godeps/_workspace/src/github.
com/Shopify/sarama/async_producer.go:213 +0xf5
github.com/Shopify/sarama.(*asyncProducer).(github.com/Shopify/sarama.topicDispatcher)-
fm()
/opt/jenkins/workspace/prod/Godeps/_workspace/src/github.
com/Shopify/sarama/async_producer.go:98 +0x20
github.com/Shopify/sarama.withRecover(0xc821adc720)
/opt/jenkins/workspace/prod/Godeps/_workspace/src/github.com/Shopify/sarama/utils.
go:42 +0x3a
created by github.com/Shopify/sarama.NewAsyncProducerFromClient
/opt/jenkins/workspace/prod/Godeps/_workspace/src/github.
com/Shopify/sarama/async_producer.go:98 +0x340
Go heap usage debugging
● alloc_objects
very useful
● go’s CPU usage
around GC strongly
related to number
of allocated objects
Example
go tool pprof -alloc_objects /tmp/server http://box:6060/debug/pprof/heap
(pprof) top
578225004112 of 902319909557 total (64.08%)
Dropped 756 nodes (cum <= 4511599547)
Showing top 10 nodes out of 112 (cum >= 75735754111)
flat flat% sum% cum cum%
58755173926 6.51% 27.36% 117454393178 13.02% github.
com/golang/protobuf/proto.(*Buffer).dec_slice_bool
….
Docker
● Containers!
● Easy deployment!
● Static compile makes
small docker images
● SignalFx container size
○ Go => 5MB
○ Java => 450 MB
Static go compiles for Docker
CGO_ENABLED=0 go build -v -installsuffix .
FROM scratch
COPY ./ingest /ingest
CMD ["/ingest"]
● Just export / for docker
containers
● http.FileServer
● Good for self download
(pprof needed)
File explorer
curl http://host.com:6060/debug/files/ingest >/tmp/ingest
Expvar
● Export JSON strings or numbers
● Visible in a browser
● Easy to use
● Best use in func init()
● Cmd line/env/build SHA/etc
Expvar the bad
Unable to unregister a variable
panic() on double register
What about non init state?
Global mutable state is an anti-pattern
Luck for us, the code is open
source!
github.com/signalfx/golib/expvar2
e := expvar2.ExpvarHandler{}
e.Exported["hello"] = expvar.Func(func() interface{} {
return "world"
})
e.Exported["distconf"] = distconf.Var()
e.Exported["env"] = expvar2.EnviromentalVariables()
handler.Path("/debug/vars").Handler(&e)
// http://localhost:6060/debug/vars?pretty=1&filter=env
Dynamic config
● Config for queue sizes,
timeouts, etc
● We use zookeeper for config
● env > file > zookeeper
○ file/env allow easy testing
and dev
● Turn debug levels on/off
● Can debug specific requests
● https://github.com/signalfx/golib
Dependencies
● Using master of dependencies is bad
● Need repeatable builds
● Vendoring is a requirement
● No pip, no cargo, no npm :( :( :(
● I blame “go get” for this mess
● https://github.com/kardianos/govendor
● https://github.com/tools/godep
Exported metrics
● Open source
○ Graphite
○ OpenTSDB
○ InfluxDB
● SaaS
○ SignalFx
● runtime.NumGoroutine()
● runtime.ReadMemStats()
○ TotalAlloc
○ Alloc
○ PauseTotalNs
● time.Now().Sub(start)
● runtime.NumCgoCall()
Count/defer pattern
atomic.AddInt64(&m.TotalConnections, 1)
atomic.AddInt64(&m.ActiveConnections, 1)
defer atomic.AddInt64(&m.ActiveConnections, -1)
start := time.Now()
next.ServeHTTP(rw, r)
reqTime := time.Since(start)
atomic.AddInt64(&m.TotalTimeNS, reqTime.Nanoseconds())
A single bad server
Tier Min/Median/Max Alloc/sec
Object explorer
● What if you forgot to export a variable?
● Uses reflection for ad hoc exploration
● https://github.
com/signalfx/golib/tree/master/explorable
Object explorer
Object explorer
Object explorer
Static checks
● golang.org/x/tools/cmd/goimports
● gofmt
● golang.org/x/tools/cmd/vet
● github.com/golang/lint/golint
○ Will need filters
● github.com/fzipp/gocyclo
● golang.org/x/tools/cmd/cover
● Wrapped into https://github.com/cep21/goverify
Questions?
● We’re hiring
○ jobs@signalfx.com

Weitere ähnliche Inhalte

Was ist angesagt?

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
 
All you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopAll you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopSaša Tatar
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating languagejgrahamc
 
marko_go_in_badoo
marko_go_in_badoomarko_go_in_badoo
marko_go_in_badooMarko Kevac
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to GoCloudflare
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go ConcurrencyCloudflare
 
Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Community
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBMongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBBoxed Ice
 
Something about Golang
Something about GolangSomething about Golang
Something about GolangAnton Arhipov
 
Event Loop in Javascript
Event Loop in JavascriptEvent Loop in Javascript
Event Loop in JavascriptDiptiGandhi4
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architectureJung Kim
 
Commit2015 kharchenko - python generators - ext
Commit2015   kharchenko - python generators - extCommit2015   kharchenko - python generators - ext
Commit2015 kharchenko - python generators - extMaxym Kharchenko
 
Python在豆瓣的应用
Python在豆瓣的应用Python在豆瓣的应用
Python在豆瓣的应用Qiangning Hong
 
Visualizing ORACLE performance data with R @ #C16LV
Visualizing ORACLE performance data with R @ #C16LVVisualizing ORACLE performance data with R @ #C16LV
Visualizing ORACLE performance data with R @ #C16LVMaxym Kharchenko
 
Мониторинг. Опять, rootconf 2016
Мониторинг. Опять, rootconf 2016Мониторинг. Опять, rootconf 2016
Мониторинг. Опять, rootconf 2016Vsevolod Polyakov
 

Was ist angesagt? (20)

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
 
All you need to know about the JavaScript event loop
All you need to know about the JavaScript event loopAll you need to know about the JavaScript event loop
All you need to know about the JavaScript event loop
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating language
 
Event loop
Event loopEvent loop
Event loop
 
marko_go_in_badoo
marko_go_in_badoomarko_go_in_badoo
marko_go_in_badoo
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools
 
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDBMongoUK 2011 - Rplacing RabbitMQ with MongoDB
MongoUK 2011 - Rplacing RabbitMQ with MongoDB
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
Event Loop in Javascript
Event Loop in JavascriptEvent Loop in Javascript
Event Loop in Javascript
 
Letswift19-clean-architecture
Letswift19-clean-architectureLetswift19-clean-architecture
Letswift19-clean-architecture
 
Commit2015 kharchenko - python generators - ext
Commit2015   kharchenko - python generators - extCommit2015   kharchenko - python generators - ext
Commit2015 kharchenko - python generators - ext
 
Python在豆瓣的应用
Python在豆瓣的应用Python在豆瓣的应用
Python在豆瓣的应用
 
Ruby meets Go
Ruby meets GoRuby meets Go
Ruby meets Go
 
Visualizing ORACLE performance data with R @ #C16LV
Visualizing ORACLE performance data with R @ #C16LVVisualizing ORACLE performance data with R @ #C16LV
Visualizing ORACLE performance data with R @ #C16LV
 
Metrics: where and how
Metrics: where and howMetrics: where and how
Metrics: where and how
 
Мониторинг. Опять, rootconf 2016
Мониторинг. Опять, rootconf 2016Мониторинг. Опять, rootconf 2016
Мониторинг. Опять, rootconf 2016
 
High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 

Ähnlich wie Go debugging and troubleshooting tips - from real life lessons at SignalFx

Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsOWASP Kyiv
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptKamil Toman
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGlobalLogic Ukraine
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoRodolfo Carvalho
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Itzik Kotler
 
Dive into sentry
Dive into sentryDive into sentry
Dive into sentryLeo Zhou
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsAzul Systems, Inc.
 
Logging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqLogging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqDoruk Uluçay
 
Network server in go #gocon 2013-11-14
Network server in go  #gocon 2013-11-14Network server in go  #gocon 2013-11-14
Network server in go #gocon 2013-11-14Jxck Jxck
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
Streaming huge databases using logical decoding
Streaming huge databases using logical decodingStreaming huge databases using logical decoding
Streaming huge databases using logical decodingAlexander Shulgin
 
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloudOUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloudJacek Gebal
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudAndrea Righi
 

Ähnlich wie Go debugging and troubleshooting tips - from real life lessons at SignalFx (20)

Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tips
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and Javascript
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii Shapoval
 
Golang
GolangGolang
Golang
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Dive into sentry
Dive into sentryDive into sentry
Dive into sentry
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Logging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqLogging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, Seq
 
Network server in go #gocon 2013-11-14
Network server in go  #gocon 2013-11-14Network server in go  #gocon 2013-11-14
Network server in go #gocon 2013-11-14
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
Go. why it goes v2
Go. why it goes v2Go. why it goes v2
Go. why it goes v2
 
Streaming huge databases using logical decoding
Streaming huge databases using logical decodingStreaming huge databases using logical decoding
Streaming huge databases using logical decoding
 
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloudOUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Intro django
Intro djangoIntro django
Intro django
 
Nodejs
NodejsNodejs
Nodejs
 

Mehr von SignalFx

Top Considerations For Operating a Kubernetes Environment at Scale
Top Considerations For Operating a Kubernetes Environment at ScaleTop Considerations For Operating a Kubernetes Environment at Scale
Top Considerations For Operating a Kubernetes Environment at ScaleSignalFx
 
How Cloud-Ready Alerting Is Optimal For Today's Environments
How Cloud-Ready Alerting Is Optimal For Today's EnvironmentsHow Cloud-Ready Alerting Is Optimal For Today's Environments
How Cloud-Ready Alerting Is Optimal For Today's EnvironmentsSignalFx
 
Microservices meetup April 2017
Microservices meetup April 2017Microservices meetup April 2017
Microservices meetup April 2017SignalFx
 
Operationalizing Docker at Scale: Lessons from Running Microservices in Produ...
Operationalizing Docker at Scale: Lessons from Running Microservices in Produ...Operationalizing Docker at Scale: Lessons from Running Microservices in Produ...
Operationalizing Docker at Scale: Lessons from Running Microservices in Produ...SignalFx
 
SignalFx Elasticsearch Metrics Monitoring and Alerting
SignalFx Elasticsearch Metrics Monitoring and AlertingSignalFx Elasticsearch Metrics Monitoring and Alerting
SignalFx Elasticsearch Metrics Monitoring and AlertingSignalFx
 
SignalFx Kafka Consumer Optimization
SignalFx Kafka Consumer OptimizationSignalFx Kafka Consumer Optimization
SignalFx Kafka Consumer OptimizationSignalFx
 
Making Cassandra Perform as a Time Series Database - Cassandra Summit 15
Making Cassandra Perform as a Time Series Database - Cassandra Summit 15Making Cassandra Perform as a Time Series Database - Cassandra Summit 15
Making Cassandra Perform as a Time Series Database - Cassandra Summit 15SignalFx
 
Docker at and with SignalFx
Docker at and with SignalFxDocker at and with SignalFx
Docker at and with SignalFxSignalFx
 
AWS Loft Talk: Behind the Scenes with SignalFx
AWS Loft Talk: Behind the Scenes with SignalFxAWS Loft Talk: Behind the Scenes with SignalFx
AWS Loft Talk: Behind the Scenes with SignalFxSignalFx
 
Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...SignalFx
 
Microservices and Devs in Charge: Why Monitoring is an Analytics Problem
Microservices and Devs in Charge: Why Monitoring is an Analytics ProblemMicroservices and Devs in Charge: Why Monitoring is an Analytics Problem
Microservices and Devs in Charge: Why Monitoring is an Analytics ProblemSignalFx
 

Mehr von SignalFx (11)

Top Considerations For Operating a Kubernetes Environment at Scale
Top Considerations For Operating a Kubernetes Environment at ScaleTop Considerations For Operating a Kubernetes Environment at Scale
Top Considerations For Operating a Kubernetes Environment at Scale
 
How Cloud-Ready Alerting Is Optimal For Today's Environments
How Cloud-Ready Alerting Is Optimal For Today's EnvironmentsHow Cloud-Ready Alerting Is Optimal For Today's Environments
How Cloud-Ready Alerting Is Optimal For Today's Environments
 
Microservices meetup April 2017
Microservices meetup April 2017Microservices meetup April 2017
Microservices meetup April 2017
 
Operationalizing Docker at Scale: Lessons from Running Microservices in Produ...
Operationalizing Docker at Scale: Lessons from Running Microservices in Produ...Operationalizing Docker at Scale: Lessons from Running Microservices in Produ...
Operationalizing Docker at Scale: Lessons from Running Microservices in Produ...
 
SignalFx Elasticsearch Metrics Monitoring and Alerting
SignalFx Elasticsearch Metrics Monitoring and AlertingSignalFx Elasticsearch Metrics Monitoring and Alerting
SignalFx Elasticsearch Metrics Monitoring and Alerting
 
SignalFx Kafka Consumer Optimization
SignalFx Kafka Consumer OptimizationSignalFx Kafka Consumer Optimization
SignalFx Kafka Consumer Optimization
 
Making Cassandra Perform as a Time Series Database - Cassandra Summit 15
Making Cassandra Perform as a Time Series Database - Cassandra Summit 15Making Cassandra Perform as a Time Series Database - Cassandra Summit 15
Making Cassandra Perform as a Time Series Database - Cassandra Summit 15
 
Docker at and with SignalFx
Docker at and with SignalFxDocker at and with SignalFx
Docker at and with SignalFx
 
AWS Loft Talk: Behind the Scenes with SignalFx
AWS Loft Talk: Behind the Scenes with SignalFxAWS Loft Talk: Behind the Scenes with SignalFx
AWS Loft Talk: Behind the Scenes with SignalFx
 
Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...Scaling ingest pipelines with high performance computing principles - Rajiv K...
Scaling ingest pipelines with high performance computing principles - Rajiv K...
 
Microservices and Devs in Charge: Why Monitoring is an Analytics Problem
Microservices and Devs in Charge: Why Monitoring is an Analytics ProblemMicroservices and Devs in Charge: Why Monitoring is an Analytics Problem
Microservices and Devs in Charge: Why Monitoring is an Analytics Problem
 

Kürzlich hochgeladen

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Kürzlich hochgeladen (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Go debugging and troubleshooting tips - from real life lessons at SignalFx

  • 1. Go: debugging and troubleshooting tips Jack Lindamood Engineer @ SignalFx cep221@gmail.com
  • 2. ● Thinking about deploying go ● Tend to write bugs ● Want to make troubleshooting easier Target audience
  • 3. Logs ● Logging built in ● Stdout vs file ● Structured logging? ● Where do logs go? ○ Scribe ○ logstash ○ etc
  • 4. Built in logging Singleton optional pattern import “log” log.Printf("User %d", 123) import “log” var Logger *log.Logger … Logger.Printf(“User %d”, 123)
  • 5. Singleton Optional Pattern type Logger struct { // … } var std = New(...) func Println(s string) { std.Println(s) }
  • 6. Structured Logging import "github.com/Sirupsen/logrus" logrus.WithField(“userID”, 123).Info(“Request”) https://github.com/inconshreveable/log15 log.Info(“Request”, “userID”, 123)
  • 7. Why not both? var Logger StdLogger = log.New(ioutil.Discard, "[Sarama] ", log.LstdFlags) // StdLogger is used to log error messages. type StdLogger interface { Print(v ...interface{}) Printf(format string, v ...interface{}) Println(v ...interface{}) }
  • 8. func abc() { log.Info("<- abc()") defer log.Info("-> abc()") // ... } Logging/defer pattern
  • 9. PProf help ● Goroutines ● Heap ● CPU usage ● Running command line
  • 10. PProf enabled import _ "net/http/pprof" go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }() // ... OR ... handler.PathPrefix("/debug/pprof/cmdline").HandlerFunc(pprof.Cmdline)
  • 11. /debug/pprof/goroutine 1 @ 0x96d3c8 0x96d1a3 0x968ae4 0x80543e 0x805650 0x4ef85a 0x5cca6e 0x4f1cbe 0x4ef31e 0x46ee91 1 @ 0x43dfd3 0x44c6d4 0x44bc32 0x4034ac 0x402279 0x43dbf0 0x46ee91 ...
  • 12. /debug/pprof/goroutine?debug=1 6 @ 0x43dfd3 0x4380fe 0x4375c0 0x499dda 0x499e46 0x49bb8a 0x4af6f4 0x502c07 0x50f110 0x6587a9 0x6589cc 0x4ffe07 0x46ee91 # 0x4375c0 net.runtime_pollWait+0x60 /usr/local/go/src/runtime/netpoll.go: 157 # 0x499dda net.(*pollDesc).Wait+0x3a /usr/local/go/src/net/fd_poll_runtime. go:73 # 0x499e46 net.(*pollDesc).WaitRead+0x36 /usr/local/go/src/net/fd_poll_runtime. go:78 # 0x49bb8a net.(*netFD).Read+0x23a /usr/local/go/src/net/fd_unix.go:232 # 0x4af6f4 net.(*conn).Read+0xe4 /usr/local/go/src/net/net.go:172 # 0x502c07 net/http.noteEOFReader.Read+0x67 /usr/local/go/src/net/http/transport. go:1370 # 0x50f110 net/http.(*noteEOFReader).Read+0xd0 <autogenerated>:126 # 0x6587a9 bufio.(*Reader).fill+0x1e9 /usr/local/go/src/bufio/bufio.go:97
  • 13. /debug/pprof/goroutine?debug=2 goroutine 37 [chan receive, 58 minutes]: github.com/Shopify/sarama.(*asyncProducer).topicDispatcher(0xc820015140) /opt/jenkins/workspace/prod/Godeps/_workspace/src/github. com/Shopify/sarama/async_producer.go:213 +0xf5 github.com/Shopify/sarama.(*asyncProducer).(github.com/Shopify/sarama.topicDispatcher)- fm() /opt/jenkins/workspace/prod/Godeps/_workspace/src/github. com/Shopify/sarama/async_producer.go:98 +0x20 github.com/Shopify/sarama.withRecover(0xc821adc720) /opt/jenkins/workspace/prod/Godeps/_workspace/src/github.com/Shopify/sarama/utils. go:42 +0x3a created by github.com/Shopify/sarama.NewAsyncProducerFromClient /opt/jenkins/workspace/prod/Godeps/_workspace/src/github. com/Shopify/sarama/async_producer.go:98 +0x340
  • 14. Go heap usage debugging ● alloc_objects very useful ● go’s CPU usage around GC strongly related to number of allocated objects
  • 15. Example go tool pprof -alloc_objects /tmp/server http://box:6060/debug/pprof/heap (pprof) top 578225004112 of 902319909557 total (64.08%) Dropped 756 nodes (cum <= 4511599547) Showing top 10 nodes out of 112 (cum >= 75735754111) flat flat% sum% cum cum% 58755173926 6.51% 27.36% 117454393178 13.02% github. com/golang/protobuf/proto.(*Buffer).dec_slice_bool ….
  • 16. Docker ● Containers! ● Easy deployment! ● Static compile makes small docker images ● SignalFx container size ○ Go => 5MB ○ Java => 450 MB
  • 17. Static go compiles for Docker CGO_ENABLED=0 go build -v -installsuffix . FROM scratch COPY ./ingest /ingest CMD ["/ingest"]
  • 18. ● Just export / for docker containers ● http.FileServer ● Good for self download (pprof needed) File explorer curl http://host.com:6060/debug/files/ingest >/tmp/ingest
  • 19. Expvar ● Export JSON strings or numbers ● Visible in a browser ● Easy to use ● Best use in func init() ● Cmd line/env/build SHA/etc
  • 20. Expvar the bad Unable to unregister a variable panic() on double register What about non init state? Global mutable state is an anti-pattern Luck for us, the code is open source!
  • 21. github.com/signalfx/golib/expvar2 e := expvar2.ExpvarHandler{} e.Exported["hello"] = expvar.Func(func() interface{} { return "world" }) e.Exported["distconf"] = distconf.Var() e.Exported["env"] = expvar2.EnviromentalVariables() handler.Path("/debug/vars").Handler(&e) // http://localhost:6060/debug/vars?pretty=1&filter=env
  • 22. Dynamic config ● Config for queue sizes, timeouts, etc ● We use zookeeper for config ● env > file > zookeeper ○ file/env allow easy testing and dev ● Turn debug levels on/off ● Can debug specific requests ● https://github.com/signalfx/golib
  • 23. Dependencies ● Using master of dependencies is bad ● Need repeatable builds ● Vendoring is a requirement ● No pip, no cargo, no npm :( :( :( ● I blame “go get” for this mess ● https://github.com/kardianos/govendor ● https://github.com/tools/godep
  • 24. Exported metrics ● Open source ○ Graphite ○ OpenTSDB ○ InfluxDB ● SaaS ○ SignalFx ● runtime.NumGoroutine() ● runtime.ReadMemStats() ○ TotalAlloc ○ Alloc ○ PauseTotalNs ● time.Now().Sub(start) ● runtime.NumCgoCall()
  • 25. Count/defer pattern atomic.AddInt64(&m.TotalConnections, 1) atomic.AddInt64(&m.ActiveConnections, 1) defer atomic.AddInt64(&m.ActiveConnections, -1) start := time.Now() next.ServeHTTP(rw, r) reqTime := time.Since(start) atomic.AddInt64(&m.TotalTimeNS, reqTime.Nanoseconds())
  • 26. A single bad server
  • 28. Object explorer ● What if you forgot to export a variable? ● Uses reflection for ad hoc exploration ● https://github. com/signalfx/golib/tree/master/explorable
  • 32. Static checks ● golang.org/x/tools/cmd/goimports ● gofmt ● golang.org/x/tools/cmd/vet ● github.com/golang/lint/golint ○ Will need filters ● github.com/fzipp/gocyclo ● golang.org/x/tools/cmd/cover ● Wrapped into https://github.com/cep21/goverify