locustio / locust

Write scalable load tests in plain Python 🚗💨
https://locust.cloud
MIT License
25.11k stars 3k forks source link

Remove specific users #2962

Open paulcFanDuel opened 3 weeks ago

paulcFanDuel commented 3 weeks ago

What The modification in this PR is to enhance the existing (very useful) functionality of being able to increase the amount locust users for a specific User Class.

Changes in this pr allows us to decrease the running locust users for individual user classes (rather than all user classes) deterministically.

The functionality remains the same for normal spawn/despawn events where user classes are not specified.

Currently in locust we can

  1. Given start conditions of a locust run where we have 3 users of class types [UserA, UserB, UserC] and are running weight 1,1,1,
  2. We can individually increase UserA for example if we send a dispatch through with:
new_dispatch(
        self, target_user_count=4, spawn_rate=1, user_classes[UserA]
    )
  1. This will give us the following running users: {"UserA": 2, "UserB": 1, "UserC": 1},
  2. We do not have the ability to remove 1 running user of a specified class currently.

With the changes in this pr we can now do the following:

  1. With starting test conditions giving us the following running users: {"UserA": 1, "UserB": 1, "UserC": 1},
  2. Remove an individual running user: new_dispatch( self, target_user_count=2, spawn_rate=1, user_classes[UserA] )
  3. Result {"UserA": 0, "UserB": 1, "UserC": 1}
cyberw commented 1 day ago

Hi! Sorry for the long response time, last couple of weeks have been insanely busy.

I think this looks very cool! Can you show a more complete example of how it would be used? Calling new_dispatch "manually" is a bit of a way to use Locust...