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

Runner doesn't look on shape_class of environment #1862

Closed
kirillantv opened this issue Aug 22, 2021 · 10 comments
Closed

Runner doesn't look on shape_class of environment #1862

kirillantv opened this issue Aug 22, 2021 · 10 comments
Labels
bug stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it

Comments

@kirillantv
Copy link

Describe the bug

I use locust as library and I am investigating how to user custom load shape in this case. And seems like locust ignore shape_class in environment.

Expected behavior

Load increasing by 10 users every 30 seconds

Actual behavior

I've got only 1 user per second all the time

After approximately 2 minutes:

 Name                                                                              # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 GET //                                                                               100     0(0.00%)  |    1105     782    2129    1000  |    0.40    0.00
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                                           100     0(0.00%)  |    1105     782    2129    1000  |    0.40    0.00

 Name                                                                              # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 GET //                                                                               101     0(0.00%)  |    1103     782    2129    1000  |    0.50    0.00
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                                           101     0(0.00%)  |    1103     782    2129    1000  |    0.50    0.00

 Name                                                                              # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 GET //                                                                               102     0(0.00%)  |    1103     782    2129    1000  |    0.50    0.00
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                                           102     0(0.00%)  |    1103     782    2129    1000  |    0.50    0.00

 Name                                                                              # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 GET //                                                                               103     0(0.00%)  |    1102     782    2129    1000  |    0.50    0.00
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                                           103     0(0.00%)  |    1102     782    2129    1000  |    0.50    0.00

 Name                                                                              # reqs      # fails  |     Avg     Min     Max  Median  |   req/s failures/s
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 GET //                                                                               104     0(0.00%)  |    1100     782    2129    1000  |    0.50    0.00
----------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregated                                                                           104     0(0.00%)  |    1100     782    2129    1000  |    0.50    0.00

Steps to reproduce

This is my code:

import gevent
import math
from locust import HttpUser, task, between, constant
from locust.env import Environment
from locust.stats import stats_printer, stats_history
from locust.log import setup_logging
from locust.shape import LoadTestShape

setup_logging("INFO", None)


class StepLoadShape(LoadTestShape):

    step_time = 30
    step_load = 10
    spawn_rate = 10
    time_limit = 600

    def tick(self):
        run_time = self.get_run_time()

        if run_time > self.time_limit:
            return None

        current_step = math.floor(run_time / self.step_time) + 1
        return (current_step * self.step_load, self.spawn_rate)


class User(HttpUser):
    wait_time = constant(1)

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


env = Environment(user_classes=[User], shape_class=StepLoadShape, host="https://docs.locust.io/")
env.create_local_runner()

gevent.spawn(stats_printer(env.stats))

gevent.spawn(stats_history, env.runner)

env.runner.start(1, spawn_rate=10)

gevent.spawn_later(600, lambda: env.runner.quit())

env.runner.greenlet.join()

Run it with python /path_to_file

Environment

  • OS: macOS 10.15.4
  • Python version: 3.7.11
  • Locust version: 2.1.0
  • Locust command line that you ran:
  • Locust file contents (anonymized if necessary):
@kirillantv kirillantv added the bug label Aug 22, 2021
@cyberw
Copy link
Collaborator

cyberw commented Aug 22, 2021

@max-rocket-internet is the most load shape-y person. Do you have time to take a look?

@max-rocket-internet
Copy link
Contributor

@kirillantv does it work when using it as a normal locustfile and a master + worker? i.e. remove everything after the User class. You can test this easily using docker-compose for example.

@mboutet
Copy link
Contributor

mboutet commented Aug 23, 2021

@kirillantv Is this also occuring with locust 1.6?

@kirillantv
Copy link
Author

@max-rocket-internet yeap. With normal locustfile that works.

@mboutet with locust 1.6 it is also occuring. I am also confused by runner.start(1, spawn_rate=10) - I implement all load logic in load shape, but I also must pass start param.

@mboutet
Copy link
Contributor

mboutet commented Aug 24, 2021

You should use env.runner.start_shape() for load shape.

@kirillantv
Copy link
Author

@mboutet Hm. Thanks! I also needed to pass shape_class param to env as object, not as class.
I think this method is sorely lacking in the documentation

@cyberw
Copy link
Collaborator

cyberw commented Aug 25, 2021

Documentation PR would be welcome. And a warning logging if someone runs runner.start() with a shape set on environment.

cyberw added a commit that referenced this issue Aug 29, 2021
…tart(). Helps avoid confusion and fixes #1862 (or at least makes it very clear what the problem is)
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it label Oct 25, 2021
@github-actions
Copy link

github-actions bot commented Nov 4, 2021

This issue was closed because it has been stalled for 10 days with no activity. This does not necessarily mean that the issue is bad, but it most likely means that nobody is willing to take the time to fix it. If you have found Locust useful, then consider contributing a fix yourself!

@github-actions github-actions bot closed this as completed Nov 4, 2021
@gauravmadarkal
Copy link

I still have this issue where I pass the custom load shape and call runner.start_shape(), the load test spawns 1 user every second instead of following what the load shape tells it to

load_test_shape = CustomLoadTestShape()
env = Environment(user_classes=user_classes, shape_class=load_test_shape, events=events)
runner = env.create_local_runner()
env.events.init.fire(environment=env, runner=runner)
runner.start_shape()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it
Projects
None yet
Development

No branches or pull requests

5 participants