I am using Locust to push messages into a RabbitMQ queue. I'm able to do this easily using the RabbitMQ sample from the locust.io-demo repository, but now I need to force the single task to wait 1 minute between each invocation.
In my test, I need to push 100 messages into a queue every minute since this system will receive messages in "bursts" in one-minute increments. I've tried implementing this but have been unsuccessful. Here's the first thing I tried:
from rabbitmq import get_client
import time
from locust import Locust, TaskSet, task, events
class RabbitTaskSet(TaskSet):
@task
def publish(self):
get_client().publish()
class MyLocust(Locust):
task_set = RabbitTaskSet
min_wait = 30000
max_wait = 30000
def on_locust_stop_hatching():
get_client().disconnect()
events.locust_stop_hatching += on_locust_stop_hatching
I assumed that the publish
method would be executed once every 30 seconds since that's what the value for the min and max wait times. I then started Locust with 1 user and a hatch rate of 1.
What I saw was that a new request was being generated every 10 seconds in the Locust UI.
I then tried this instead:
class RabbitTaskSet(TaskSet):
@task
def publish(self):
get_client().publish()
time.sleep(30)
class MyLocust(Locust):
task_set = RabbitTaskSet
# min_wait = 30000
# max_wait = 30000
I then started Locust again with 1 user and a hatch rate of 1. Oddly enough I saw the same results - 1 new request every 10 seconds. Heck I even tried using gevent.time
instead of time.time
but I still got the same results.
How can I make my publish task wait for 30 seconds between each execution? Is there a property that I'm missing?