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.

"New test" with different number of users

See original GitHub issue

It seems likes a bug to me, but please correct me if I’m wrong. It seems that after clicking on “new test” and giving lower amount of users to be created, Locust still uses some of the users created on first run.

Describe the bug

Example: When i start locust and create (total) 5 users with 5 users per sec, I get correct amount of users/requests. That is correct. Then i click Stop (in the UI). After clicking on “New test” and specifying lower amount of users(total 1 and 1 per sec), Locust still starts 4 users in total and execute tasks - but in console i can see that 1 user was spawned

Code:

import logging
import time
import uuid
from locust import task, HttpUser, SequentialTaskSet, constant_pacing, task, events
from locust.exception import StopUser

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("locust")

class UserTasks(SequentialTaskSet):
    wait_time = constant_pacing(1)

    @task
    def test_api_one(self):
        logger.info(f"Task1: {self.parent.user_id}")
        time.sleep(1)

    @task
    def test_api_two(self):
        logger.info(f"Task2: {self.parent.user_id}")
        time.sleep(1)
    
    @task
    def test_api_three(self):
        self.interrupt(False)

class WebsiteUser(HttpUser):
    host = "http://local"
    wait_time = constant_pacing(5)
    tasks = [UserTasks]

    def on_start(self):
        self.user_id = str(uuid.uuid4())
        logger.info(f"START USER: {self.user_id}")

    def on_stop(self):
        logger.info(f"STOP USER: {self.user_id}")

Expected behaviour

I would expect that if i run new test with lower number of users - from 5 to 1 users, Locust will just create 1 user and run (spawn) only that one.

You can see it on the screenshot:

Environment

  • OS: docker with python 3.9
  • Python version: 3.9
  • Locust 2.9.0
  • locust -f temp.py

Screenshot 2022-07-20 at 16 21 47

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
cyberwcommented, Aug 5, 2022

Damn, I dropped the ball here. Will pick it up some time next week if nobody else has the time. Maybe @mboutet ?

1reaction
prestonhalecommented, Aug 4, 2022

Getting the exact same behavior. Additionally, all the users from the previous test are spawned instantaneously and don’t respect the chosen “Spawn rate”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Many Test Users in a Usability Study?
If you want a single number, the answer is simple: test 5 users in a usability study. Testing with 5 people lets you...
Read more >
User testing: How many users do you need? - Maze
TLDR: the number of testers you need depends on various factors. We recommend you test with at least twenty users to uncover most...
Read more >
How to properly test for difference in number of user actions?
For the number of users in each group, I would use a chi-squared test between expected # users (total/2) and observed in each...
Read more >
How many users should you test with in user testing?
Why don't we do large numbers in usability testing? · Suggested Sample Sizes for Research · Magic Number 15 for Usability Testing...or Why...
Read more >
How many virtual users do I need for load testing? - TechBeacon
Still, considering the architecture of most websites and web apps, testing with fewer concurrent users may produce overly optimistic results. In other words, ......
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