Top Banner
Scaling a Web Service BarCamp HK 2007 Leon Ho, Stepcase Limited
23
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Scaling a Web Service

Scaling a Web ServiceBarCamp HK 2007

Leon Ho, Stepcase Limited

Page 2: Scaling a Web Service

Objective

• Sustaining the scale of the traffic

• Zero downtime

• High performance

• Squeezing every juice from the server

Page 3: Scaling a Web Service

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

1. Hardware

Page 5: Scaling a Web Service

Shared Hosting

Web Server DB

Stage 1

Page 6: Scaling a Web Service

Web Server DB

Stage 2

Page 7: Scaling a Web Service

Web ServerMaster

DB

SlaveDB

SlaveDB

Stage 3

Page 8: Scaling a Web Service

MySQL Cluster

Web Server

MasterDB

MasterDB

Stage 4

Page 9: Scaling a Web Service

MySQL Cluster

App ServerMaster

DB

MasterDB

App Server

App Server

Load Balancer

Stage 5

Page 10: Scaling a Web Service

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

Remember the point is to stay in early stages.

Page 12: Scaling a Web Service

2. Reduce Connections

Page 13: Scaling a Web Service

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

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

Feed

• 60,000 subscriptions daily

• We use external provider - Feedburner

Page 16: Scaling a Web Service

3. Reduce File Size

Page 17: Scaling a Web Service

Javascript

• Compress the javascript

• JSMin, Dojo ShrinkSafe, Packer, YUI Compressor

• http://compressorrater.thruhere.net

Page 18: Scaling a Web Service

4. Optimize and Cache

Page 19: Scaling a Web Service

Web & DB Server

• Web: Moved to Lighttpd

• DB: MySQL. Increase query cache, max connection and wait timeout

Page 20: Scaling a Web Service

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

What else?

• Eliminate bottleneck

• Hard drive > Memory > CPU

• Reduce Abuse and Spam

Page 22: Scaling a Web Service

Next

• Adding more comprehensive monitoring

• Munin

• More scaling - this time - on Rails

Page 23: Scaling a Web Service

Questions?

Visit Us: http://www.stepcase.comhttp://www.lifehack.org

P.S. We are hiring!

Contact Me:[email protected]