Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session/cookie management in Apache JMeter

We have a simple performance test flow in an application.

  1. We login
  2. Search based on some criteria
  3. repeat searches for different parameters.

We are using Jmeter to do a performance testing. We need to have multiple threads running to test this in a scalable manner.

The way we currently have this arranged is:

-Test Plan   - Thread Group       - Cookie Manager       - Login To application       - Search on param 1       - Search on param 2   - results summary table   - Summary report 

So basically we have summary return table and report present on plan level while cookie manager is present on thread group level.

When I run for one thread it runs fine and completes well. When I scale it to multiple threads, as soon as the next thread kicks off, the session for the last thread is invalidated. This causes failures for all the already running threads due to newly spawned thread.

I reached this result with observation:
1. If I run multiple threads, only last thread has got valid responses in result summary tree
2. If I run with 2 threads with ramp up period as 10 seconds, which means each thread gets time to finish itself, then both of them run successfully.

As per my understanding each thread login's into application and since cookie manager is at thread level, the values will be maintained for session id for each thread respectively? But what is causing the override of the session id value between threads?

Any help will be much appreciated.

like image 854
Priyank Avatar asked Sep 07 '09 13:09

Priyank


People also ask

What is cookie manager in JMeter?

The cookie manager stores and sends cookies just like a web browser. If you have an HTTP Request and the response contains a cookie, the Cookie Manager automatically stores that cookie and will use it for all future requests to that particular web site. Each JMeter thread has its own "cookie storage area".

How do I save cookies in JMeter?

Saving cookies value to Jmeter variable:Change the property CookieManager. save. cookies=true in jmeter properties file.


2 Answers

Copied from jmeter documentation:

The last element is a HTTP Cookie Manager . A Cookie Manager should be added to all web tests - otherwise JMeter will ignore cookies. By adding it at the Thread Group level, we ensure that all HTTP requests will share the same cookies.

From chapter "4.2.2 Logic Controllers" in http://jmeter.apache.org/usermanual/test_plan.html.

EDIT: I guess you should use http://jmeter.apache.org/usermanual/component_reference.html#Simple_Controller to group your requests together with Cookie Manager.

like image 178
Andrey Adamovich Avatar answered Sep 24 '22 18:09

Andrey Adamovich


I think that Andrey's answer cannot help. He quotes that each request will use the same cookies BUT according to jmeter manual:

Each JMeter thread has its own "cookie storage area".

As far as I understand the question, you want each thread to share the same session ID cookie. So it seems to me you need to have two thread groups and execute them consecutively. First thread group (with a single thread that executes once only) should login and save the session cookie value to a global parameter (perhaps you need to use jmeter's scripting capabilities). Then set that cookie in the cookie manager of the second thread group.

Hope that helps.

like image 32
akostadinov Avatar answered Sep 23 '22 18:09

akostadinov