Skip to content

Conversation

Copy link

Copilot AI commented Dec 15, 2025

  • Understand the issue and explore the codebase
  • Reduce lock scope in ConnectionPool.get_connection()
  • Add test for lock not held during connection establishment
  • Add test for concurrent connection acquisition performance
  • Fix linter formatting errors in test file
Original prompt

This section details on the original issue you should resolve

<issue_title>Async performance issue since version 5.3.0</issue_title>
<issue_description>The unannounced introduction of asyncio.Lock when acquiring a connection from the pool in #3445 is causing noticeable performance degradation:

async def get_connection(self, command_name=None, *keys, **options):
async with self._lock:
"""Get a connected connection from the pool"""
connection = self.get_available_connection()
try:
await self.ensure_connection(connection)
except BaseException:
await self.release(connection)
raise
return connection

This becomes especially evident under high load, where lock contention becomes a bottleneck. The issue affects version 5.3.0 and later. Others have also reported performance impacts, as noted in #3624.

I kind of understand the rationale behind this change, but personally, I would acquire the lock only to pop a connection and then performs ensure_connection outside the lock. Alternatively, if it didn’t appear to cause issues in earlier versions, may be no lock at all?</issue_description>

<agent_instructions>Fix the lock range - it should not include the call to establishing a socket connection and handshake execution. Add proper unit tests.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@petyaslavova Hi @d33kayyy, thanks for bringing this to our attention. We will take a look at it soon.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 15, 2025 15:18
Move ensure_connection() outside the lock in ConnectionPool.get_connection() to prevent lock contention during socket connection and TLS handshake operations. This matches the pattern already used in BlockingConnectionPool and significantly improves performance under high load.

Co-authored-by: petyaslavova <[email protected]>
- Simplify lock checking test by using outer scope instead of passing pool reference
- Make performance test more maintainable with configurable timeouts and better error messages

Co-authored-by: petyaslavova <[email protected]>
Copilot AI changed the title [WIP] Fix async performance issue caused by asyncio.Lock Fix async connection pool lock contention during connection establishment Dec 15, 2025
Copilot AI requested a review from petyaslavova December 15, 2025 15:25
@petyaslavova petyaslavova marked this pull request as ready for review December 15, 2025 15:49
@petyaslavova
Copy link
Collaborator

@copilot fix linter errors

Copy link
Author

Copilot AI commented Dec 15, 2025

@copilot fix linter errors

Fixed in commit 7104055. The issue was a formatting preference for assert statements - ruff wanted the error message on the same line as the condition when it can fit.

Copy link
Collaborator

@petyaslavova petyaslavova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@petyaslavova petyaslavova removed their assignment Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async performance issue since version 5.3.0

2 participants