Go in Production
-
Upload
john-alan-simmons -
Category
Engineering
-
view
132 -
download
1
Transcript of Go in Production
Go in ProductionHow to get there… and stay there!
John-Alan Simmons
John-Alan Simmons @jsimnz @iamjsimnz
Introduction
if new_to_go || played_with_go {
fmt.Println(“Keep watching!”)
} else {
fmt.Println(“Still keep watching!”
}
28 March 2012 - Go1
● Why is this important?● Go1 Guarantee
○ Officially stable to develop with!
● One of the first companies to publicly use Go● Went from 30 servers to 2
How to get there...
“One of Go's key design goals is code adaptability; that it should be easy to take a simple design and build upon it in a clean and natural way.”
- Andrew Gerrand
Go is well designed
● Simple but extensive standard library● Easy to write maintainable code
○ Quick to prototype○ Quicker to refactor into maintainable code
● When in doubt, consult the standard library
Go is Compiled …
● Compiler will catch lots of errors● Few runtime crashes● Build once, deploy (mostly) everywhere
○ Even cross compile■ github.com/mitchellh/gox
… Statically Compiled
● No shared library management● Produces a single binary● Easy to distribute to production servers
○ scp, rsync, even s3
import “testing”
● Great builtin testing package○ and benchmarking
● Integrated directly into the tooling● Very handy since Go doesn’t have good
debugging support
Dependency Management
● No builtin dependancy or package management (sort of)
● “Build it and they will come”● go get tool
○ Always pulls from master○ Can shoot yourself in the foot!
Vendoring VS Versioning
Vendoring
● Downloads 3rd party packages into project folder
● Keith Rarick’s, Godep○ github.com/kr/godep○ locally saves 3rd party packages
Versioning
● import specific versions of 3rd party packages
● Gustavo Niemeyer’s, gopkg.in○ Basically a go get proxy server to point to specific
versions○ Ex. “import github.com/jsimnz/gotter” => “import gopkg.
in/jsimnz/gotter.v1”
How to stay there….
Running Applications
● No (traditional) deamonize support○ Due to package initialization and goroutines○ Lots of discussions on it
● godaemon, ○ github.com/VividCortex/godaemon○ Uses os.StartProcess, twice○ Can access stdout & stderr○ Keep open files
Upstart/Systemd
● Very common to use● Process supervision● Explicit control● Properly create background go applications
Code updates
● 2 standard options code updates○ Zero-downtime restarts○ Graceful shutdown & seamless proxying
Zero-downtime Restarts
● Self updating● Same problems as daemonizing programs● Richard Crowley’s, Goagain
○ github.com/rcrowley/goagain○ Problems with os.Exit()
Graceful shutdown & proxying
● Stop accepting requests on SIGINT● Release socket FD● Start new process● Wait for current requests to finish● Exit.
Graceful shutdown & proxying II
● Stretchr’s, Graceful○ github.com/stretchr/graceful○ Waits for all requests to finish
● Miki Tebeka’s, Seamless○ bitbucket.org/tebeka/seamless○ Seamless TCP proxy
import “log”
● Builtin logging package○ similar to fmt but prints to stderr○ import “log/syslog”, interface to syslog
● Many, many, many 3rd party logging● go-logging
○ github.com/op/go-logging○ Great, full featured logging library
Monitoring & Metrics
● Low-level builtin runtime pprof, import runtime/pprof○ goroutines○ heaps○ threadcreate○ block
● Builtin runtime debug, import runtime/debug○ Garbage Collector stats○ Memory stats
Go-Metrics, github.com/rcrowley/go-metrics
● Custom metrics○ Gauges○ Meters○ Counters○ ExpDecaySample○ EMA○ Histograms○ etc….
● Custom backends○ Stderr○ Syslog○ Graphite○ Influxdb○ Librato○ StatHat
NewRelic Monitoring
● Yuriy Vasiyarov’s, Gorelic○ github.com/yvasiyarov/gorelic○ Uses Go-Metrics○ Middleware
■ Beego■ revel■ gocraft■ martini
PAAS
● Great support for PAAS○ Heroku○ Google App Engine○ OpenShift○ AWS Elastic Beanstalk○ DotCloud○ Tsuru○ And more…
■ code.google.com/p/go-wiki/wiki/ProviderIntegration
Golang gopher thanks you!
Questions?