开发者

How can I accurate count for specific user when dealing with multiuser in locust

开发者 https://www.devze.com 2022-12-07 21:53 出处:网络
Background I was trying to use locust to test a web application, which has some kinds of user role like admin and common user; I want to run test and set different user a given count, eg: {\'admin\':

Background

I was trying to use locust to test a web application, which has some kinds of user role like admin and common user; I want to run test and set different user a given count, eg: {'admin': 1, 'common user': 50}

My Question

  1. Does locust support this feature?
  2. I read the doc and source example which use stages to set user count at different stage
stages = [
        {"duration": 60, "users": 10, "spawn_rate": 10, "user_classes": [WebsiteUserA]},
        {"duration": 100, "users": 50, "spawn_rate": 10, "user_classes": [WebsiteUserA, WebsiteUserB]},
        {"duration": 180, "users": 100, "spawn_rate": 10, "user_classes": [WebsiteUserA]},
        {"duration": 220, "users": 30, "spawn_rate": 10},
        {"duration": 230, "users": 10, "spawn_rate": 10},
        {"duration": 240, "users": 1, "spawn_rate": 1},
    ]

def tick(self):
    run_time = self.get_run_time()

    for stage in self.stages:
        if run_time < stage["duration"]:
            # Not the smartest solution, TODO: find something better
            try:
                tick_data = (stage["users"], stage["spawn_rate"], stage["user_classes"])
            except KeyError:
                tick_data = (stage["users"], stage["spawn_rate&quo开发者_C百科t;])
            return tick_data
    return None

It seems that it can make sure which kind of user will run at different stage, but it doesn't show how can i accurate how many user WebsiteUserA will have and how many the others

  1. Is there any way or plugins can match my requirement ? All i want is to set 1 WebsiteUserA and 50 WebsiteUserB at 2th stage in that example
  2. If there not, is there any tools can help me with that?


You have a few options.

  1. If you absolutely only want a set number of users, set fixed_count on your admin user. From the docs:

If the value > 0, the weight property will be ignored and the ‘fixed_count’-instances will be spawned. These Users are spawned first. If the total target count (specified by the –users arg) is not enough to spawn all instances of each User class with the defined property, the final count of each User is undefined.

  1. If you don't want a set count of users and you just want to make sure your admin user has roughly 50x less load than the other users, set the weight attribute on your users either directly or when you pass in the users, as a dictionary instead of a list:

{"duration": 100, "users": 50, "spawn_rate": 10, "user_classes": {WebsiteUserA: 1, WebsiteUserB: 50}}

More on these first two options can be found in the docs.

  1. Control the ratio and user spawn decision yourself. Make a single user and create your own logic to determine when and how to run the admin flow the way you want by calling whatever functions you want. Use a global variable or various other methods to track whether or not you need to spawn an admin user. This can be pretty powerful and give you lots of control, but it can be a bit difficult to do when running in distributed mode.
0

精彩评论

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