question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for completely custom load pattern / shape

See original GitHub issue

Describe the solution you’d like

To be able to programmatically control the user and hatch rate over a period of time. This would allow us to scale up and down and generate spikes which allows more accurate representation of real world load.

We can generate this easily:

Screen Shot 2020-06-15 at 13 05 52

But not this:

Screen Shot 2020-06-15 at 13 07 49

And not this either:

Screen Shot 2020-06-16 at 14 10 03

Describe alternatives you’ve considered

I tried something quite hacky but it’s not good enough:


def traffic_spike(spike_after, spike_length, normal_wait_time):
    def wait_time_func(self):
        if not hasattr(self,"_traffic_spike_start"):
            self._traffic_spike_start = time()
            return normal_wait_time
        else:
            run_time = time() - self._traffic_spike_start
            if run_time > (spike_after + spike_length) or run_time < spike_after:
                return normal_wait_time
            else:
                return 0

    return wait_time_func

class QuickstartUser(HttpUser):
    wait_time = traffic_spike(600, 300, 1)

    @task
    def index_page(self):
        self.client.get("/hello")
        self.client.get("/world")

Also I know we could implement this outside of locust and call the locust API but it’s not ideal.

Additional context

k6 has something called stages that looks great:

export let options = {
  stages: [
    { duration: '30s', target: 20 },
    { duration: '1m30s', target: 10 },
    { duration: '20s', target: 0 },
  ],
};

It would be great to see something like this in locust. Perhaps it could look like this:

from locust import User, TaskSet, between, LoadShape


class LoadWithSpike(LoadShape):
    stages = [
        {'duration': 3600, 'users' 1000, 'hatch': 5},
        {'duration': 300, 'users' 5000, 'hatch': 50},
        {'duration': 1800, 'users' 1000, 'hatch': -50}
    ]


class MyUser(HttpUser):
    wait_time = between(1, 3)

    @task(2)
    def index(self):
        self.client.get("/")

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
cyberwcommented, Jul 29, 2020

I think the shape should be possible to have in a separate file

Can do but this is needless complexity, no? You can already import things from other files in python.

I just like the idea of having the load profile “orthogonal” to the User definition.

Sure, you could specify the shape file with -f and have multiple shape files import the same “actual” locustfile (with User definitions), but it feels a bit upside down and ties the load profile tightly to a locustfile.

Maybe not super important though…

1reaction
cyberwcommented, Jul 29, 2020

Looks nice. We’ll need a couple really of good unit tests for this, including cases

  • correctly applying stop_timeout when ramping down
  • make sure there is no error for parameters (-u, -t etc) not being specified when there is a shape.
  • where new slaves are added during the test (I think the appropriate behaviour is trying to keep the number of users balanced across slaves but not stopping users already running just to migrate them somewhere else)

A few opinions:

  • I think the name should be Shape, not Shaper
  • I think the shape should be possible to have in a separate file, specified using a new parameter (–shape?). Or maybe we should just allow multiple -f arguments (as the effect of --shape would be to load another file which happens to include a shape class)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create custom patterns - Adobe Support
Learn how to create custom patterns using Adobe Illustrator. Enhance your presentation templates and make your slides pop!
Read more >
3D Printing Supports – The Ultimate Guide - All3DP
Learn everything you need to know about 3D printing support structures. Tackle overhangs and bridges in your models with confidence!
Read more >
How to Create a Custom Pattern in Photoshop - YouTube
In this tutorial I will show you how to create a custom pattern in Photoshop for your custom design.You can be very creative...
Read more >
Filling Shapes with Colors and Patterns - SketchUp Help
Select a folder from the available options to choose one of LayOut's preset patterns. If you'd like to use a custom pattern, you...
Read more >
How to Add Custom Pattern Fills in Silhouette Studio V4
Custom patterns can be anything from a photo to a digital background or seamless pattern. These can be used to fill shapes for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found