Go in Production

31
Go in Production How to get thereand stay there! John-Alan Simmons

Transcript of Go in Production

Page 1: Go in Production

Go in ProductionHow to get there… and stay there!

John-Alan Simmons

Page 2: Go in Production

John-Alan Simmons @jsimnz @iamjsimnz

Page 3: Go in Production

Introduction

if new_to_go || played_with_go {

fmt.Println(“Keep watching!”)

} else {

fmt.Println(“Still keep watching!”

}

Page 4: Go in Production

28 March 2012 - Go1

● Why is this important?● Go1 Guarantee

○ Officially stable to develop with!

Page 5: Go in Production

● One of the first companies to publicly use Go● Went from 30 servers to 2

Page 6: Go in Production

How to get there...

Page 7: Go in Production

“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

Page 8: Go in Production

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

Page 9: Go in Production
Page 10: Go in Production

Go is Compiled …

● Compiler will catch lots of errors● Few runtime crashes● Build once, deploy (mostly) everywhere

○ Even cross compile■ github.com/mitchellh/gox

Page 11: Go in Production

… Statically Compiled

● No shared library management● Produces a single binary● Easy to distribute to production servers

○ scp, rsync, even s3

Page 12: Go in Production

import “testing”

● Great builtin testing package○ and benchmarking

● Integrated directly into the tooling● Very handy since Go doesn’t have good

debugging support

Page 13: Go in Production

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!

Page 14: Go in Production

Vendoring VS Versioning

Page 15: Go in Production

Vendoring

● Downloads 3rd party packages into project folder

● Keith Rarick’s, Godep○ github.com/kr/godep○ locally saves 3rd party packages

Page 16: Go in Production

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”

Page 17: Go in Production
Page 18: Go in Production

How to stay there….

Page 19: Go in Production

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

Page 20: Go in Production

Upstart/Systemd

● Very common to use● Process supervision● Explicit control● Properly create background go applications

Page 21: Go in Production

Code updates

● 2 standard options code updates○ Zero-downtime restarts○ Graceful shutdown & seamless proxying

Page 22: Go in Production

Zero-downtime Restarts

● Self updating● Same problems as daemonizing programs● Richard Crowley’s, Goagain

○ github.com/rcrowley/goagain○ Problems with os.Exit()

Page 23: Go in Production

Graceful shutdown & proxying

● Stop accepting requests on SIGINT● Release socket FD● Start new process● Wait for current requests to finish● Exit.

Page 24: Go in Production

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

Page 25: Go in Production

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

Page 26: Go in Production

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

Page 27: Go in Production

Go-Metrics, github.com/rcrowley/go-metrics

● Custom metrics○ Gauges○ Meters○ Counters○ ExpDecaySample○ EMA○ Histograms○ etc….

● Custom backends○ Stderr○ Syslog○ Graphite○ Influxdb○ Librato○ StatHat

Page 28: Go in Production

NewRelic Monitoring

● Yuriy Vasiyarov’s, Gorelic○ github.com/yvasiyarov/gorelic○ Uses Go-Metrics○ Middleware

■ Beego■ revel■ gocraft■ martini

Page 29: Go in Production

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

Page 30: Go in Production
Page 31: Go in Production

Golang gopher thanks you!

Questions?