Am 27.07.2017 um 03:35 schrieb David Luu:
JMeter has random controller, and I was wondering how one would set up
weighted ratios of different samplers executing at different frequency in
the random draw.

For example comparing to the option available in locust.io by specifying
the ratio of execution frequency:

http://docs.locust.io/en/latest/writing-a-locustfile.html#declaring-tasks
http://docs.locust.io/en/latest/writing-a-locustfile.html#tasks-attribute

What is the equivalent for JMeter, if available?

Would it be nesting random controllers so the the less frequent samplers go
into yet another random controller within a root random controller and
continue the nesting process for the lesser frequent samplers and the
highest weighted one is under root random controller?
I would use a switch controller together with some jsr223 scripting. You could use:
 - test action
   - jsr223 preprocessor (for code see below)
- switch controller (switching on ${switchValue} which is set in preprocessor above) - simple controller (named with one of the possible values of ${switchValue} see below)
   - simple controller (..)
   ...

Code for the preprocessor:
---start snippet---
weightsMap = ["first": 5, "second": 3, "third": 1]

def computeSwitchValue(weightsMap) {
    weightsSum = weightsMap.values().sum()
    r = Math.random() * weightsSum
    sum = 0.0
    for (entry in weightsMap.entrySet()) {
        switchValue = entry.key
        sum += entry.value
        if (sum >= r) {
            return switchValue
        }
    }
}

vars.put("switchValue", computeSwitchValue(weightsMap))
---end snippet---

Don't forget to check "Cache compiled script if available"

The weights are defined in weightsMap where the keys are the names of the controllers inside the switch controller and the values are the actual weights.

Hope this helps,
 Felix

Thanks,
David



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to