Download - Scaling web-applications
Mihai Oaida
Senior Web Developer @ www.imobiliare.roStudent , Politehnica Timi oarașWeb technologies instructor
www.tehnologii-web.ro
Scaling Web Applications
Mihai Oaida <[email protected]> 00
We will talk about ...
FactsTheory + Myths ArchitectureStatic contentDynamic contentCaching
Scaling Web Applications
Mihai Oaida <[email protected]> 01
Web application facts
Mostly stateless Very read intensive ( > 90% )Not so dynamicCan be fine grained
Highly scalable, if designed to :)
Scaling Web Applications
Mihai Oaida <[email protected]> 02
Hardware facts
Limited context switchingLimited opened filesVery limited random IO Limited sequential IOLimited RAM
Scaling Web Applications
Mihai Oaida <[email protected]> 03
Scalability vs Performance
Scalability how many
Performancehow fast
Scalability + Performance how many and how fast
Scaling Web Applications
Mihai Oaida <[email protected]> 04
Vertical vs Horizontal
Vertical Scaling Bigger server2X capacity != 2x price
Horizontal ScalingMore identical servers 2X capacity ≈ 2x price
Scaling Web Applications
Mihai Oaida <[email protected]> 05
Benchmarking and Profiling
Benchmarking How fast a page loads, under certain
conditions
ProfilingIn a page execution, how much time each
component consumes
Scaling Web Applications
Mihai Oaida <[email protected]> 06
Benchmarking and Profiling
Benchmarking Page / site performance?Page / site scalability ?
ProfilingWhat is the bottleneck?
Scaling Web Applications
Mihai Oaida <[email protected]> 07
Benchmarking and Profiling
Prepare testsExpect resultsRun repeatable testsAnalyse dataInterpret data correctly !!!
Scaling Web Applications
Mihai Oaida <[email protected]> 08
Architecture
Web server – dynamic, static contentDatabase serverCaching server
+ load balancer+ network equipment
Scaling Web Applications
Mihai Oaida <[email protected]> 09
Static content - HTTP optimization
Use Expires and Last-Modified headersUse sprites for imagesMerge css filesMerge js filesUse compression – gzipUse multiple subdomains
img1.tehnologii-web.ro img2.tehnologii-web.ro
Scaling Web Applications
Mihai Oaida <[email protected]> 10
Static content - Server
Use dedicated server(s) just for staticUse asynchronous web servers
Lighthttpd, nginx
Or,Just use a CDN ( Content delivery network )
Scaling Web Applications
Mihai Oaida <[email protected]> 11
Dynamic content
Usually web servers are not the bottleneck
Code optimizationUse less RAM and less CPUgood performance!= good scalability
For PHPOpcode cache : xCache, apc, eAccelarator
Scaling Web Applications
Mihai Oaida <[email protected]> 12
Dynamic content
Dynamic = 0.x% static + 0.y% dynamic ?
Can real-time data have a 5 minute delay ?
Batch writesPre-cache
Scaling Web Applications
Mihai Oaida <[email protected]> 13
Database - general
Choose an open-source one that has proven to scale: MySQL :)
Use Master – Slave architectureWrite on master(s)Read from slaves
Scaling Web Applications
Mihai Oaida <[email protected]> 14
Database
Don't run on the default configuration
key_buffer, query cache, sort buffer, etc
All need tuning as data changes
Scaling Web Applications
Mihai Oaida <[email protected]> 15
Database
Use indexes – don't index everythingCreate very selective indexes, high cardinalityJoin tables very carefullyDenormalize
Scaling Web Applications
Mihai Oaida <[email protected]> 16
Database
Optimize queriesUse DESCRIBE commandActivate slow query log and monitor it!
Scaling Web Applications
Mihai Oaida <[email protected]> 17
Cache - Memcache
Asynchronous serverNo authenticationKey value databaseIn memoryVery scalableHas api in many languagesSmall limitations
Scaling Web Applications
Mihai Oaida <[email protected]> 18
Conclusions
There is no secret recipe, no easy solutionIt is very application specific
To scale you need not only the right tools but the right thinking!
Scaling Web Applications
Mihai Oaida <[email protected]> 19