InterCon 2016 - Software as a service usando Go como principal linguagem: os cases globo.com
-
Upload
imasters -
Category
Technology
-
view
62 -
download
0
Transcript of InterCon 2016 - Software as a service usando Go como principal linguagem: os cases globo.com
Who Am I
● Desenvolvedor na Globo.com desde 2008● Criado de projetos open source como Splinter e tsuru
Canais
func compute(ch chan int) {ch <- someComputation()
}
func main() {ch := make(chan int)go compute(ch)result := <-ch
}
Canais
func compute(ch chan int) {ch <- someComputation()
}
func main() {ch := make(chan int)go compute(ch)result := <-ch
}
http
func main() { http.HandleFunc("/hello", handleHello) http.ListenAndServe("localhost:7777", nil)}
func handleHello(w http.ResponseWriter, req *http.Request) { fmt.Fprintln(w, "Hello, 世界!")}
http + encodingtype user struct { Name string}
func userHandler (w http.ResponseWriter, r *http.Request) {u := user{Name: “andrews”}b, err := json.Marshal(u)if err != nil {
panic(err) } w.Write(b)}
gofmt
func main() { http.HandleFunc("/hello", handleHello) http.ListenAndServe("localhost:7777", nil)}
gofmt
func main() {http.HandleFunc("/hello", handleHello)http.ListenAndServe("localhost:7777", nil)
}
race detectorfunc main() {
start := time.Now()var t *time.Timert = time.AfterFunc(randomDuration(), func() {
t.Reset(randomDuration())})time.Sleep(5 * time.Second)
}
func randomDuration() time.Duration {return time.Duration(rand.Int63n(1e9))
}
race detectorpanic: runtime error: invalid memory address or nil pointer dereference[signal 0xb code=0x1 addr=0x8 pc=0x41e38a]
goroutine 4 [running]:time.stopTimer(0x8, 0x12fe6b35d9472d96) src/pkg/runtime/ztime_linux_amd64.c:35 +0x25time.(*Timer).Reset(0x0, 0x4e5904f, 0x1) src/pkg/time/sleep.go:81 +0x42main.func·001() race.go:14 +0xe3created by time.goFunc src/pkg/time/sleep.go:122 +0x48
race detector==================WARNING: DATA RACERead by goroutine 5: main.func·001() race.go:14 +0x169
Previous write by goroutine 1: main.main() race.go:15 +0x174
Goroutine 5 (running) created at: time.goFunc() src/pkg/time/sleep.go:122 +0x56 timerproc() src/pkg/runtime/ztime_linux_amd64.c:181 +0x189==================
tsuru (vantagens)
● Baixo overhead● Cross compile (windows, linux, mac)● Performance, no-blocking I/O, concorrência e paralelismo
Cartola
● Performance sem precisar “escovar bits”● Antes 24 máquinas com 24 cores● Agora 24 máquinas com 4 cores