0
votes

I have created a test case wherein I need to read files from a directory and for each file I need to invoke an HTTP request. So I created a Bean Sampler to list files in a directory and put that in a variable that will be used by a For each controller. I have kept HTTP requests inside For each controller so that for each file an HTTP request is invoked. The above works like a champ for one thread. When I update the thread count > 1, then I see a weird behavior that the number of HTTP requests is less than even the number of threads. I am expecting the HTTP request to be (no. of threads * no. of files * loop count).

Please let me know what is the problem.

I am attaching the screenshot for better illustration Thread Group

Bean Sampler

File folder = new File("D:\\OIT_FUNCTIONS\\inputSamples\\files\\large");

File[] files = folder.listFiles(new FileFilter() {
    public boolean accept(File file) {
        return file.isFile();
    }
});

for (int i=0; i < files.length; i++) {
    vars.put("file_" + i, files[i].getAbsolutePath());
    MimetypesFileTypeMap fileTypeMap = new MimetypesFileTypeMap();
    String mimeType = fileTypeMap.getContentType(files[i]);
    vars.put("mime",mimeType);
}

For each controller

HTTP Reuqests

Aggregate graph

If you see the Aggregate graph it can be seen that only 151 requests was called while 100 bean Sampler was called.

I am expecting [100(no.of threads) * no. of files * loop count] HTTP request to be called

1
Please have a look at how to ask a question here. If it's possible, also provide minimal reproducible example (better code snippets, than pictures). This way we can help better.Giorgi Tsiklauri
@GiorgiTsiklauri Provided the code of bean samplervinit saha

1 Answers

0
votes

The problem is that you're violating 3 best practices:

  1. You're using Beanshell for scripting however since JMeter 3.1 you should be rather using JSR223 and Groovy. In particular for your use case you can go for Directory Listing Config plugin
  2. You're reading the files by each thread on each iteration althrough it can be done only once.
  3. You're running your test in GUI mode although GUI mode is for tests development and debugging, test must be executed in command-line non-GUI mode

Without seeing stdout and jmeter.log file I cannot tell exactly what went wrong, but definitely it's due to at least above of the aforementioned points (if not to all of them)