Scaling a Web Service
       BarCamp HK 2007
    Leon Ho, Stepcase Limited
Objective

• Sustaining the scale of the traffic
• Zero downtime
• High performance
• Squeezing every juice from the server
Why?
• Stepcase Lifehack (http://www.lifehack.org):
 • 1 million visits per month
 • 2 million pageviews per month
 • Thos...
1. Hardware
Stage 1

Web Server              DB


       Shared Hosting
Stage 2

Web Server   DB
Stage 3
                      Slave
                       DB
             Master
Web Server
              DB
            ...
Stage 4
                Master
                 DB

Web Server      Master
                 DB

             MySQL Cluster
Stage 5
           App Server
                           Master
                            DB
 Load
           App Server...
Servers

•   Stage 2

•   Running 2 servers;
    each with 4 cores
    and 4GB RAM

•   Exposing only one
    server to pu...
Remember the point is
to stay in early stages.
2. Reduce Connections
Static Files
• Moves out to a separate server
 • Consider Amazon S3
• Image - Decrease the number of images
  you need to ...
Amazon S3
• We moved our static images to S3
• files.lifehack.org CNAME
  s3.amazonaws.com
• use cronjob and s3sync to keep...
Feed


• 60,000 subscriptions daily
• We use external provider - Feedburner
3. Reduce File Size
Javascript

• Compress the javascript
 • JSMin, Dojo ShrinkSafe, Packer,YUI
    Compressor
• http://compressorrater.thruhe...
4. Optimize and Cache
Web & DB Server


• Web: Moved to Lighttpd
• DB: MySQL. Increase query cache, max
  connection and wait timeout
Cache

• Cache, Cache, and Cache
 • Page level (wp-cache)
 • DB queries (memcache, or any object
    caches)
 • PHP opcode...
What else?

• Eliminate bottleneck
• Hard drive > Memory > CPU
• Reduce Abuse and Spam
Next

• Adding more comprehensive monitoring
 • Munin
• More scaling - this time - on Rails
Questions?
                             Visit Us:
    Contact Me:
                    http://www.stepcase.com
leon@stepcas...
Upcoming SlideShare
Loading in …5
×

Scaling a Web Service

2,237 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,237
On SlideShare
0
From Embeds
0
Number of Embeds
80
Actions
Shares
0
Downloads
83
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Scaling a Web Service

  1. 1. Scaling a Web Service BarCamp HK 2007 Leon Ho, Stepcase Limited
  2. 2. Objective • Sustaining the scale of the traffic • Zero downtime • High performance • Squeezing every juice from the server
  3. 3. 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
  4. 4. 1. Hardware
  5. 5. Stage 1 Web Server DB Shared Hosting
  6. 6. Stage 2 Web Server DB
  7. 7. Stage 3 Slave DB Master Web Server DB Slave DB
  8. 8. Stage 4 Master DB Web Server Master DB MySQL Cluster
  9. 9. Stage 5 App Server Master DB Load App Server Balancer Master DB MySQL Cluster App Server
  10. 10. Servers • Stage 2 • Running 2 servers; each with 4 cores and 4GB RAM • Exposing only one server to public network
  11. 11. Remember the point is to stay in early stages.
  12. 12. 2. Reduce Connections
  13. 13. 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
  14. 14. 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
  15. 15. Feed • 60,000 subscriptions daily • We use external provider - Feedburner
  16. 16. 3. Reduce File Size
  17. 17. Javascript • Compress the javascript • JSMin, Dojo ShrinkSafe, Packer,YUI Compressor • http://compressorrater.thruhere.net
  18. 18. 4. Optimize and Cache
  19. 19. Web & DB Server • Web: Moved to Lighttpd • DB: MySQL. Increase query cache, max connection and wait timeout
  20. 20. Cache • Cache, Cache, and Cache • Page level (wp-cache) • DB queries (memcache, or any object caches) • PHP opcode - xcache, e-accelerator
  21. 21. What else? • Eliminate bottleneck • Hard drive > Memory > CPU • Reduce Abuse and Spam
  22. 22. Next • Adding more comprehensive monitoring • Munin • More scaling - this time - on Rails
  23. 23. Questions? Visit Us: Contact Me: http://www.stepcase.com leon@stepcase.com http://www.lifehack.org P.S. We are hiring!

×