Scaling a Web Service
-
Upload
leon-ho -
Category
Technology
-
view
1.963 -
download
0
description
Transcript of Scaling a Web Service
![Page 1: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/1.jpg)
Scaling a Web ServiceBarCamp HK 2007
Leon Ho, Stepcase Limited
![Page 2: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/2.jpg)
Objective
• Sustaining the scale of the traffic
• Zero downtime
• High performance
• Squeezing every juice from the server
![Page 3: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/3.jpg)
Why?
• Stepcase Lifehack (http://www.lifehack.org):
• 1 million visits per month
• 2 million pageviews per month
• Those does not include images, javascript, stylesheets
• We’ve done 5400 new connections per min
![Page 4: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/4.jpg)
1. Hardware
![Page 5: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/5.jpg)
Shared Hosting
Web Server DB
Stage 1
![Page 6: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/6.jpg)
Web Server DB
Stage 2
![Page 7: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/7.jpg)
Web ServerMaster
DB
SlaveDB
SlaveDB
Stage 3
![Page 8: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/8.jpg)
MySQL Cluster
Web Server
MasterDB
MasterDB
Stage 4
![Page 9: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/9.jpg)
MySQL Cluster
App ServerMaster
DB
MasterDB
App Server
App Server
Load Balancer
Stage 5
![Page 10: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/10.jpg)
Servers
• Stage 2
• Running 2 servers; each with 4 cores and 4GB RAM
• Exposing only one server to public network
![Page 11: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/11.jpg)
Remember the point is to stay in early stages.
![Page 12: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/12.jpg)
2. Reduce Connections
![Page 13: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/13.jpg)
Static Files
• Moves out to a separate server
• Consider Amazon S3
• Image - Decrease the number of images you need to load
• CSS Spites
• Use Firebug to benchmark
![Page 14: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/14.jpg)
Amazon S3
• We moved our static images to S3
• files.lifehack.org CNAME s3.amazonaws.com
• use cronjob and s3sync to keep them in sync
• next, move js, css, and post images out
![Page 15: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/15.jpg)
Feed
• 60,000 subscriptions daily
• We use external provider - Feedburner
![Page 16: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/16.jpg)
3. Reduce File Size
![Page 17: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/17.jpg)
Javascript
• Compress the javascript
• JSMin, Dojo ShrinkSafe, Packer, YUI Compressor
• http://compressorrater.thruhere.net
![Page 18: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/18.jpg)
4. Optimize and Cache
![Page 19: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/19.jpg)
Web & DB Server
• Web: Moved to Lighttpd
• DB: MySQL. Increase query cache, max connection and wait timeout
![Page 20: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/20.jpg)
Cache
• Cache, Cache, and Cache
• Page level (wp-cache)
• DB queries (memcache, or any object caches)
• PHP opcode - xcache, e-accelerator
![Page 21: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/21.jpg)
What else?
• Eliminate bottleneck
• Hard drive > Memory > CPU
• Reduce Abuse and Spam
![Page 22: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/22.jpg)
Next
• Adding more comprehensive monitoring
• Munin
• More scaling - this time - on Rails
![Page 23: Scaling a Web Service](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b7938b4a7959d7418b472a/html5/thumbnails/23.jpg)
Questions?
Visit Us: http://www.stepcase.comhttp://www.lifehack.org
P.S. We are hiring!
Contact Me:[email protected]