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

On Stop causes the task to continue #1552

Closed
masonCaminer opened this issue Sep 7, 2020 · 15 comments · Fixed by #1560
Closed

On Stop causes the task to continue #1552

masonCaminer opened this issue Sep 7, 2020 · 15 comments · Fixed by #1560
Labels

Comments

@masonCaminer
Copy link

Describe the bug

If I add a new table concurrently, I click Stop, and then my on_stop method will be executed. On_stop is deleting the table. At this moment, one user will start executing on_stop and the other user will continue to execute task

Expected behavior

Task is no longer executed when on_stop is expected

Actual behavior

The Task is still executed

Steps to reproduce

  1. Task is a new table
  2. On_stop removes the table one by one

Environment

  • OS:
  • Python version: 3.8
  • Locust version: 1.2.3
  • Locust command line that you ran: locust -f src/loadTest/11_add_core.py --users=20 --spawn-rate=20
  • Locust file contents (anonymized if necessary):
@cyberw
Copy link
Collaborator

cyberw commented Sep 7, 2020

can you add your locust file?

@cyberw
Copy link
Collaborator

cyberw commented Sep 11, 2020

@masonCaminer I'm super interested in debugging this, as I've had similar issues in the past, but right now I'm unable to reproduce. Can you post your locust file? Also, what "tables" are you talking about?

@masonCaminer
Copy link
Author

This is our project. I can't provide you with the process of pressure testing. What I can provide you is the process and script

@masonCaminer
Copy link
Author

USER_CREDENTIALS = PerformanceTest.get_users()
PerformanceTest.init_locust_env()
setup_logging(loglevel="INFO")


class QuickstartUser(FastHttpUser):
    wait_time = between(1, 1)
    host = os.getenv('host')

    def on_start(self):
        if len(USER_CREDENTIALS) > 0:
            name, password = USER_CREDENTIALS.pop()
            self.login = Treelab.login(email=name, password=password)
            self.workspace = Treelab.get_workspaces(token=self.login.token)[0]
            self.core = self.workspace.add_core(core_name=random_str(), is_assert=False)

    @task
    def add_table(self):
        self.core.add_table(table_name=str(uuid.uuid4()), is_assert=False, locust=self)

    def on_stop(self):
        self.workspace.remove_core(core_id=self.core.id, is_assert=False, locust=self)


@events.init.add_listener
def on_locust_init(environment, **_kwargs):
    TimescaleListener(env=environment, testplan="9_add_table.py", target_env="myTestEnv")


if __name__ == "__main__":
    run_single_user(QuickstartUser, include_time=True, include_length=True, init_listener=on_locust_init)

@cyberw
Copy link
Collaborator

cyberw commented Sep 14, 2020

What do the Treelab methods call in the end? Is it http calls? If not, you need to make sure they are gevent-friendly, otherwise it will not work

@cyberw
Copy link
Collaborator

cyberw commented Sep 14, 2020

I had no issues running the following code. There might still be an issue in locust (as I think I've seen it sometimes) but maybe you have run into something that is more related to your particular setup..

...

class DemoUser(FastHttpUser):
    host = f"http://google.com/"
    wait_time = between(1, 1)

    def on_start(self):
        self.client.get("/?0")

    @task
    def t(self):
        with self.client.get("/?1") as resp:
            pass

    def on_stop(self):
        self.client.get("/?2")


@events.init.add_listener
def on_locust_init(*, environment, **_kwargs):
    listeners.TimescaleListener(testplan="demo", target_env=env, env=environment)

@masonCaminer
Copy link
Author

I use the same principle as you, both functions in fasthttp.py

@masonCaminer
Copy link
Author

@masonCaminer
Copy link
Author

The username and password are all test

@masonCaminer
Copy link
Author

locust -f src/loadTest/11_add_core.py --users=5 --spawn-rate=5 --headless --run-time 20s

@masonCaminer
Copy link
Author

I only run 20 seconds, but after 20 seconds it keeps going

@masonCaminer
Copy link
Author

USER_CREDENTIALS = PerformanceTest.get_users()
PerformanceTest.init_locust_env()
setup_logging(loglevel="INFO")


class QuickstartUser(FastHttpUser):
    wait_time = between(1, 1)
    host = os.getenv('host')

    def on_start(self):
        if len(USER_CREDENTIALS) > 0:
            name, password = USER_CREDENTIALS.pop()
            self.login = Treelab.login(email=name, password=password)
            try:
                self.workspace = Treelab.get_workspaces(token=self.login.token)[0]
            except:
                self.workspace = Treelab.add_workspace('压测', token=self.login.token)

    @task
    def add_core(self):
        self.core = self.workspace.add_core(str(random.randint(1, 100)), locust=self)

    def on_stop(self):
        self.workspace.remove_cores()


@events.init.add_listener
def on_locust_init(environment, **_kwargs):
    TimescaleListener(env=environment, testplan="11_add_core", target_env="myTestEnv")

@masonCaminer
Copy link
Author

You can see grafana and you can see two problems.The first is on_ start time is also included in the total time. The second problem is the above

@masonCaminer
Copy link
Author

I'm in Slack @you

@cyberw
Copy link
Collaborator

cyberw commented Sep 14, 2020

I have replied now. But you really must try to reproduce this without using your custom client, otherwise I cannot help.

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

Successfully merging a pull request may close this issue.

2 participants