Slide 1

Slide 1 text

Software Engineering with Go in Infrasturecture Tatsuhiko Kubo@cubicdaiya Go All Stars@2015/10/11 ʙmercari.goʙ

Slide 2

Slide 2 text

@cubicdaiya / Tatsuhiko Kubo • Software Engineer @ Mercari, Inc. • Infrastructure Engineering • Skills • C, Go, Lua, nginx, … • OSS Developer • ngx_small_light, ngx_dynamic_upstream, nginx-build, slackboard, cachectl, gaurun, …

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

https://www.mercari.com/ Mercari - Your Friendly Mobile Marketplace

Slide 5

Slide 5 text

@cubicdaiya / Tatsuhiko Kubo • Software Engineer @ Mercari, Inc. • Infrastructure Engineering • Skills • C, Go, Lua, nginx, … • OSS Developer • ngx_small_light, ngx_dynamic_upstream, nginx-build, slackboard, cachectl, gaurun, …

Slide 6

Slide 6 text

@cubicdaiya / Tatsuhiko Kubo • Software Engineer @ Mercari, Inc. • Infrastructure Engineering • Skills • C, Go, Lua, nginx, … • OSS Developer • ngx_small_light, ngx_dynamic_upstream, nginx-build, slackboard, cachectl, gaurun, …

Slide 7

Slide 7 text

Infrastructure Engineeringʁ • Responsible for • DevOps / Reliability / Scalability / Performance / Security / Troubleshooting / … • Works are various and varies by • position / organization structure / authoritiy / speciality

Slide 8

Slide 8 text

As for me • Basically, • Almost all root-user can doʂ • Especially, • Software Engineering in Infrastructure Usually, I designate myself as Software Engineer in Infrastructure Engineering.

Slide 9

Slide 9 text

Software Engineering in Infrastructure@myself • Developing & Operating • CLI-tools for usual oprations • e.g. nginx-build, slackboard, cachectl • High performance & Scalable systems (e.g. ↓) • Gaurunʙpush system@Mercariʙ • Pascalʙlog analysis base@Mercariʙ • Task force (e.g. Migration from PHP5.3 to 5.6)

Slide 10

Slide 10 text

Software Engineering in Infrastructure • Developing & Operating • CLI-tools for operations • e.g. nginx-build, slackboard, cachectl • High performance & Scalable systems (e.g. ↓) • Gaurunʙpush system@Mercariʙ These are built with Go

Slide 11

Slide 11 text

Reason I select Go • Go has features Software Engineer in Infrastructure Engineering likes • Simple build and deployment • Powerful cuncurrency support • Enough scalability & productivity & robustness • Go fits in many situations as alternative for C and LL

Slide 12

Slide 12 text

Reason I select Go • I like C • In my opinion, • Go is C in 21st century • Rust is C++ in 21st century

Slide 13

Slide 13 text

mercari.go families • cubicdaiya / nginx-build • cubicdaiya / cachectl • cubicdaiya / slackboard • mercari / gaurun • etc…

Slide 14

Slide 14 text

nginx-build • Seamless nginx builder • https://github.com/cubicdaiya/nginx-build • Single-binary does everything for building nginx • Download source • Embed external libraries (PCRE, ZLIB, OpenSSL) • Embed 3rd party modules

Slide 15

Slide 15 text

Building nginx with nginx-build $ nginx-build -d work -pcre -zlib -openssl nginx-build: 0.6.0 Compiler: gc go1.5.1 2015/10/11 02:19:10 Download nginx-1.9.5..... 2015/10/11 02:19:10 Download openssl-1.0.2d..... 2015/10/11 02:19:10 Download zlib-1.2.8..... 2015/10/11 02:19:10 Download pcre-8.37..... 2015/10/11 02:19:12 Extract nginx-1.9.5.tar.gz..... 2015/10/11 02:19:12 Extract zlib-1.2.8.tar.gz..... 2015/10/11 02:19:22 Extract pcre-8.37.tar.gz..... 2015/10/11 02:19:25 Extract openssl-1.0.2d.tar.gz..... 2015/10/11 02:19:25 Generate configure script for nginx-1.9.5..... 2015/10/11 02:19:25 Configure nginx-1.9.5..... 2015/10/11 02:19:32 Build nginx-1.9.5..... 2015/10/11 02:22:19 Complete building nginx! ... 2015/10/11 02:22:19 Enter the following command for install nginx. $ cd work/nginx/1.9.5/nginx-1.9.5 $ sudo make install download concurrently

Slide 16

Slide 16 text

