locustio / locust

Write scalable load tests in plain Python 🚗💨
https://locust.cloud
MIT License
24.97k stars 2.98k forks source link

Multi-threading Tasks? #985

Closed argentlynx closed 5 years ago

argentlynx commented 5 years ago

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 https://github.com/locustio/locust/issues/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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

does anyone have a solution for this?

kevalRPansuriya commented 4 years ago

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 commented 4 years ago

@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")