RedDotRubyConf 2016
@arnvald, RedDotRubyConf 2016YOUR API IS TOO SLOW!
View Slide
@arnvald, RedDotRubyConf 2016YOUR API IS TOO SLOW!2TQDCDN[HCUVGPQWIJ
Grzegorz Witek
is speed a feature?
is lack of speed a bug?
AlgoliaGithub
Web application optimizationloading prioritystatic contentdynamic contentdomain sharingJavaScriptcompressionasset minifying CSSHTMLun-CSSprefetchingHTTP/2 image spritesCDNdatabase optimizationmulti-threading
Web API optimizationloading prioritystatic contentdynamic contentdomain sharingJavaScriptcompressionasset minifying CSSHTMLun-CSSprefetchingHTTP/2 image spritesCDNdatabase optimizationmulti-threading
Long way of a request! " #
Latency! " #
Where are your users?"
Where are your users?"Singapore Jakarta13ms
Where are your users?"Singapore Hanoi100ms
Where are your users?"Singapore New York265ms
Where are your users?"Singapore Shanghai320ms
Dynamic content acceleration! CDN#
Latency
Latency
Processing#
Don’t be a smart-ass“Oh, I know, we have to cache it!”
Measuregem 'ruby-prof' gem 'rack-mini-profiler'
Measurein production modepre-production stage
Measuregem 'newrelic' gem 'skylight'
Measureprofile - focus on the slowest part
Measurebenchmark - compare alternative solutions
Improve
ImproveRely on your database
ImproveWhere is your cache?
ImproveRedis on a separate machine - fastRedis on the same machine - fasterApplication memory - the fastest
ImproveMulti-layered cache (Russian doll caching)
ImproveWhen needed - mutate
ImproveUpgrade your libraries
ImproveWhen needed - replace your libraries
Improvegem 'json' gem 'oj'gem 'oj-mimic-json'
ImproveNative extensions - not only C!
Improvehttps://github.com/rustbridge/helixhttps://github.com/d-unseductable/ruru
ImproveMove processing to the background
ImproveWhen desperate - extract part of the application
ImproveI said "when desperate" not "ASAP NOW!!!11"
ImproveI said "part", not "rewrite everything in Go"
ImproveThere's more, way more
Download! " #
ImproveNot only GZIP
Speed up your APIuse CDN infrastructureprofile and benchmarkfocus on the slowest partrewriting is the last thing to consider
Speed up your APIRuby is fast enoughSinatra is fast enoughRails is fast enough