Download concurrently parallels := 0 done := make(chan bool) (...) if *pcreStatic { parallels++ go downloadAndExtractParallel(&pcreBuilder, done) } if *openSSLStatic { parallels++ go downloadAndExtractParallel(&openSSLBuilder, done) } if *zlibStatic { parallels++ go downloadAndExtractParallel(&zlibBuilder, done) } parallels++ go downloadAndExtractParallel(&nginxBuilder, done) (...) for i := 0; i < parallels; i++ { <-done }

Slide 17

Slide 17 text

Go as alternative for shellscript • Before I started to write nginx-build with shellscript • after 2 hours -> (ϊ ʄДʄ)ϊ~~~ᵲᵲ • I noticed Go fits in this case • Easy to maintain and distribute binary • Cross-platform support

Slide 18

Slide 18 text

cachectl • Page cache controller • https://github.com/cubicdaiya/cachectl • CLI-tool for controlling page cache for OS • Daemonization as cachectld is available

Slide 19

Slide 19 text

Seamless combination with C • cachectl requires • communication with system calls (posiv_fadivse, mincore, mmap, etc…) • Go provides FFI (cgo) // C.xxx() are functions came from C world func activePages(path string) int { cs := C.CString(path) result := C.activePages(cs) C.free(unsafe.Pointer(cs)) return int(result) }

Slide 20

Slide 20 text

Cautions for cgo • Allocated objects must be released manually • Not garvage-collected • e.g. Object generated with C.CString(string) requires C.free() • cgo is possible to cause slow-compilation

Slide 21

Slide 21 text

slackboard • Slack proxy server • https://github.com/cubicdaiya/slackboard • Building blocks • slackboardʙslack proxy serverʙ • slackboard-cliʙclient for slackboardʙ • slackboard-logʙclient for blackboard like cronlogʙ

Slide 22

Slide 22 text

Use case for Mercari

Slide 23

Slide 23 text

slackboard-cli $ echo mercari | \ slackboard-cli \ -c tech-test \ -s slackboard-server:29800 TMBDLCPBSE POST /notify-directly Post to Slack

Slide 24

Slide 24 text

slackboard-log $ ls $ slackboard-log \ -c tech-test \ -s slackboard-server:29800 -- ls hoge TMBDLCPBSE POST /notify-directly Post to Slack

Slide 25

Slide 25 text

Go simplifies build all: bin/slackboard bin/slackboard-cli bin/slackboard-log gom: go get -u github.com/mattn/gom bundle: gom install bin/slackboard: slackboard.go slackboard/*.go gom build $(GOFLAGS) -o bin/slackboard slackboard.go bin/slackboard-cli: slackboard-cli.go slackboard/*.go gom build $(GOFLAGS) -o bin/slackboard-cli slackboard-cli.go bin/slackboard-log: slackboard-log.go slackboard/*.go gom build $(GOFLAGS) -o bin/slackboard-log slackboard-log.go fmt: go fmt ./... clean: rm -rf bin/slackboard* Each mercari.go family has small Makefile

Slide 26

Slide 26 text

Go simplifies deployment • Go programs are available as single-binary • Easy to package with RPM • At mercari, administrators can install and update them with yum • cachectl & slackboard-cli are deployed on all servers at setup

Slide 27

Slide 27 text

Gaurun • A general push notification server for smartphone application • https://github.com/mercari/gaurun • Proxing push-requests to APNS and GCM • Provides HTTP APIs

Slide 28

Slide 28 text

Push system@mercari

Slide 29

Slide 29 text

Requirements for Gaurun • As HTTP server • Good performance • High Concurrency • net/http is good choice

Slide 30

Slide 30 text

Gaurun Internals • Gaurun consists of • HTTP server / Job Queue / Job Workers • Job Queue is channel • Job Worker is goroutine

Slide 31

Slide 31 text

Gaurun Internals (BVSVO )551 1045QVTI #PEZJT+40/ $MJFOU 1VTI/PUJpDBUJPO 8PSLFS 1VTI/PUJpDBUJPO 8PSLFS 2VFVF 1VTI/PUJpDBUJPO )BOEMFS &ORVFVF 1VTI/PUJpDBUJPO 8PSLFS 1VTI/PUJpDBUJPO 8PSLFS %FRVFVF

Slide 32

Slide 32 text

Go is powerful • Go provides enough • scalability & productivity & robustness • Gaurun scales easily • 1st version of slackboard was written in 1 hour • mercari.go families work fineʂ

Slide 33

Slide 33 text

Summary • Go has features Software Engineer in Infrastructure Engineering likes • Simple build and deployment • Powerful cuncurrency support • Enough scalability & productivity & robustness • Go fits in many situations as alternative for C and LL

Slide 34

Slide 34 text

We are hiring!