Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add property to disable FunctionProperty caching #5788

Merged
merged 2 commits into from
May 12, 2023

Conversation

vlsi
Copy link
Collaborator

@vlsi vlsi commented Mar 7, 2023

Description

By default, JMeter caches function properties during a test iteration, however, it might cause unexpected results when a component is shared across threads and the expression depends on the thread variables.

It looks like the caching results in wrong HTTP headers being sent if #727 is applied.
Even though JMeter does not modify HTTP Header Manager components during the execution, however, it looks like any function that is used in the headers would be "cached", so other threads could reuse the value generated by a completely different thread.

I believe the current caching behaviour is not well-defined, so I suggest we disable it in the upcoming versions.

The PR does not change the existing behaviour, and it just adds a property so the users could disable caching.

@vlsi vlsi force-pushed the function_caching branch from d52ecb9 to 08c4a16 Compare March 23, 2023 10:25
@vlsi vlsi force-pushed the function_caching branch from 08c4a16 to 7beaf41 Compare April 22, 2023 11:51
@vlsi
Copy link
Collaborator Author

vlsi commented May 5, 2023

Frankly speaking, I lean towards changing the default to "do not cache based on iteration number only" as the previous behavior (==cache based on iteration number) was introducing silent and hard-to-notice bugs, so I would alter the default to "do not cache".
If somebody still needs the cache, they could activate it back, however, I expect we would still remove the setting sometime in the future.

@vlsi vlsi force-pushed the function_caching branch 2 times, most recently from 730dea5 to fdd8266 Compare May 5, 2023 16:46
@@ -102,14 +102,6 @@ public SampleResult sample(Entry e)// Entry tends to be ignored ...
return res;
}
try {
String request = getScript();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FSchumacher , it turns out this caused two executions of getScript for BeanShellSampler.
One was to pass the script for res.setSamplerData, and the second getScript was in processFileOrScript for actual BSH execution.

I guess that is unexpected. However, the fix does not seem to be trivial: if I change processFileOrScript signature, it breaks backward compatibility because others might have overridden the method.
On the other hand, processFileOrScript does not expose script and fileName, so it is not clear how to get that information out.

For now, I added a new parameter to processFileOrScript so it calls setSamplerData as needed. I think it is unlikely that people override processFileOrScript. I checked GitHub search, and I found no cases for overriding processFileOrScript.

If you are ok with that, I think we need to make the same changes for JSR223 samplers. They have exactly the same issue, and it can call getScript() several times during execution as well.

@vlsi vlsi added this to the 5.6 milestone May 10, 2023
@vlsi vlsi force-pushed the function_caching branch 5 times, most recently from 33ff2c8 to 62d6e56 Compare May 11, 2023 17:29
vlsi added 2 commits May 11, 2023 20:32
Previously it cached the values based on iteration number only
which triggered wrong results on concurrent executions.

The previous behavior can be temporary restored with
function.cache.per.iteration=true property.
…mpler, and JSR223TestSampler

Previously, BeanShellSampler called getScript several times which
might cause wrong results when the script included a function that
changes on each call (e.g. couter).
Now getScript is called only once per sample.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants