jmeterperformance-testing

JMETER- Why does my JMeter test only execute 10-12 requests per second instead of the configured 40 requests per second?


I'm currently running a JMeter load test on my laptop and I'm encountering an issue where my test plan is not achieving the expected throughput. Here are the details of my test configuration:

Test Plan
—Thread Group ( number of threads =40,rampup =20, loop count =250)
     —— Directory Listing Data source(listed our source directory and unchecked all the checkboxes)
     —— Post API HTTP Request with body as ${fileContent}
                                                  
           —— Post API Header Manager with one of the headers as Authorization and hardcoded the token as Bearer <token>
           —— JSR223 PreProcessor to read data from directory listing data source
     —— Constant throuput Timer with target throughput as 2400 and calculate throughput based on all active threads in current thread group

I have a folder on my desktop called ten that has 10000 txt files with naming convention like 1a.txt, 2a.txt etc.

This is the code inside my JSR223 preprocessor:-

import org.apache.jmeter.services.FileServer
import java.util.concurrent.TimeUnit

// Get the filename
def file = vars.get("filename")

// Skip unwanted files
if (file == ".DS_Store" || !file.endsWith(".txt")) {
    return
}

def path = "/Users/username/Desktop/ten/" + file
def fileContent = new File(path).text

// Log the file being posted
log.info("Thread " + ctx.getThreadNum() + " is posting file: " + file)

// Save the file content to a variable
vars.put("fileContent", fileContent)

// Save the start time
long startTime = System.nanoTime()
vars.put("startTime", startTime.toString())
vars.put("fileName", file)

Configuration Details: Thread Group Settings:

Number of Threads (users): 40

Ramp-Up Period (seconds): 20

Loop Count: 250

Constant Throughput Timer Settings:

Target Throughput: 2400 requests per minute (40 requests per second)

Calculate Throughput based on: All active threads in current thread group

Total Number of Messages: 10000

Expected Behavior: The test should execute 40 requests per second.

Actual Behavior: The test is only executing roughly 10-12 requests per second.


Solution

  • You will get 40 requests per second with 40 users only if response time will be 1 second (or less). If response time will be higher - the throughput will be proportionally lower.

    You can try increasing the number of threads, it might resolve you issue (given the system under test is capable of handling the load) or consider using Concurrency Thread Group and Throughput Shaping Timer combination, this way JMeter will be able to kick off extra threads if current amount is not enough to reach the desired throughput.

    Also writing data to the same file with 40 threads using JSR223 Post-Processor is not the best idea as in case of multithreading the result file will be corrupt, consider using Flexible File Writer instead.