scaling applications with go

34
SCALING APPLICATIONS WITH GO -Vimlesh Sharma

Upload: vimlesh-sharma

Post on 16-Jul-2015

381 views

Category:

Education


2 download

TRANSCRIPT

Page 2: Scaling applications with go

Introduction

What does Go offer?

Where go can be used?

Go in Production

Go in comparison to other language

Case studies

TABLE OF CONTENTS

Page 3: Scaling applications with go

Go is a general-purpose programming language, like Python,

Java, or C

It is commonly referred to as golang.

A programming language developed at Google in 2007

Main contributor were Robert Griesemer, Rob Pike, and Ken

Thompson.

INTRODUCTION

Page 4: Scaling applications with go

WHAT DOES GO OFFER ?

Page 5: Scaling applications with go

Go is relatively

compact language

easier to learn

Go language spec is webpage (http://golang.org/ref/spec )

that prints as a 56 page PDF compared to others

Java SE – 768 pages http://docs.oracle.com/javase/specs/

Scala – 183 pages http://www.scala-

lang.org/docu/files/ScalaReference.pdf

Go documentation is better than other languages.

A SIMPLE LANGUAGE THAT IS EASY TO

LEARN AND READ.

Page 6: Scaling applications with go

Go combines ease of programming in an interpreted &

dynamically typed language.

Also it provides high efficiency and safety of a statically

typed, compiled language.

var intA int

intA = 32 // intA has 32 and is static type int

intB := 42 // intB has value 42 and dynamic type int

STATICALLY TYPED, BUT WITH A DYNAMIC

FEEL

Page 7: Scaling applications with go

Like C and C++, Go compiles to native machine code so that

we don’t need environments such as CLR and JVM to run Go

applications.

Go compiler compiles programs very quickly that helps

particularly when compiling large applications

‘Gocc ’ is a go compiler’s compiler

https://code.google.com/p/gocc/

COMPILED TO NATIVE MACHINE CODE

Page 8: Scaling applications with go

Go is concurrent system

Concurrency is a way to structure a program by breaking it

into pieces that can be executed independently.

Concurrency vs. parallelism

Concurrency is about dealing with lots of things at once

Parallelism is about doing lots of things at once

Not the same, but related

Concurrency is about structure, parallelism is about execution

Concurrency provides a way to structure a solution to solve a

problem that may (but not necessarily) be parallelizable

GO SUPPORTS CONCURRENCY

Page 9: Scaling applications with go

In Go, concurrency is a first -class citizen in the core language

Go introduces Goroutines, which lets you run functions

concurrently.

You can communicate and pass values between Goroutines

using Channels.

Goroutines and Channels are great features of Go that let you

leverage concurrency and parallelism

LANGUAGE-LEVEL CONCURRENCY FEATURES

Page 10: Scaling applications with go

Go’s standard libraries are exemplary.

Go also provide 3rd party packages.

Go’s package management system is designed to work with

modern scenarios

e.g. sharing it with developers overs GIT repository) unlike NPM,

NuGet, RubyGem

EXPANSIVE STANDARD LIBRARY

Page 11: Scaling applications with go

Go provides lots of tools for managing documentation,

testing, package management, and more.

go doc : can be used to pull documentation for anything in

codebase.

go test : This is one of the easiest testing setup

go get : This is used to pull the shared source code from GIT

GREAT TOOLS

Page 12: Scaling applications with go

WHERE CAN GO CAN BE

USED?

Page 13: Scaling applications with go

Server application

Command-line tools - https://github.com/codegangsta/cli

Web applications

Games - http://go-ngine.com/

Scientific computing -

https://archive.fosdem.org/2014/schedule/event/hpc_devroo

m_go/

Android & IOS development (in upcoming versions)

Many More...

USAGE

Page 14: Scaling applications with go

USING GO IN

PRODUCTION

Page 15: Scaling applications with go

Go produces statically linked binaries that are self sufficient.

Single binary makes deployment super -easy.

This is great when compared to other dependency setup that

is required for most other application.

SINGLE BINARY

Page 16: Scaling applications with go

Go has excellent support for cross compilation.

gonative is a simple tool which creates a build of Go that can

