Web Application that
Scales
Ahmed Abd-ElHaffiez
Agenda
Sorry… No Agenda for this Session
SN
SN…Stands for Shared-Nothing
Measure of Success
• Scalability.
• Flexibility.
• Responsiveness.
Flexibility
Just forget about it….
Responsiveness
• Time taken to load a webpage on a
browser.
• Whatever it takes , we should
measure it, and improve it if it’s
necessary.
Firebug
Case Study
http://modernegypt.bibalex.org
Yslow
Interesting Plugin for firefox
1.Make Fewer HTTP
Requests
Minimize number of files
loaded/request
Combine CSS and JS files.
lightwindow.
prototype.js css
effects.js mainjs.js images.css maincss.css
scriptaculous.js home.css
1.continue
• Minimize the files size.
– Remove breaks and comments.
• Google AJAX Libraries
– Load Common libraries from google.
Google
prototype.js
Website application.js
2.CDN
Distribute the data over different servers.
Specially if the data is very heavy.
Take a look to Amazon Cloudfront,
Distributed S3 Storage.
3.Expires Headers
http header
Expires: Wednesday, 11 Mar 2009
10:00:00 GMT
Client Server
Apache Configuration:
<ifmodule mod_expires.c>
<filesmatch “\.(jpg|gif|png|css|
Image js)$”>
expires
ExpiresActive on
ExpiresDefault “access plus 2
days”
</filesmatch>
</ifmodule>
Server Side Optimizations
client http://fizo.com/posts
apache
Web server
20-50 requests/sec
(mongrel)
Server Side Optimizations
client http://fizo.com/posts
apache /public/posts
Web server (mongrel) 20-50 requests/sec
Server Side Optimizations
client http://fizo.com/posts
>1000 requests/sec
apache header
Box # 1
Box # 2
Web server (mongrel) 20-50 requests/sec
"There are only two hard things in
Computer Science: cache
invalidation and naming things."
— Phil Karlton
Memcached
A Hash in the memory
Memcached
Memcached
Application Application Application
instant instant instant
Client Side Caching
Client browser Server
get /users/fizo
Render body
Caches page Body with etag Create etag
get /users/fizo
Render body
etag Create etag
304 not modified Compare etag
Renders
cached page
Client Side Caching
Client browser Server
get /users/fizo
Render body
Caches page Body with last modfied
get /users/fizo
Compare last
Request header date
HTTP_IF_MODIFIED_SINCE
Renders 304 not modified
cached page
Advanced HTTP Caching
Reverse Proxy caches
Varnish...Squid
Proxy cache
fizo.com