apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.3k stars 2.09k forks source link

StringFromFile: Behaviour not clear with more than one Thread if file name depends on Thread (__threadNum in the file name) #2670

Closed asfimport closed 12 years ago

asfimport commented 12 years ago

@pmouawad (Bug 52284): I think there is an issue in StringFromFile function. In the docs and javadocs it is said that:

But debugging the attached Test Case , I see only one instance of StringFromFile shared by the 3 threads. So this leads to a buggy result. Expected result shoud be that each time threadNum should match file Num (not the case) And each file should be read, depending on execution some files are not read at all.

Created attachment TestFunction.jmx: Test plan

TestFunction.jmx ````xml false false continue false 3 3 1 1322690907000 1322690907000 false Sleep_Time 100 = Sleep_Mask 0xFF = Label ${__threadNum}-${__StringFromFile(/data/jmeter/StringFromFile/${__threadNum}.txt, VAR1)} = ResponseCode = ResponseMessage = Status OK = SamplerData = ResultData = org.apache.jmeter.protocol.java.test.JavaTest false saveConfig true true true true true true true false true true false false true false false false false false 0 true 3 ````

OS: All

asfimport commented 12 years ago

@pmouawad (migrated from Bugzilla): Created attachment Capture d’écran 2011-12-04 à 11.37.40.png: Run result

Run result
asfimport commented 12 years ago

@pmouawad (migrated from Bugzilla): Created attachment Archive.zip: Test data

asfimport commented 12 years ago

@pmouawad (migrated from Bugzilla): (In reply to comment 0)

Created attachment 28023 [details] Test plan

I think there is an issue in StringFromFile function. In the docs and javadocs it is said that:

  • JMeter instantiates a copy of each function for every reference in a Sampler or elsewhere; each instance will open its own copy of the the file

This part is OK in fact, I mixed up Thread and multiple usage

But debugging the attached Test Case , I see only one instance of StringFromFile shared by the 3 threads. So this leads to a buggy result. Expected result shoud be that each time threadNum should match file Num (not the case) And each file should be read, depending on execution some files are not read at all.

The issue is more in Synchronisation as described in Test Plan

asfimport commented 12 years ago

Sebb (migrated from Bugzilla): Function references are only instantiated once per occurrence in the test Plan.

So if a sampler references StringFromFile, all threads will use the same instance of the function.

This allows the same data file to be shared between threads.

The file is opened once, on the first reference, so will use whatever thread number happens to run the first sample.

This is similar to how the global counter (IterationCounter) works.

StringFromFile was designed to share the data across threads.

CSV Dataset can be used for per-thread data files.

It would be possible to implement a per-thread version of StringFromFile by using ThreadLocal storage for the file details. However I'm not sure there's a good use case for it, given that we already have CSV Dataset.

I'll update the Javadoc and function desc.

asfimport commented 12 years ago

Sebb (migrated from Bugzilla): Docs updated.

URL: http://svn.apache.org/viewvc?rev=1212996&view=rev Log: Clarify docs (https://github.com/apache/jmeter/issues/2670)

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java jmeter/trunk/xdocs/usermanual/functions.xml