Search code examples
jmeterload-testingbeanshell

How to use BeanShell server to modify Jmeter's user properties while running the test


I would like to control throughput in real-time while running the test. How do I do that using BeanShell server?

Basically I want to update a user property 'throughput' (used in Constant Throughput Timer) from command line while the test is running.

Solution: Based on Dmitri's answer I did the following:
1. I added to user.properties:

beanshell.server.port=9000  
beanshell.server.file=beanshell.server.file=/home/sam/JMeter/apache-jmeter-4.0/extras/startup.bsh
  1. Started JMeter and my test.
  2. Executed this command in Terminal:
    ~/JMeter/apache-jmeter-4.0$ java -jar lib/bshclient.jar localhost 9000 /home/sam/JMeter/beanshell/setthroughput.bsh 100
  3. Value of throughput property is now 100. Fantastic!

Solution

    1. Add the next 2 lines to user.properties file:

      beanshell.server.port=9000
      beanshell.server.file=../extras/startup.bsh
      
    2. Restart JMeter to pick the settings up
    3. Set throughput property in the Constant Throughput Timer using __P() function like:

      ${__P(throughput,60)}
      

      this will set default throughput to 60 requests per minute (1 request per second), if throughput property will be defined somewhere somehow - the value will get overriden.

    4. Create setthroughput.bsh in "lib" folder of your JMeter installation with the following contents:

      setprop("throughput", args[0]);
      
    5. In the runtime you will be able to modify the throughput like:

      java -jar bshclient.jar localhost 9000 setthroughput.bsh 100
      

      JMeter set throughput

    More information: Beanshell Server


    I believe it would be easier if you switch to Throughput Shaping Timer which has load_profile property so you will be able to control throughput in more flexible and efficient manner. You can install Throughput Shaping Timer using JMeter Plugins Manager