Friday, February 25, 2011

Searching for a Git Client for your windows machine?

Have you moved to GIT ?

Are you searching for a free GIT client for your windows machine?

If you are like me who use SVN,CVS for version control for various projects and were comfortable with using the respective clients in windows and are searching for the same for GIT then say hi to "TortoiseGit "

With a few steps you can install it and it sweetly integrates with windows. Screen shots below

Try it out !!

Till next time...

Wednesday, February 23, 2011

My take on “Optimizing HTTP Caching” for your web application.

One quick way to a snappy and fast loading web page is to add appropriate HTTP headers to your response to ensure that resources are cached, by a browser or proxy. Browsers or proxies can refer to the locally cached copy instead of having to download it again on subsequent visits to the web page.

Let’s quickly dive into the various headers you’ll need to set with the optimal values. The values will defer from app to app depending on how long you may want the browsers or proxies to cache the content.

Expires  or max-age ? What do you use ?

  • Expires
    • The Expires HTTP header was the basic means of controlling caches back in the good old days of HTTP 1.0. It tells all caches how long the data in its local storage is fresh for. After that time, caches will always check back with the origin server to see if a document is changed. Expires headers are supported by practically every cache.
    • Expires header was very useful ,but it had some limitations .One being ,since there’s a date involved, the clocks on the Web server and the cache must be synchronized.
    • Example : "Expires: Sat, 01 Jan 2000 00:00:00 GMT"
  • max-age=[seconds]
    • Introduced in the HTTP 1.1 spec, this is a replacement for Expires but the advantage here is that this directive is relative to the time of the request, rather than an absolute date.
Expires or Cache-Control max-age when set ensures that no request is ever sent out from the browser and the file will be picked up from the local cache (provided other Cache control headers like no-cache ,no-store, must-revalidate, proxy-revalidate are not set) .

What if we cannot predict the lifetime of the page content and want the browser to check with the server on a regular basis if the cached copy is still FRESH. ??

Don’t worry we can do this to with headers like Last-Modified and Etag.
  • Last-Modified
    • This indicates the date and time at which the origin server believes the file was last modified
    • This is a "weak" caching header on which the browser applies a heuristic to determine whether to fetch the item from cache or not. (The heuristics are different among different browsers.)
  • ETag
    • This can be any value that uniquely identifies a resource (file versions or content hashes are typical)
So why do we need to set this?
  • These headers allow the browser to efficiently update its cached resources by issuing conditional GET requests when the user explicitly reloads the page.
  • If the resource has not changed the browser will NOT reply back with the entire file content in the response but just with a header  “304 Not Modified“ indicating to the browser that it can serve the file from its cache since its still fresh.
  • If you rely on ETags ,you may face a problem if you have multiple servers behind a load balancer (configured in a non-sticky environment) since the ETag generation may result in a different key.

What are some other Cache control headers that I can set ??
  • public or private
    • Setting the Cache-Control header to private disables proxy caching altogether for these resources. 
    • If your application relies less on proxy caches for user locality, this might be an appropriate setting.
  • must-revalidate
    • This directive specifies that the cache MUST revalidate with the server that the content is still fresh before serving the file from local cache.

How can I speed up my web application ??
  • Specify one of the two headers Expires or Cache-Control max-age for all cacheable resources. 
  • Specify one of two headers Last-Modified or ETag for all cacheable resources.
  • Set values appropriate to your web application
  • Use a tool like YSlow or Google’s Page Speed to check the end result.

Till next time …

Tuesday, February 15, 2011

Benchmarking Tomcat 6.0.32 and Resin 3.1.3 Pro

So we are in the process of migration from Resin 3.1.3 Pro to Tomcat 6.0.32. So the questions haunting my mind were “What if Resin is actually better than Tomcat”? Will Tomcat handle load? Will it serve static content faster than Resin? . To answer all these questions I configured JMeter and ran a quick test.

What did the test consist of ?
Made a call to the login page of my application which included (6 static calls,1 call to a jsp and 2 to servlets).Configured Jmeter to create 350 concurrent clients. Hence each client made the 9 calls which resulted in a total of 3150 Requests in all.

What was the Raw Result?
While performing the test even though the network traffic on my laptop got real slow, I tried accessing the page served by both resin and tomcat from another pc and it was very responsive. Also monitored the CPU & memory usage on the server and didn't notice any spikes .Tomcat hardly used 350 MB of memory during the load. Check the screen shots below.

What’s my conclusion?
The results are very very close .Resin's throughput (49.9 requests/min) was a bit higher than that of Tomcat (47.7 requests/min). I am assuming it’s because most of the files were static .One could further tweak Tomcat's thread creation to handle more requests and may also think of running apache over tomcat (tried setting it up and its quite simple to configure).But in short if your replacing Resin with Tomcat ,I am sure Tomcat would perform just as well as Resin.

Till next time...

Monday, February 14, 2011

How the hell did that value come in the cookie ??? I swear I never set it !!!!

Cookies have two version i.e Version 0 and Version 1. Version 0 adheres to the original Netscape spec while Version 1 adheres to RFC 2109.According to specs, in Version 0, cookie values "SHOULD NOT" contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons, and semicolons. Version 1 cookies on the other hand allow such values but the entire value will be quoted. Eg: "testing:value".

Version 1 cookies are not fully supported by all user agents. By default (if not explicitly specified)cookies are created using Version 0 to ensure the best interoperability. One can explicitly set the version of the cookie by specifying Version="0/1"

I carried out some tests using IE 8, Firefox 3.6, Chrome 9 and JMeter as user-agents and Tomcat 6.0.32 as the application server. The test simply created a cookie storing a url as a value i.e URL= Tomcat docs mention that if a value contains illegal characters it would set the version of the cookie to 1 and quote the value. Using fiddler to check the raw request /responses, I confirmed it did just that. When the first request goes out ,it went without a cookie and when the response came back it returned with the cookie set with version 1 (the value was quoted). Now the user-agents especially JMeter and on occasions the browsers mentioned above ,when sending the next request ,it sent the cookie but with a version set to 0.Tomcat on receiving the request ,then treated the version of cookie as 0 and truncated everything after : (colon). Hence when the value of the cookie was read it gave just http instead of

Next time you are using cookies keep these points in mind or you might just go crazy thinking "How the hell did that value come in the cookie ???". Or a better option would be to URL or Base 64 encode/decode values in cases where the value contains special characters.

Till next time ...