In my scenario, I'm stopping users after completing a SequentialTaskSet. At the same time, I need to launch users in a regular interval, for example at each 100ms. There may be some users already running or not, it doesn't matter. However, if there's a user already running, locust won't create a new one, i.e. it won't create on top of a user.
def spawn_users(env):
while True:
env.runner.start(1, spawn_rate=50)
gevent.sleep(0.1) # sleep for 100 ms
for x in range(1000):
gevent.spawn(spawn_users, env)
N.B. Obviously, I can create 50/100/any number of users at a time but I need to create one by one.
Summary: Create locust users at a regular interval no matter how many users already running and how much time they are taking executing tasks.
Note: I'm also open to try other load testing frameworks if this use case is more suitable for them.
A more supported and perhaps simpler way to do this would be to use a Load Test Shape.
https://docs.locust.io/en/stable/generating-custom-load-shape.html
The end result is similar to what you've already done, but may give you slightly more freedom and abstracted stability.