2

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?

Tom Purl
  • 519
  • 4
  • 20
  • Check this out https://stackoverflow.com/questions/25392451/locust-how-to-make-locust-run-for-a-specific-amount-of-time – bumblebee May 02 '19 at 05:40
  • Thank you for the quick response bumblebee but I don't want to stop the entire test. I want my taskset to wait for 30 seconds before executing. I want all users to run the task set at the same time and then wait 30 seconds before running again. – Tom Purl May 02 '19 at 13:39
  • Have a look at this https://github.com/locustio/locust/issues/59#issuecomment-41624517 – bumblebee May 02 '19 at 13:46

1 Answers1

0

use this code

from rabbitmq import get_client
import time

from locust import Locust, TaskSet, task, events,between

class RabbitTaskSet(TaskSet):
    @task
    def publish(self):
        get_client().publish()

class MyLocust(Locust):
    task_set = RabbitTaskSet
    wait_time = between(5000, 10000)


def on_locust_stop_hatching():
    get_client().disconnect()
Loopero
  • 31
  • 1
  • 5