Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to define bursty traffic #225

Closed
bearrito opened this issue Jan 1, 2015 · 2 comments
Closed

Be able to define bursty traffic #225

bearrito opened this issue Jan 1, 2015 · 2 comments

Comments

@bearrito
Copy link

bearrito commented Jan 1, 2015

Perhaps there is a way to do it with existing functionality but I would like a way to generate bursty traffic.

By that I would mean : define it in terms of standard deviations or multiples of baseline load for a certain interval.

So for now, if I have a N single workers I will have on average M = N * (min_wait + max_wait) /2 requests per second made.

What I would like is - every K seconds increase the load to say M * L requests per second for J seconds, where J,K,L > 1

Thoughts?

@4tapsmobile
Copy link

Two locusts? One for baseline and another for the burst? Your "burst" locust could sleep for K seconds and repeat. That's what I would do.

@heyman
Copy link
Member

heyman commented Jan 12, 2015

What @4tapsmobile is suggesting might work for you.

It should also be fairly easy to achieve by overriding the wait method in your TaskSet, which is the method that each running Locust user calls between each task execution. (

def wait(self):
)

Here's a start:

from time import time
from locust import TaskSet

class BurstingTaskSet(TaskSet):
    K = 10
    J = 3
    burst_wait_time = 0.1

    bursting = False
    interval_start = time()

    def set_bursting(self):
        if not self.bursting and time() - self.interval_start > self.K:
            self.bursting = True
            self.interval_start = time()
        elif self.bursting and time() - self.interval_start > self.J:
            self.bursting = False
            self.interval_start = time()

    def wait(self):
        self.set_bursting()
        if self.bursting:
            self._sleep(self.burst_wait_time)
        else:
            super(BurstingTaskSet, self).wait()

If you want to synchronise the bursting between a lot of running locust users (which take time to spawn, and might run distributed on different servers), you probably want to add some synchronisation logic that uses the system clock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants