Best practices-for-production-environments

50 %
50 %
Information about Best practices-for-production-environments

Published on April 27, 2014

Author: ArtemKovardin

Source: slideshare.net

Best Practices for Production Environments

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


Some Go
 Projects Bazooka Traffic tier Media streaming Search & Explore glue Prometheus Stream backend* HLS implementation** Many others…

Dev environment Repo structure Formatting and style Configuration Logging and telemetry Validation and testing Dependency management ᕕ( ᐛ )ᕗ Build and deploy

Dev environment

Single GOPATH for all projects Work in $GOPATH/src/github.com/soundcloud/foo vim, Sublime Text, emacs—no IDEs

Repo structure

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


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


github.com/soundcloud/whatever/
 README.md
 Makefile
 whatever-server/
 main.go
 whatever-worker/
 main.go
 foo/
 foo.go
 bar.go

Formatting and style

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

func process(dst io.Writer, readTimeout, 
 writeTimeout time.Duration, allowInvalid bool,
 max int, src <-chan util.Job) {
 // ...
 }

func process(
 dst io.Writer,
 readTimeout, writeTimeout time.Duration,
 allowInvalid bool,
 max int,
 src <-chan util.Job,
 ) {
 // ...
 }

f := foo.New(foo.Config{
 “zombo.com”,
 conference.KeyPair{
 Key: “gophercon”, // String value
 Value: 2014,
 },
 os.Stdout,
 })

Configuration

package flag

func main() {
 var (
 foo = flag.String(“foo”, “doch”, “...”)
 bar = flag.Int(“bar”, 34, “...”)
 )
 flag.Parse()
 // ...
 }

Logging and telemetry

Logging and telemetry

package log

Logging and telemetry

Push
 model Pull
 model vs. Graphite
 Statsd
 AirBrake expvar
 Prometheus
 others?

Testing and validation

Testing and validation

package testing ☞reflect.DeepEqual☜

// +build integration
 
 var fooAddr = flag.String(...)
 
 func TestFoo(t *testing.T) {
 f, err := newFoo(*fooAddr)
 // ...
 }

Testing and validation

Save Build onon go fmt goimports or go vet golint go test and and maybe Deploy on go test 
 -tags=integration gocov?

YAGNI

Dependency management

How important is your project? go get -d & hope! VENDOR Eh Very ☞ ☞ import proxy?

VENDOR submodules with subtrees with a tool with ✖✖✖ means copy your dependencies

Binary VENDOR Library _vendor
 subdirectory Blessed build, with
 prefixed GOPATH + vendor
 subdirectory Rewrite your
 imports + ☞ ☞

Build and deploy

Build and deploy

Development “Official” ☞ go build ☞ make

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

Build and deploy

StatefulStateless Any/no model12-Factor model ProvisionedScaled vs. Containers Containers? MySQL, RedisRequest router

$ git push bazooka master
 $ bazooka scale -r <new> -n 4 ...
 $ # validate
 $ bazooka scale -r <old> -n 0 ... Deploying
 stateless
 services

Embrace simplicity

Thanks! ! Peter Bourgon @peterbourgon Questions?

Add a comment

Related pages

Go: Best Practices for Production Environments

Go: Best Practices for Production Environments (This was originally a talk at GopherCon 2014. Find the slides here, and the video here.) (This article has ...
Read more

Best practice for test and production environments - Stack ...

Best practice for test and production environments. up vote 2 down vote favorite. In the company I work, ... What is the best practice about environments?
Read more

Go: Best Practices for Production Environments : golang

reddit: the front page of the internet ... Great article, but I feel like there is a misprint. First they say that when you make a library your vendored ...
Read more

Oracle VM Server for SPARC Best Practices

ORACLE VM SERVER FOR SPARC BEST PRACTICES ... and describes best practices for production environments with intense resource, performance, ...
Read more

GopherCon 2014 Best Practices for Production Environments ...

Go is a simple language. Sometimes, that simplicity means that common, peripheral tasks are deferred to other tools to solve. This talk will ...
Read more

Go: Best Practices for Production Environments - CSDN.NET

If you ship a binary, create a _vendor subdirectory in the root of your repository. (With a leading underscore, so the go tool ignores it when doing e.g ...
Read more

packaging-best-practices.html - Oracle

Best Practices for Building Production Quality EAR Files. by Hussein Badakhchani ... Packaging Best Practices for Production Environments.
Read more

Best Practices for Production Environments · astaxie/2014 ...

Showing 1 changed file with 0 additions and 0 deletions. BIN best-practices-for-production-environments.pdf
Read more

Go: Best Practices for Production Environments - 第七城市

基于spring boot和Docker搭. Head First Java 学习笔记一. Mycat架构分析. SeimiCrawler抓取并整合多页 [JAVA WEB] 集成 MyBatis Ge. RabbitMQ ...
Read more