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

Multi-threading Tasks? #985

Closed
argentlynx opened this issue Mar 21, 2019 · 6 comments
Closed

Multi-threading Tasks? #985

argentlynx opened this issue Mar 21, 2019 · 6 comments

Comments

@argentlynx
Copy link

argentlynx commented Mar 21, 2019

Locust seems to be waiting for requests to finish before spawning a new task.

Expecting that I can hit something like 600r/min using 20 parallel users and 100ms min and max wait time (I know it should be higher than 600 with this setting but, I'm hoping for something like 600)

On a high-latency (but high throughput) connection I max out at 50r/min even with a min and max wait time of 100ms and 20 parallel users.

Following Issue 198 #198 I was able to dramatically increase my requests per minute so I think that before I used multithreading, locust was basically waiting for each request to finish before running a new task. Which is awesome!

However, is there some way to do this in the Locust class instead of within the Task itself?

Right now my task is something like:

@task

def something(self):

from gevent.pool import Group

group = Group()

group.spawn

group.spawn

group.spawn

etc

but it seems like it would be more natural to have this somewhere else, so that each task is a thread, instead of each line within a task. Is there a way to do this in Locust?

class MyLocust(HttpLocust):

task_set = MyTaskSet

min_wait = 100

max_wait = 1000

parallel_tasks = true #something like this?

@aldenpeterson-wf
Copy link
Contributor

Why do you want to do this in each Locust instead of having more Locusts?

Locust's concurrency is almost always increased by the number of Locusts (aka users) - not parallelization of each individual task within a Locust.

Locust seems to be waiting for requests to finish before spawning a new task.

This is by design. Locust is designed to simulate users, who perform various task sets - which reflect actual user activity (I suppose some users may open up 10 tabs and actively work in all 10 simultaneously, this seems very rare though).

@argentlynx
Copy link
Author

argentlynx commented Mar 24, 2019

I am testing a single-page app that works a little like a spreadsheet, so the user can send multiple requests before receiving a reply. Thanks though, I will investigate parallel users instead, or continue using the solution from 198

@kevalRPansuriya
Copy link

kevalRPansuriya commented May 29, 2020

I agree @argentlynx I am having the same problem I have two tasks and want to execute one every 2 seconds and two every 30 seconds but locust seems to wait to finish the task and that's why my 30-second task is not running on the exact time.

@guilhermemaiaribeiro
Copy link

does anyone have a solution for this?

@kevalRPansuriya
Copy link

hi, @racooninho in my case I want two-run task one at every 1 second and two at every 30 seconds so I created a timer which is running every 30 seconds and one locust task every 1 second.

@kevalRPansuriya
Copy link

@racooninho create a timer in on_start method refer code to create timer

import threading
def gfg():
print("GeeksforGeeks\n")

timer = threading.Timer(2.0, gfg)
timer.start()
print("Exit\n")

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

No branches or pull requests

4 participants