traitement temps réel chez streamroot - golang paris juin 2016

33
REALTIME AT STREAMROOT

Upload: simon-caplette

Post on 09-Jan-2017

357 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

REALTIME

AT

STREAMROOT

Page 2: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Simon Caplette

I am a Backend Scalability Engineer

at

streamroot.io

Page 3: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

What Streamroot does ?

o Provide drop in/transparent P2P functionalities for large video broadcasters (vod, live)

o Allow broadcasters to save up to 70% bandwidth, handle huge ramp up/spikes for live events

Page 4: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Ingredients used to build the platform

Love & compassionTest Driven DevelopmentPragmatism (YAGNI !!!)

Ship when you are green (CD, CR)Beck's Simple design rules

Page 5: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Passes the tests

Reveals intention

No duplication

Fewest elements- Kent Beck, 1990

Page 6: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

REALTIME

CONCURRENT

LOW LATENCY

RESPONSIVE

Page 7: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

SCALABILITY != PERFORMANCE

SCALABILITY ~ CONCURRENCY

(Thinking more in process distribution rather than CPU perf)

… so Go was good candidate from the start

Page 8: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

INPUT

SYSTEM

BUSINESS & OPERATIONAL OUTPUT

Processing time ~ Real life events

Page 9: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Realtime components at Streamroot

o Tracker: matching viewers for p2po Signaling server: initial exchange of

clients metadata before direct communication

o Autoscaler & traffic reportero Data pipeline for realtime display

Page 10: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Go signaling servero Relayer: very easy logico Persistent connections (web sockets)o Locking + map registryo Unit holds 150k with no load balancer

(HAProxy), 35,000 msg/secondso Spike in Elixir/Erlang: 200k

Page 11: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Go Trackero A tracker remembers and match viewers

amongst themselveso Responsiveness: in memory vs.

interprocesso Go has few data structures (usually

composition of map primitive)o Tracking and handling concurrent accesso Locking (W, RW), snapshot isolationo Optimistic control, channels

Page 12: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Our Autoscaler (and realtime reporter)

o One Go process is very good at doing different things simultaneously (a cron that exposes JSON on HTTP)

o Autoscaler: watch overall load; control cloud instances; report/store historically on action/data

o What I called Octopus pattern (built in concurrency, solid timers/tickers, http cancellation)

o Go is terse! Module has 619 Lines of code (include both Azure, AWS controls)

o Stable: been running for months without any quirkso (Demo image)

Page 13: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

REALTIMEDATA

PIPELINE

Page 14: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Non functional requirements

DISPLAY REALTIME MULTIPLE GRAPHS & AGGREGATES

…ALL UNDER A SECOND

Page 15: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

KAFKA CLUSTER

CONSUMER 2CONSUMER 1

TIME SERIE STORAGE

COLLECTOR COLLECTOR COLLECTOR

Page 16: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Low latency

o Realtime pipeline's components have all high write throughput (fast writes)

o Kafka: contiguous write, retention, …, no ack if needed

o Time series DB ( InfluxDB in Go): line protocol, batches, write ahead log, UDP client if really needed, ...

o … Collectors (HTTP end points)

Page 17: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Collectorso Simple Go http endpoints that received,

validate and push JSON text to the pipeline

o Out of the box Go stdlib endpoint holds 10,000 to 20,000 request per seconds (C10k problem solved ;) )

Page 18: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Collectors - Fail fasto If you bail out as soon as you're back on

your feet for otherso Go system language: great io, http

packageso io.LimitedReader, http.MaxBytesReader

Page 19: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Collectors – Payload sizeo For uncompressed JSON, payload size

matterso Go un/marshal is based on reflection.

Larger payloads suffero github.com/pquerna/ffjson on 1.5MB

payloads did not helpo Avoid switching on payload type. A url

path for a type when neededo Do not nest JSON until necessary.

Friendlier down the pipeline

Page 20: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Collectors – Reuse resourceso Great Go package synco sync.Pool (reminder of the Flyweight

pattern)o exampleo … have not tried/measured it yet.

YAGNI ;)

Page 21: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Collectors - Benchingo https://github.com/tsenart/vegetao Great first results even from your local

computero Easily push your bench command line

binary on any cloud machine with more cores

Page 22: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Data permanent storageInfluxDB

o Flexible and powerful time series DB … approaching version 1.0 ;)

o Allow fast query with useful functions (max, percentile, median, derivative, …)

o … less density in points leads to faster query overall

Page 23: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

KAFKA CLUSTER

CONSUMER 2CONSUMER 1

TIME SERIE STORAGE

COLLECTOR COLLECTOR COLLECTOR

Page 24: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Go consumerso https://github.com/Shopify/saramao Lots of redundancy in incoming data

(JSON payloads) that can be reduce per broadcaster, per content, etc...

o Consumers:a. pulls JSON payloads from Kafkab. apply logic (reduce, discard)c. push to backend storage or anything

(live geo map, etc...)

Page 25: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Go consumers (2)o Consumer's main logic pattern is our

replay aggregatoro Aggregator:

a. consume live payloadsb. wait for configured timec. flushd. repeat

o Design allow anytime restart; supports failure; can stop service for long period if needed

Page 26: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

DASHBOARD DEMO SCREENS

Page 27: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

MISCELLANEOUS

Page 28: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

YAGNI deploymento Disclaimer: I am not a sysadmin although

I enjoy ito Any Cloud → Ubuntu → Systemdo Use conventions for your binary

deploymento Capture your conventions with Ansibleo Easy rollback / respawn

Page 29: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

YAGNI deployment (2)

$PROJECT_NAME-`git rev-parse --short HEAD`-`date +%Y-%m-%d`

# example: collector-073b570-2016-05-27

GOARCH=amd64 GOOS=linux go build -o pkg/$ARTIFACT_NAME

scp pkg/$ARTIFACT_NAME $HOST_ALIAS:~/goapps/$PROJECT_NAME/

ln -fs $ARTIFACT_NAME $PROJECT_NAME

sudo service restart $PROJECT_NAME

Page 30: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

YAGNI deployment (3)

[Unit]Description=Payload collectorAfter=network.target

[Service]LimitNOFILE=1000000Environment=KAFKA_BROKERS=x.x.x.x:9092,x.x.x.x:9092,x.x.x.x:9092SyslogIdentifier=streamroot-traff-collectorExecStart="/home/streamroot/goapps/collector/collector"Restart=always

[Install]WantedBy=multi-user.target

Neutral binary. Injection from environment

Page 31: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Dependencies surface$ REPO=github.com/streamroot;$ for PROJECT in `ls $GOPATH/src/$REPO`;$ do go list -f '{{ join .Deps "\n" }}' $REPO/$PROJECT | grep -v $REPO | grep '\.' | grep -v 'internal' | sort | uniq; done

github.com/Azure/azure-sdk-for-gogithub.com/influxdata/influxdbgithub.com/dgrijalva/jwt-gogithub.com/gorilla/contextgithub.com/gorilla/websocketgolang.org/x/time/rategopkg.in/mgo.v2github.com/Shopify/saramagithub.com/rcrowley/go-metricsgithub.com/jeromer/syslogparser

Page 32: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Great place to work.You are responsible for your shit!

http://www.streamroot.io/[email protected]

(with Subject: Golang meetup)Core JS developer

Backend Scalability Engineer

Our developer's bloghttps://indevwith.streamroot.io/

Page 33: Traitement temps réel chez Streamroot - Golang Paris Juin 2016

Thank you!

Any questions?

(I am available for new projects)