7

how to configure the thread group ramp up time with a jmeter variable, I tried for both number of threads and ramp up time. No of threads is working fine, but ramp up time takes the default value 1 and the variable value doesn't take effect, Appreciate any help

Mercy
  • 171
  • 3
  • 12

3 Answers3

19

You cannot use variables in Thread Group setting as Thread Groups are initialised during startup, before any variables are read.

If you need to make number of threads and/or ramp-up period configurable use __P() function like:

  • ${__P(threads,)}
  • ${__P(rampup,)}

Properties

Aforementioned threads and rampup properties can be defined in several ways:

  1. If you run JMeter in command-line non-GUI mode you can pass the properties via -J command line key as

    jmeter -Jthreads=50 -Jrampup=30 -n -t /path/to/your/testplan.jmx
    

    The same approach will work for GUI mode, however it is not recommended to use GUI for load test execution as it is quite resource consuming and may ruin your test.

  2. You can define these properties in user.properties file (located in /bin folder of your JMeter installation) as:

    threads=50
    rampup=30
    

    After restart JMeter will pick the properties up and you will be able to refer them via __P() function as described above.

See Apache JMeter Properties Customization Guide for comprehensive information on various JMeter properties and ways of working with them

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • JMeter is so easy to use, to pass an environment variable to it all you need to do is 1) set the environment variable 2) pass the environment variable to Jmeter with the -J commandline option 3) define a user-defined-variable that uses the obvious __p() function to read the variable 4) use that user defined varaible in youe step definition. So much better than other apps that would do silly things like allow you to just set the OS env var and then refer to that in your step definition – dan carter Jun 04 '19 at 21:40
  • There are better ways, for example [__env() function](https://jmeter-plugins.org/wiki/Functions/#envsupfont-color-gray-size-1-since-1-2-0-font-sup) like `${__env(your environment variable here,,)}` or [__groovy()](https://www.blazemeter.com/blog/groovy-new-black) function like `${__groovy(System.getenv('your environment variable here'),)}`. At least JMeter is flexible enough to be used by such a highly skilled professional like you and a greenhorn like me and provides more than 1 way to implement this or that requirement – Dmitri T Jun 05 '19 at 03:38
  • have to install a 3rd party plugin to read an environment variable lol. And the groovy syntax is so concise. But seriously thanks, that groovy method still far less clunky than the normal -J and __P() way so i'm gonna switch to it. – dan carter Jun 06 '19 at 10:31
  • Interestingly, even on Jmeter 5.2.1, I can use User Variables (based on Jmeter properties) for (1) number of threads and (2) test duration, but NOT for the ramp up period. Seems quite inconsistent. – Randall T. Apr 13 '21 at 19:16
2

There is no reason why it works for # of threads but doesn't work for ramp-up time. I've been using configurable properties for both with success.

1 is the default value in JMeter if variable can't be resolved properly. You likely made a typo. To investigate the problem, you may want to use 'Property Display' element (right-click WorkBench / Add / Non-Test Element / Property Display).

If this doesn't help, please post link to the screenshot of thread group, and relevant part of your config where you define the ramp-up time variable.

EDIT : example

This is the way I usually work with configurable properties stored in external files (and it works for ramp-up as well):

  • define user defined variable on test plan level, e.g. someVarName is ${__P(someVarName)}
  • then use this var e.g. in ramp-up as ${someVarName}
automatictester
  • 2,436
  • 1
  • 19
  • 34
1

You cannot use variables for those values, only properties:

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116