Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Best practices-for-production-environments

7,545 views

Published on

Published in: Engineering, Technology
  • Hey! Stop when you hit £700 profit on the week! Want to get started and make £700 this week? He's running a special introductory offer for the start of 2020 but this ends soon. CLICK HERE TO JOIN.. ▲▲▲ https://bit.ly/30jWepO
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • See how I make over $7,293 a month from home doing REAL online jobs! ★★★ http://t.cn/AisJWYf4
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/2ZDZFYj ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ♥♥♥ http://bit.ly/2ZDZFYj ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Earn Up To $316/day! Easy Writing Jobs from the comfort of home! ★★★ https://tinyurl.com/vvgf8vz
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Best practices-for-production-environments

  1. Best Practices for Production Environments
  2. These slides may not make much sense without a narrative! For the proper article, see
 http://peter.bourgon.org/go-in-production

  3. Some Go
 Projects Bazooka Traffic tier Media streaming Search & Explore glue Prometheus Stream backend* HLS implementation** Many others…
  4. Dev environment Repo structure Formatting and style Configuration Logging and telemetry Validation and testing Dependency management ᕕ( ᐛ )ᕗ Build and deploy
  5. Dev environment
  6. Single GOPATH for all projects Work in $GOPATH/src/github.com/soundcloud/foo vim, Sublime Text, emacs—no IDEs
  7. Repo structure
  8. github.com/soundcloud/whatever/
 README.md
 Makefile
 main.go
 support.go
 
 
 
 

  9. github.com/soundcloud/whatever/
 README.md
 Makefile
 main.go
 support.go
 foo/
 foo.go
 bar.go
 

  10. github.com/soundcloud/whatever/
 README.md
 Makefile
 whatever-server/
 main.go
 whatever-worker/
 main.go
 foo/
 foo.go
 bar.go
  11. Formatting and style
  12. go fmt Google’s Code Review Guidelines Avoid named return parameters Avoid make and new (unless you know sizes) Use struct{} for sentinel value: sets, signal chans Break long lines on parameters
  13. func process(dst io.Writer, readTimeout, 
 writeTimeout time.Duration, allowInvalid bool,
 max int, src <-chan util.Job) {
 // ...
 }
  14. func process(
 dst io.Writer,
 readTimeout, writeTimeout time.Duration,
 allowInvalid bool,
 max int,
 src <-chan util.Job,
 ) {
 // ...
 }
  15. f := foo.New(foo.Config{
 “zombo.com”,
 conference.KeyPair{
 Key: “gophercon”, // String value
 Value: 2014,
 },
 os.Stdout,
 })
  16. Configuration
  17. package flag
  18. func main() {
 var (
 foo = flag.String(“foo”, “doch”, “...”)
 bar = flag.Int(“bar”, 34, “...”)
 )
 flag.Parse()
 // ...
 }
  19. Logging and telemetry
  20. Logging and telemetry
  21. package log
  22. Logging and telemetry
  23. Push
 model Pull
 model vs. Graphite
 Statsd
 AirBrake expvar
 Prometheus
 others?
  24. Testing and validation
  25. Testing and validation
  26. package testing ☞reflect.DeepEqual☜
  27. // +build integration
 
 var fooAddr = flag.String(...)
 
 func TestFoo(t *testing.T) {
 f, err := newFoo(*fooAddr)
 // ...
 }
  28. Testing and validation
  29. Save Build onon go fmt goimports or go vet golint go test and and maybe Deploy on go test 
 -tags=integration gocov?
  30. YAGNI
  31. Dependency management
  32. How important is your project? go get -d & hope! VENDOR Eh Very ☞ ☞ import proxy?
  33. VENDOR submodules with subtrees with a tool with ✖✖✖ means copy your dependencies
  34. Binary VENDOR Library _vendor
 subdirectory Blessed build, with
 prefixed GOPATH + vendor
 subdirectory Rewrite your
 imports + ☞ ☞
  35. Build and deploy
  36. Build and deploy
  37. Development “Official” ☞ go build ☞ make
  38. GOVER=go1.2.1 ! STAGE=.stage GOPATH=$(CURDIR)/$(STAGE)/gopath GOROOT=$(CURDIR)/$(STAGE)/go GOCC=$(GOROOT)/bin/go GO=TMPDIR=/tmp GOROOT=$(GOROOT) GOPATH=$(GOPATH) $(GOCC) ! OS=$(shell uname) ARCH=$(shell uname -m) GOOS=$(subst Darwin,darwin,$(subst Linux,linux,$(OS))) GOARCH=$(subst x86_64,amd64,$(ARCH)) GOPKG=$(subst darwin-amd64,darwin-amd64-osx10.8,$(GOVER).$(GOOS)-$(GOARCH).tar.gz) ! PKGBASE=github.com/soundcloud/goku PKGPATH=$(GOPATH)/src/$(PKGBASE) ! all: build ! build: $(GOCC) $(PKGPATH) GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C roshi-server build GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C roshi-walker build GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C reader build GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C writer build GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C gap-backfill build ! clean: GOPATH=$(GOPATH) GOROOT=$(GOROOT) GO=$(GOCC) make -C roshi-server clean
  39. Build and deploy
  40. StatefulStateless Any/no model12-Factor model ProvisionedScaled vs. Containers Containers? MySQL, RedisRequest router
  41. $ git push bazooka master
 $ bazooka scale -r <new> -n 4 ...
 $ # validate
 $ bazooka scale -r <old> -n 0 ... Deploying
 stateless
 services
  42. Embrace simplicity
  43. Thanks! ! Peter Bourgon @peterbourgon Questions?

×