Search code examples
jmeterfile-read

Usage of file protocol in HTTP request


Reading file using HTTP Request is suggested for Passing variables between threads.

For example you could use the Save Responses to a file listener or perhaps a BeanShell PostProcessor in one thread, and read the file using the HTTP Sampler "file:" protocol, and extract the information using a PostProcessor

Which is working, but should the warning in doc be ignored?

Note: the FILE protocol is intended for testing purposes only. It is handled by the same code regardless of which HTTP Sampler is used.

Is/when it safe/good practice to use file protocol or is it deprecated/bad practice?


Solution

    1. Using Beanshell PostProcessor is a definitely bad practice, since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language
    2. Writing and reading files might cause massive disk IO overhead which can become the bottleneck for your script especially when it comes to high loads. Moreover in-memory operations will be much faster than writing/reading the file to/from the file system

    Assuming all above:

    although there is nothing wrong with using file protocol if you need to read the data from a file on the file system, it's better to avoid these interim files and pass the data between threads using memory, the options are in:

    1. Use __setProperty() function in 1st thread group to store the value and __P() function in other Thread Groups to read the previously stored value
    2. Use Inter-Thread Communication Plugin which can be used for passing variables between threads, even if they live in different Thread Groups (see SynchronizationExample.jmx for a practical use case). Inter-Thread Communication Plugin can be installed using JMeter Plugins Manager