0-60 with Goliathbuilding high-performance (Ruby) web servicesIlya Grigorik@igrigorik
conn =EM::HttpRequest.new('http://gogaruco.com')r1 =conn.get :path => "speakers.html", :keepalive => true# 250 msr2 =conn.get :path => "schedule.html"# 300 ms# wait until done …Answer:All of the above!Total execution time is:250 ms300 ms550 ms~ 65% truthiness~ 25% truthiness *~ 10% truthiness **HTTP Quizthis is not a trick question…
“SPDY? We can’t even get HTTP right…”the why, how, and how-to of Goliath
ServerClient20 msTCP handshakeHTTP Requestheaders, body40 msprocessingMulti-part body (*)Terminate connectionHTTP 1.0RFC 1945 (1996)+ 40ms TCP setup (network)+ 20ms request (network) + 40ms processing + 20ms response (network)66% of time in network overhead
Benchmark client RTT, not just the server processing timeA public service announcement…
Keep-aliveRe-use open connection
No multiplexing, serial
Default to “on”PipeliningNo multiplexing
Parallel requestsHTTP 1.1RFC 2616 (1999)
+ 40ms TCP setup (network)+ 20ms request (network) + 40ms processing + 20ms response (network) x 40ms TCP setup (network)+ 20ms request (network) + 40ms processing + 20ms response (network) 200ms for two requestsSmall win over HTTP 1.0Keep-aliveRFC 2616 (1999)* One gotcha…
Net:HTTPKeep-aliveRFC 2616 (1999)Connection: close  < ugh!
+ 40ms TCP setup (network)+ 20ms request (network) + 40ms processing + 20ms response (network) 60% of time in network overhead120ms for two requests – 50% improvement!PipeliningRFC 2616 (1999)
Connection setup: 50msRequest 1: 300msRequest 2: 250msTotal time: ~250 ms~300 ms~350 ms~600 msPipelining Quiz RFC 2616 (1999)
There is just one small gotcha… Making HTTP Pipelining Usable on the Open Webhttp://tools.ietf.org/html/draft-nottingham-http-pipeline-01
conn =EM::HttpRequest.new('http://gogaruco.com')r1 =conn.get :path => "speakers.html", :keepalive => true# 250 msr2 =conn.get :path => "schedule.html"# 300 msTotal execution time is:250 ms300 ms550 msKeep-alive what? HTTP 1.0!~ 65% truthiness~ 25% truthiness *~ 10% truthiness **Good: Keep-alive + PipeliningBad: Keep-alive + Garbage“I’m confused”HTTP in the wildit’s a sad state of affairsKeep-alive: mostly works – yay!Pipelining:  disabled (except in Opera)
HTTP can be a high-performance transportGoliath is our attempt to make it work
Goliath == v3 API stack
Open source in 2011
Growing community
“Social Analytics”
Rails frontend
Ruby backend
95%+ of traffic via API’s++Brief HistoryGoliath @ PostRank
Rails…HTTP APIHTTP APIHTTP APIHTTP APISQLSQLSQL…SQLSQLSolrSQLSeparate logical & physical services
Easy to tune, easy to maintain, easy to “scale”
Stable code, fault-tolerancePROHigher upfront ops cost
Lots of cross-service communicationCON
www.goliath.ioSingle responsibility web-services
AsyncHTTP response streaming + progressive notifications
AsyncHTTP request streaming + progressive notifications

0-60 with Goliath: Building High Performance Ruby Web-Services