Skip to content

Support sharing connection pools between users#2059

Merged
cyberw merged 4 commits into
locustio:masterfrom
miedzinski:shared-pools
Mar 28, 2022
Merged

Support sharing connection pools between users#2059
cyberw merged 4 commits into
locustio:masterfrom
miedzinski:shared-pools

Conversation

@miedzinski
Copy link
Copy Markdown
Contributor

This PR adds support for sharing connection pools between users. It is done by exposing lower level pool (urllib3.PoolManager for HttpUser, geventhttpclient.client.HTTPClientPool for FastHttpUser).

Example usage:

from geventhttpclient.client import HTTPClientPool
from locust import FastHttpUser, HttpUser
from urllib3 import PoolManager


# Both users will be limited to 10 concurrent connections at most.

class UserA(HttpUser):
    pool_manager = PoolManager(maxsize=10, block=True)


class UserB(FastHttpUser):
    client_pool = HTTPClientPool(concurrency=10)

Fixes #1925.

@cyberw
Copy link
Copy Markdown
Collaborator

cyberw commented Mar 27, 2022

Cool stuff. A few test cases would be nice, ideally one that actually verifies somehow that connections are really pooled. And we’d need to add it to the docs somewhere.

@miedzinski
Copy link
Copy Markdown
Contributor Author

@cyberw PTAL.

I have no idea why mypy reported that error, because I didn't touch HttpSession.request_name, but adding a type hint fixed it.

@miedzinski
Copy link
Copy Markdown
Contributor Author

Now black is failing due to psf/black#2964.

@cyberw cyberw merged commit 6ca2724 into locustio:master Mar 28, 2022
@cyberw
Copy link
Copy Markdown
Collaborator

cyberw commented Mar 28, 2022

Thx! I think merging will get us the fix needed for >3.6 builds.

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

Successfully merging this pull request may close these issues.

Make each virtual user to share same connections

2 participants