-
Notifications
You must be signed in to change notification settings - Fork 3k
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
FastHttpUser requests are blocking #1810
Comments
If instead you do: group = Group()
group.add(gevent.spawn_later(0, self.client.get, "/example_url_1"))
group.add(gevent.spawn_later(0, self.client.get, "/example_url_2"))
group.add(gevent.spawn_later(0, self.client.get, "/example_url_3"))
group.join() Or: greenlets = [
gevent.spawn(self.client.get, "/example_url_1"),
gevent.spawn(self.client.get, "/example_url_2"),
gevent.spawn(self.client.get, "/example_url_3"),
]
gevent.joinall(greenlets) Does it work? |
If you make a PR with that change we can merge it, no problem. |
Made a pull request: #1812 |
Quick question, how do we set the concurrency then? This is quite a major feature that is not documented in the Locust.IO docs |
class MyUser(FastHttpUser):
concurrency = 5 This is only necessary if you want to make concurrent requests within a single simulated user with custom spawned greenlets. With that said, I think it would make sense to increase the default |
Thanks, got it working nonetheless. Had to set it to 15 for the 15 concurrent endpoints we load during app launch |
…ion in #1810 Add a test (which also serves as an example for how to use it)
Describe the bug
I'd like to simulate concurrent requests, much like a real javascript client would do. This can be done by spawning multiple greenlets within a task, and resolving them cooperatively. This approach is also suggested in this issue report. This works just fine with HttpUser, but FastHttpUser requests are blocking, which means that the requests spawned are handled sequentially instead of cooperatively.
This also affects the request times of requests performed. For example, in the sample code below, the result time of request to /example_url_3 is the sum of all requests performed, request time to url /example_url_2 is the sum of request times to /example_url_1 and /example_url_2, and so on. This is the most unfortunate part of the issue.
geventhttpclient already supports concurrency, but this is 1 by default. The gevent UserAgent can be passed a concurrency kwarg, as explained here, but this is ignored in locust. I forked locust and made this commit that allows adjusting concurrency within a locust user class that extends FastHttpUser. From my perspective, setting the concurrency to some number above 1 solves the issue. In the code sample below, concurrency=3 would be enough.
Expected behavior
Requests should be executed cooperatively.
Actual behavior
Requests are blocking instead of cooperatively.
Steps to reproduce
Environment
The text was updated successfully, but these errors were encountered: