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

Fixed RPS load test #2697

Open
2 tasks done
rockingcubes opened this issue May 3, 2024 · 3 comments
Open
2 tasks done

Fixed RPS load test #2697

rockingcubes opened this issue May 3, 2024 · 3 comments

Comments

@rockingcubes
Copy link

Prerequisites

Description

I'm testing API endpoints in which the test case is that in total 10 minutes I have to ramp up users linearly until the rps is >= 70 if rps greater than 70 and the current time is < 10 minutes then maintain in steady state for remaining time. My question is, is there a way I can take the current RPS and user count in every iteration? My code is

from locust import TaskSet,HttpUser, LoadTestShape

class Scan(TaskSet):
    @task
    def perf_scan(self):
        self.client.get(“/api”)

class url(HttpUser):
    tasks = [Scan]

class CustomLoadShapeScenario2(LoadTestShape):
    def tick(self):
        total_time = 600
        run_time = self.get_run_time()
        if RPS < 70 and run_time<total_time: # here for RPS I need a solution to extract from locust
            users = run_time//10
            spawn_rate = 1
        elif run_time<total_time:
            users = user_count # here for RPS I need a solution to extract from locust. It is the user_count until the if condition was satisfied
            spawn_rate = 1
        return (users, spawn_rate) 

Any code example or solution will be of great help.

@Sawiq
Copy link

Sawiq commented May 6, 2024

A one possibility I can see would be to access the stats instance within environment and then lookup inside it's entry dictionary and then on entry's num_reqs_per_sec property.

see doc

@rockingcubes
Copy link
Author

A one possibility I can see would be to access the stats instance within environment and then lookup inside it's entry dictionary and then on entry's num_reqs_per_sec property.

see doc

Thank you @Sawiq. Does locust supports different endpoints with different custom load shape? For example if I have 10 endpoints and each endpoints have different custom load shape. I want all the endpoints to run simultaneously.

@cyberw
Copy link
Collaborator

cyberw commented May 8, 2024

A one possibility I can see would be to access the stats instance within environment and then lookup inside it's entry dictionary and then on entry's num_reqs_per_sec property.
see doc

Thank you @Sawiq. Does locust supports different endpoints with different custom load shape? For example if I have 10 endpoints and each endpoints have different custom load shape. I want all the endpoints to run simultaneously.

No and yes. You cant have different load shapes for different endpoints. Load shapes only control how many User instances are started and (optionally) the distribution between User types.

So you'll need to define 10 User classes and use the user_classes parameter for the shape to control when/how many users are started at each stage. https://docs.locust.io/en/latest/custom-load-shape.html#restricting-which-user-types-to-spawn-in-each-tick

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

No branches or pull requests

3 participants