cross compile to all platforms. –

http://github.com/inconshreveable/gonative

http://dave.cheney.net/2013/07/09/an-introduction-to-cross-

compilation-with-go-1-1

CROSS COMPILATION

Page 17: Scaling applications with go

There is excellent support for

Live profiling capability for CPU

Memory

Goroutines

OS threads

Lock contention etc

Read more at http://blog.golang.org/profiling -go-programs

Use go toolchain and profile the application on-demand.

BUILT-IN PROFILING

Page 18: Scaling applications with go

C++ Java Javascript Scala Go

Type Safe

Garbage Collection

Compilation Slow Slow NA Slow Fast

Concurrency

Ease of Programming

Efficiency Highest Moderate Slow Good Close to C++

GO IN COMPARISON TO OTHER LANGUAGE

Page 19: Scaling applications with go

BENCHMARKING ON JSON RESPONSE.

Nodejs 32.8% https://www.techempower.com/benchmarks/#section=data-r9&hw=i7&test=json

Page 20: Scaling applications with go

CASE STUDY FROM

GOPHERCONINDIA 15

Page 21: Scaling applications with go

Ruby is a complex language

Memory consumption and speed

Lot of caching data in memory for speed, GC in Ruby consumed a lot

of time ultimately hindering performance.

Concurrency

The safest way to do concurrency in Ruby is through the use of

multiple processes, so app uses many workers and hence memory

consumption.

FROM A RUBY MONOLITH TO MICROSERVICES

IN GO

Page 22: Scaling applications with go

Instead of refactoring the entire application, moving selected

component to a micro services architecture in go increased

the efficiency.

Main Application + Go Micro services boost application

performance.

https://sourcegraph.com/blog/live/gopherconindia/1126565

68167

SOLUTION/OBSERVATION

Page 23: Scaling applications with go

N1QL pronounced as “nickel”.

N1QL is a query language developed in Go for Couchbase, a

distributed NoSQL database.

With N1QL scalable application can be developed quickly

N1QL: A QUERY LANGUAGE IN GO

Page 24: Scaling applications with go

SIGNIFICANT LOWER DEVELOPMENT COST.

C++ 210 days Go 150 days C++ 400 bugs Go 250 bugs

Page 25: Scaling applications with go

Benchmarks show that Go compares favorably with C++ and

Java

In C++, they had to experiment with a bunch of dif ferent

libraries

In Java, they had to fiddle around with a bunch of parameters

l ike the min heap size

Go worked well out of the box -

https://sourcegraph.com/blog/live/gopherconindia/1116380

91937

SOLUTION/OBSERVATION

Page 26: Scaling applications with go

Extract dominant color from images.

Generate Insight based on product color

Pain Point:

They were having high system usage.

Avg mem. consumption was more than 70%

PROCESSING IMAGES WITH GO

Page 27: Scaling applications with go

Existing architecture

Modified architecture

Page 28: Scaling applications with go

Serves more request

Server usage never exceeds more than 50 -60%

Easier deployment

Only golang standard library used -

https://sourcegraph.com/blog/live/gopherconindia/1116486

97747

SOLUTION/OBSERVATION

Page 29: Scaling applications with go

EMBD

http://www.raspberrypi.org

Page 30: Scaling applications with go

Requirement

Static binary.

Efficient Code.

Zero latency(real time)

Cross Platform

Initial choice was Python (Dropped – Restricted library)

EMBD a package entirely written in Go

High Performance.

SOLUTION/OBSERVATION

https://sourcegraph.com/blog/live/gopherconindia/111626334627

Page 31: Scaling applications with go

LIST OF COMPANIES USING GO IN

PRODUCTION

Page 32: Scaling applications with go
Page 33: Scaling applications with go

Golang’s 3 hours online jumpstart course

http://tour.golang.org/welcome/1

Testimonials

https://sendgrid.com/blog/convince-company-go-golang/

http://www.scriptrock.com/blog/our-experience-with-golang

Further reading

http://golang.org/doc/

https://talks.golang.org/

http://thenewstack.io/a-closer-look-at-golang-from-an-architects-

perspective/

QUICK LINKS

Page 34: Scaling applications with go

THANKS