Skip to content

Commit

Permalink
FastHttpUser: Bump default max concurrency to 10, inspired by discuss…
Browse files Browse the repository at this point in the history
…ion in #1810 Add a test (which also serves as an example for how to use it)
  • Loading branch information
cyberw committed Aug 29, 2022
1 parent 09c9f65 commit 4c899b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ class by using the :py:func:`@task decorator <locust.task>` on the methods, or b
insecure: bool = True
"""Parameter passed to FastHttpSession. Default True, meaning no SSL verification."""

concurrency: int = 1
"""Parameter passed to FastHttpSession. Describes number of concurrent requests allowed by the FastHttpSession. Default 1.
Note that setting this value has no effect when custom client_pool was given."""
concurrency: int = 10
"""Parameter passed to FastHttpSession. Describes number of concurrent requests allowed by the FastHttpSession. Default 10.
Note that setting this value has no effect when custom client_pool was given, and you need to spawn a your own gevent pool
to use it (as Users only have one greenlet). See test_fasthttp.py / test_client_pool_concurrency for an example."""

client_pool: Optional[HTTPClientPool] = None
"""HTTP client pool to use. If not given, a new pool is created per single user."""
Expand Down
23 changes: 23 additions & 0 deletions locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,29 @@ class MyUser(FastHttpUser):
self.assertEqual(2, self.connections_count)
self.assertEqual(4, self.requests_count)

def test_client_pool_concurrency(self):
class MyUser(FastHttpUser):
host = "http://127.0.0.1:%i" % self.port

@task
def t(self):
def concurrent_request(url):
response = self.client.get(url)
assert response.status_code == 200

pool = gevent.pool.Pool(20)
urls = ["/slow?delay=0.2"] * 20 # these urls are all the same, but they could be different
for url in urls:
pool.spawn(concurrent_request, url)
pool.join()

user = MyUser(self.environment)
before_requests = time.time()
user.t()
after_requests = time.time()
expected_delta = 0.4 # 20 requests with concurrency 10 and response time 0.2
self.assertAlmostEqual(before_requests + expected_delta, after_requests, delta=0.1)


class TestFastHttpCatchResponse(WebserverTestCase):
def setUp(self):
Expand Down

0 comments on commit 4c899b9

Please sign in to comment.