Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter HTTP Request Post Body from File

I am trying to send an HTTP request via JMeter. I have created a thread group with a loop count of 25. I have a ramp up period of 120 and number of threads set to 30. Within the thread group, I have 20 HTTP Requests. I am a little confused as to how JMeter runs these requests. Do each of the 20 requests within a thread group run in a single thread, and each loop over a thread group runs concurrently on a different thread? Or do each of the 20 requests run in different threads as and when they are available.

My other question is, Over each loop, I want to vary the body of the post data that is being sent via the HTTP request. Is it possible to pass the post data body via a file instead of inserting the data into the JMeter Body Data Tab as show below:

enter image description here

However, instead of doing that, I want to define some kind of variable that picks a file based on iteration of the threadgroup that is running, for example, if it is looping over the thread group the second time, i want to call test2.txt, if the third time test3.txt etc and these text files will contain different post data. Could anyone tell me if this is possible with JMeter please and if so, how would I go about doing this.

like image 201
kushaldsouza Avatar asked Dec 25 '22 07:12

kushaldsouza


1 Answers

Point 1 - JMeter concurrency

JMeter starts with 1 thread and spawns more threads as per ramp-up set. In your case (30 threads and 120 seconds ramp-up) another thread is being added each 4 seconds. Each thread executes 20 requests and if there is another loop - starts over, if there is no loop - the threads shuts down. To control load and concurrency JMeter provides 2 options:

  1. Synchronizing Timer - pause all threads till specified threshold is reached and then release all of them at the same time
  2. Constant Throughput Timer - to specify the load in requests per minute.

Point 2 - Send file instead of text

You can replace your request body with __fileToString function. If you want to parametrize it you can use nested function to provide current iteration - see below.

Point 3 - adding iteration as a parameter

JMeter provides 2 options on how you can increment a counter each loop

  1. Counter config element - starts from specified value and gets incremented by specified value each time it's called.
  2. __counter function - start from 1 and gets incremented by 1 each time it's being called. Can be "per-user" or "global"

See How to Use JMeter Functions post series for comprehensive information on above and more JMeter functions.

like image 181
Dmitri T Avatar answered Dec 28 '22 07:12

Dmitri T