Session / cookie management in Apache JMeter

We have a simple performance test in the application.

  • We log in
  • Search by some criteria
  • repeats the search for various parameters.

We use Jmeter to test performance. We need to have multiple threads to test this in a scalable manner.

The way we currently have is:

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

Thus, we have a summary pivot table and a report at the plan level, while a cookie manager is present at the level of the stream group.

When I run for a single thread, it works fine and works fine. When I scale it to multiple threads, as soon as the next thread starts, the session for the last thread becomes invalid. This causes crashes for all already running threads due to a newly created thread.

I achieved this result with the observation:
1. If I run multiple threads, only the last thread has valid answers in the final result tree
2. If I start with 2 threads with a rise period of 10 seconds, which means that each thread takes time to finish itself, then both of them are successfully executed.

According to my understanding, each stream is registered in the application, and since the cookie manager is at the stream level, will the values ​​be maintained for the session identifier for each stream, respectively? But what causes the redefinition of the value of the session identifier between threads?

Any help would be greatly appreciated.

+45
java cookies session-cookies session jmeter
Sep 07 '09 at 13:35
source share
5 answers

Copied from jmeter documentation:

The last element is the HTTP Cookie Manager. A cookie manager must be added to all web tests - otherwise JMeter will ignore cookies. By adding this at the Thread group level, we make sure that all HTTP requests use the same cookies.

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

EDIT . I think you should use http://jmeter.apache.org/usermanual/component_reference.html#Simple_Controller to group your requests together with the cookie manager.

+45
Sep 07 '09 at 21:04
source share

I think that Andrey’s answer cannot help. He cites that each request will use the same cookies, but according to the jmeter manual:

Each JMeter stream has its own cookie storage area.

As far as I understand this question, you want each thread to share the same session id cookie. Therefore, it seems to me that you need to have two groups of threads and execute them sequentially. The first group of threads (with a single thread that runs only once) should log in and save the session cookie value in the global parameter (maybe you need to use the jmeter scripting features). Then set this cookie in the cookie manager of the second stream group.

Hope this helps.

+6
Nov 08 '11 at 16:17
source share

Try increasing the rise time. I came across the same question where the rise time was about 1 second, then I increased it to 3 seconds per stream, and it went fine.

+1
Jun 17 2018-11-11T00:
source share

Try the following:

Open the user properties available in the JMeter bin folder

Change it and add the following line:

 CookieManager.check.cookies=false 

Save it and run the script. I hope this solves your problem.

0
Dec 14 2018-11-12T00:
source share

First change your code to:

 jmeter.properties CookieManager.save.cookies=true CookieManager.name.prefix=mycookie_ 

Then add the HTTP cookie manager to the same stream group as your java sampler.

Then in your java sampler add:

 JMeterVariables jmv = JMeterContextService.getContext().getVariables(); Iterator<Map.Entry<String,Object>> it = jmv.getIterator(); while(it.hasNext()){ Map.Entry<String,Object> v = it.next(); System.out.println("name: " + v.getKey() + " value: " + v.getValue()); } 
0
Jun 25 '13 at 11:28
source share



All Articles