Search code examples
cachingjmeterakamaicachemanager

Akamai and Jmeter cache manager


I have been running on Jmeter from past few weeks. There is no end-to-end use case in my Jmeter tests (e.g. login >> go to profile page >> logout). I am simply hitting few important pages of my application directly. e.g. Registration page, Home Page, About Us etc.

How these pages are served:

Scenario 1: User >> Akamai >> Server >> Akamai >> User

Scenario 2: User >> Akamai >> User (i.e. after all pages cached in Akamai)

There are 99% chances that when I run Jmeter tests, they are getting served from Akamai i.e. Scenario 2.

Questions:

  1. Do I need HTTP Cache manager for Scenario 2? I mean Why do I need pages cached twice once at Akamai and same time on my machine's RAM?
  2. Only if answer to #1 is Yes: Is this mandatory/optimum to use cache manager with cookie manager?
  3. Only if answer to #1 is Yes: My scripts are written as: Test Plan >> Thread group >> Throughput Controller >> 80+ HTTP Request Sampler (actually pages). So do I need HTTP cache manager at throughput controller level or at inside each HTTP Request Sampler? enter image description here

Solution

  • From your question, I understand that Akamai is a CDN where static pages are served.

    Keeping this in mind, my answer is as follows:

    1. Do I need HTTP Cache manager for Scenario 2? I mean Why do I need pages cached twice once at Akamai and same time on my machine's RAM?

    Yes Or No. Depends on the configuration you want to achieve. You must understand the difference b/w pages served by Akamai (CDN cache) is different from the pages stored locally on the user's machine.

    Local cache - fastest way of retrieving the page. (achived by Cach-Control: max-age directive). If specified, there is NO need to even hit the Akamai server. Browser fetches the page from local cache itself. If max-age is expired, then browser sends a revalidate request to check whether it has the latest copy. CDN/Server validates it and if the copy is latest, then sends 304 (not modfied). otherwise, the latest copy of the page served with new max-age (max-age is send only if implemented).

    So, the point is how the server is configured to deal with Cache. If local cache is implemented using Expires/Cache-Control, then you must add HTTP Cache Manager to the Test Plan.

    2. Only if answer to #1 is Yes: Is this mandatory/optimum to use cache manager with cookie manager? Normally, Cache is independent of the user. Cookie manager is to make the user genuine by sending Cookies. Cache Manager to reduce the network latency (round trips) while loading the page. If cache mechanism implementation varies for logged in Vs anonymous users, then you must consider both the cases. Otherwise, Cookie manager is not required.

    3. Only if answer to #1 is Yes: My scripts are written as: Test Plan >> Thread group >> Throughput Controller >> 80+ HTTP Request Sampler (actually pages). So do I need HTTP cache manager at throughput controller level or at inside each HTTP Request Sampler?

    Generally, you add the HTTP Cache Manager at the top of the hierarchy (under Test Plan or Thread Group), so it will be applicable to all the Samplers (children).

    Note: I strongly suggest to understand the application behaviour at HTTP level (in which JMeter works) using Browser -> F12 -> Network tab. This gives each and every HTTP request sent to load the browser, and resposne is retrieved from local cache or CDN or the server etc.

    Please go through the following headers to completely understand the behaviour:

    1. Cache-Control header (max-age directive)
    2. ETag header
    3. Last-Modified header
    4. Expires

    Following are the references to start with:

    1. http://dev.mobify.com/blog/beginners-guide-to-http-cache-headers/
    2. https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching
    3. https://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html