-
Notifications
You must be signed in to change notification settings - Fork 2.6k
BlockingConnectionPool simplification: use counter instead of connection list #2518
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
Conversation
Codecov ReportBase: 92.28% // Head: 92.27% // Decreases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #2518 +/- ##
==========================================
- Coverage 92.28% 92.27% -0.01%
==========================================
Files 115 115
Lines 29660 29660
==========================================
- Hits 27371 27369 -2
- Misses 2289 2291 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@@ -1646,7 +1652,10 @@ async def disconnect(self, inuse_connections: bool = True): | |||
self._checkpid() | |||
async with self._lock: | |||
resp = await asyncio.gather( | |||
*(connection.disconnect() for connection in self._connections), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This disconnects only those connections in the pool, not all connections as before.
def __init__( | ||
self, | ||
max_connections: int = 50, | ||
timeout: Optional[int] = 20, | ||
connection_class: Type[Connection] = Connection, | ||
queue_class: Type[asyncio.Queue] = asyncio.LifoQueue, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LifoQueue ensures that hot connections are the ones re-used first, which is probably beneficial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no difference in my simple tests, maybe i did something wrong but Lifo had 0 impact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I´m not sure there will be a difference, or that this was the original intent of the LifoQueue. But LIFO is often used in caching, to maintain hot information. There is a degenerate case which can happen with Fifo, which is that if you pull always the oldest connections, you may end up with all the connections having timed out, or been disconnected due to idleness or other such things. But maybe that doesn't matter at all. Maybe the only intention of the LifoQueue was to keep those None
objects at the end.
I added |
|
Btw, this is probably obsoleted with the merging of #2911 |
It is |
Pull Request check-list
Please make sure to review and check all of these items:
$ tox
pass with this change (including linting)?I do not have docker on my machine and i couldn't find a way to make it work with podman. I hope repo CI can run test and catch bugs.
There are a lot of linting errors/warnings about docstring formatting in cluster.py file which I haven't touched.
Action doesn't start for my branch. I assume it only works for PRs
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Description of change
Existing code juggling full queue of
None
s and using extra list to store connections looked weird so I simplified it to use a simple counter to track how many connections were allocated.Also added slots to pools.
I tested my change with the following code using different
max_connections
values:It also performs a few % better than existing solution, probably because of slots.