wonders of golang

31
Wonders of Golang

Upload: kartik-sura

Post on 10-Jan-2017

451 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Wonders of Golang

Wonders of Golang

Page 2: Wonders of Golang

Pain points of Systems Software

Change in computing landscape

Scale of development

Developer productivity

Dependency management

Page 3: Wonders of Golang
Page 4: Wonders of Golang
Page 5: Wonders of Golang

Enter Go

A new language, a concurrent, garbage-collected language with fast

compilation.

Page 6: Wonders of Golang

Syntax and SemanticsSimilar to C• compiled• Statically typed• Procedural with pointers

Small changes to C semantics• No Pointer arithmetic• No implicit numeric conversions• Array bounds are always checked

Big changes• Linguistic support for Concurrency• Garbage collection• Interface, reflection, type switches, etc.

Page 7: Wonders of Golang

Packages

• Modularity and reusability• Componentize software• Import clause– import “fmt”

• Package name is used to qualify items– Name vs. pkg.Name

• Remote packages– import "github.com/garyburd/redigo"

Page 8: Wonders of Golang

Defining visibility using Naming

• Name of the identifier itself carries the visibility– Upper case initial letter: Public/ exported/ visible to

other packages– Lower case initial letter: Private to the package

Page 9: Wonders of Golang

Concurrency

• Do not communicate by sharing memory; instead, share memory by communicating.

Page 10: Wonders of Golang

Goroutine

• Function executing concurrently with others in same address space

• Lightweight• Multiplexed into multiple OS threads• Go keyword

Page 11: Wonders of Golang

Channels

• way for two goroutines to communicate with one another and synchronize their execution

• By default, sends and receives block until the other side is ready.

• Combine communication and synchronization• Buffered channels

Page 12: Wonders of Golang

Channelhttp://www.goinggo.net/2014/02/the-nature-of-channels-in-go.html

Page 13: Wonders of Golang

Buffered channel

Page 14: Wonders of Golang

Channel Idioms

• A channel can allow the launching goroutine to wait for the sort to complete.

Page 15: Wonders of Golang

Server throughput

Page 16: Wonders of Golang

Request serving architectures

Page 17: Wonders of Golang

Cost of scheduling OS threads

• POSIX Threads: Signal mask, CPU affinity, cgroups• Store all the CPU registers• Cost of context switch Vs amount of work

Page 18: Wonders of Golang

Goroutine scheduling

• Switched happen only at predefined times– If channel operations are blocking– Go statement– Blocking syscalls like file and network IO– Garbage collection

• Compiler knows which registers are used

Page 19: Wonders of Golang

Stack management

POSIX threads• Large amount of

memory pre-reserved• Amount of available

memory reduces with increase in threads

Goroutine• Starts with 2k

• A check before a function call

• Shrinks with GC

Page 20: Wonders of Golang

OOP

Page 21: Wonders of Golang

Struct

Page 22: Wonders of Golang

Embedding

Page 23: Wonders of Golang

Multiple embedding

Page 24: Wonders of Golang

A golang-Interface is a class, with NO fields, and ALL VIRTUAL methodsWhen you call a method on the var/parameter, a concrete method is called via method dispatch from a jmp-table.

Interface

Page 25: Wonders of Golang

Standard library

• Exp package for experimental new packages• Archive and compresion: read .tar and .zip• Bytes and String• Collections: heap, lists• File, OS• Maths• Networking: UNIX domain and network

sockets, TCP/IP, and UDP

Page 26: Wonders of Golang
Page 27: Wonders of Golang

Tools

• Gofmt: single style for readability and scalability

• Golint: checks style violations• GoVet: finding common mistakes• Inbuilt performance profiler

Page 28: Wonders of Golang
Page 29: Wonders of Golang

Golang @ PubMatic

• Low latency high throughput• Large number of network IO to external

partners• Billions of requests per day• Multiple go services live• Third party components such as redis,

Aerospike, MySQL, GeoIP

Page 30: Wonders of Golang

We are hiring!http://www.pubmatic.com/careers.php

Page 31: Wonders of Golang

GOPHERCON

• The Go Conference in India• 19 - 20 February 2016• Vivanta by Taj, MG Road, Bengaluru • http://www.gophercon.in/• Ticket is Rs 3999 (last 60 tickets remaining)• Discount code D1000 for Rs 1000 off!• https://www.townscript.com/e/gci16