开发者

Jmeter - weighted random values?

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 twice as often.

Perhaps throughput controller mixed with random somehow?


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

Jmeter - weighted random values?

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


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.


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