HTTP Cache Manager – Why I should use it and an example.
JMeter is not a browser, but JMeter provides config elements which helped to mimic the browser behavior and make your tests more realistic. “Cache manager” is used to simulate the browser caching behavior in Jmeter by adding caching functionality to HTTP requests within its scope.
In general, a browser caches files locally including any documents that make up a website, such as HTML files, CSS style sheets, JavaScript scripts, as well as graphic images and other multimedia content. When you revisit a website, the browser checks which content was updated in the meantime and only downloads updated files or what is not available in the cache. Bandwidth usage is reduced on both the user and server side and allows the page to load faster.
During load testing, we do not consider static resource files (like HTML, CSS, js, images, etc.) and JMeter does not download these static resources until it is explicitly configured to do so. HTTP Cache Manager must be included in your test plan if you have enabled your HTTP sampler to “Retrieve All Embedded Resources”.
HTTP Cache Manager will cache these downloaded resources and will not download again from the server until these are modified.
Cache manager properties
- Clear cache each iteration. As it says, each iteration the cached content is wiped.
- Use Cache-Control/Expires header when processing GET requests: If selected then Cache-Control/Expires value is checked against the current time. If the request is a GET request, and the timestamp is in the future, then the sampler returns immediately, without requesting the URL from the remote server.
- Max Number of elements in cache: By default value is set to 5000 which means cache manager will store 5000 items in the cache. You can increase this value but keep in mind that this will consume memory accordingly, and JMeter may throw “out of memory” exception. You may need to adjust your – Xmx value accordingly in JMeter .bat/.sh file or parameters in the RedLine13 load test.
For JMeter documentation, please refer to
http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Cache_Manager
Example Test Plan
Showing performance difference with and without HTTPCacheManager
Test plan includes two thread groups (one include cache manager and other does not). Each thread group is hitting the same URL, but you will see the difference in average response times and data transferred KB/Sec. Also, if you look into the View results tree listener, then you will notice “Response code: 304 and Response message: Not Modified” in Sampler results tab for resources which were using cache manager.