Jmeter - weighted random values?

前端 未结 4 606
执念已碎
执念已碎 2021-01-14 00:32

How can I go about running tests/controllers based on random weight? For instance, have two tests, one with a weight of 25%, the other with 50%. The one with 50 should run t

相关标签:
4条回答
  • 2021-01-14 01:11

    I think you can use Throughput Controllers configured someway like the following:

    Throughput Controller

    Throughput values are pre-set, either from configuration properties or generated in acceptable range of values (0..100 in this case).

    0 讨论(0)
  • 2021-01-14 01:16

    I achieved this by creating a Switch Controller with the following switch value:

    ${__javaScript( var s="001"; new Number(s.charAt( Math.floor(Math.random()*s.length) )) )}
    

    The javascript selects a random character from the string s and converts it to a number. So in the example above, 0 would be selected twice as often as 1, and the weightings can be altered by adding/removing characters from the string.

    I used a String and not an Array was because the javascript version used by my version of JMeter appeared to not support array literals, so this made it a bit less verbose.

    0 讨论(0)
  • 2021-01-14 01:25

    You better use 2 thread groups for this case. Set up first to generate more request than second.

    PS. You may use Throughput Shaping Timer to control rate in each group.

    0 讨论(0)
  • 2021-01-14 01:26

    For some simple weightings you can use the fact the switch controller defaults to the first child to your advantage. Eg 50% 25% 25% like so

    Switch Controller - ${__Random(0,3)}
     - Child 0 (and 3)
     - Child 1
     - Child 2
    
    • http://jmeter.apache.org/usermanual/component_reference.html#Switch_Controller
    • http://jmeter.apache.org/usermanual/functions.html#__Random

    You take this one step further by grouping tasks in Random and Simple controllers as the children.

    0 讨论(0)
提交回复
热议问题