19 October 2012

Cloud Tip: How to scale website for 1 million + hits

Yesterday I was working on solutions to scale up our App Server (JBoss) to a maximum of 1 million  + hits (per day) by utilizing minimal resources. I came up with a solution something like:

serversetup

The minimal architecture becomes some thing like this


Varnish will cache all the request in memory. so what about the statefull requests.




I came up with a VCL script with this architecture:


VCL Script used (its a sample one, production one having ACL and other throttling features):

backend default {
    .host = "localhost";  # Varnish is running on same server as Apache
    .port = "8080";
}

sub vcl_recv {
  # remove unnecessary cookies
  if (req.http.cookie ~ "JSESSIONID") {
    return (pass);
  } else {
    unset req.http.cookie;
  }
}

sub vcl_fetch {
  if (req.http.cookie ~ "JSESSIONID" || req.request == "POST") {
    return (deliver);
  } else {
    # remove all other cookies and prevent backend from setting any
    unset beresp.http.set-cookie;
    set beresp.ttl = 600s;
  }
}

sub vcl_deliver {
  # send some handy statistics back, useful for checking cache
  if (obj.hits > 0) {
    set resp.http.X-Cache-Action = "HIT";
    set resp.http.X-Cache-Hits = obj.hits;
  } else {
    set resp.http.X-Cache-Action = "MISS";
  }
}

Dont forgot to benchmark with YSLOW or Apache Benchmark tool.  :D

The real speed depands upon how much memory you are allocating for Varnish... its upto you!

You can customize this for you requirement. Take wordpress VCL template as base reference.

Reference Materials:









Varnish Internals

No comments:

Post a Comment