Skip to content

PYTHON-2360 Ensure ConnectionCreatedEvents are emitted before ConnectionReadyEvents #493

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

Merged
merged 2 commits into from
Oct 6, 2020

Conversation

ShaneHarvey
Copy link
Member

@ShaneHarvey ShaneHarvey commented Sep 30, 2020

This uncovered a minor oversight in our minPoolSize connection creation logic. We did create the connection but we did not ensure that the connection was authenticated. Connections created in the background (for minPoolSize) are now authenticated. This is a minor performance improvement (lower latency on first connection use).

…ionReadyEvents

Connections created in the background (for minPoolSize) are authenticated.
Copy link
Contributor

@prashantmital prashantmital left a comment

Choose a reason for hiding this comment

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

Can you explain how this results in improved performance? It seems to me that with this change check_auth will be called twice - once in the background on socket creation and then again when the socket is checked out (i.e. in Pool._get_socket()). I'm guessing that the second call would result in a no-op but it is not clear to me how?

@ShaneHarvey
Copy link
Member Author

ShaneHarvey commented Oct 2, 2020

Can you explain how this results in improved performance?

Before this change the background thread which creates minPoolSize connections would only create the connection and run the handshake. This means that the first operation which using that connection needs to authenticate which incurs added latency.

After this change, the background thread creates the connection and authenticates it too.

I'm guessing that the second call would result in a no-op but it is not clear to me how?

Yes the second call is a no-op. Each SocketInfo caches the set of credentials which have already been authenticated. See the implementation of check_auth:

cached = set(itervalues(all_credentials))
authset = self.authset.copy()
# Logout any credentials that no longer exist in the cache.
for credentials in authset - cached:
auth.logout(credentials.source, self)
self.authset.discard(credentials)
for credentials in cached - authset:
self.authenticate(credentials)

@ShaneHarvey ShaneHarvey merged commit 337a08c into mongodb:master Oct 6, 2020
@ShaneHarvey ShaneHarvey deleted the PYTHON-2360 branch October 6, 2020 20:27
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.

2 participants