Skip to content
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

PYTHON-4482 Make _ServerSessionPool lock-free and still thread safe #1660

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

ShaneHarvey
Copy link
Member

@ShaneHarvey ShaneHarvey commented Jun 6, 2024

https://jira.mongodb.org/browse/PYTHON-4482

Still todo:

  • Benchmark shows a notable improvement for both single threaded and multi-threaded:
(pymongo-py39) ➜  mongo-python-driver git:(PYTHON-4482) python bench-command.py 1  
Python: 3.9.13, PyMongo: 4.8.0.dev0, MongoDB: 5.0.15
Running 10000 operations across 1 thread(s)
command: 1.32s
find_one: 1.93s
insert_one: 1.84s
(pymongo-py39) ➜  mongo-python-driver git:(PYTHON-4482) python bench-command.py 100
Python: 3.9.13, PyMongo: 4.8.0.dev0, MongoDB: 5.0.15
Running 10000 operations across 100 thread(s)
command: 1.22s
find_one: 1.52s
insert_one: 1.35s

VS master:

(pymongo-py39) ➜  mongo-python-driver git:(master) python bench-command.py 1
Python: 3.9.13, PyMongo: 4.8.0.dev0, MongoDB: 5.0.15
Running 10000 operations across 1 thread(s)
command: 1.36s
find_one: 1.95s
insert_one: 1.90s
(pymongo-py39) ➜  mongo-python-driver git:(master) python bench-command.py 100
Python: 3.9.13, PyMongo: 4.8.0.dev0, MongoDB: 5.0.15
Running 10000 operations across 100 thread(s)
command: 1.64s
find_one: 1.67s
insert_one: 1.49s

Copy link
Contributor

@Jibola Jibola left a comment

Choose a reason for hiding this comment

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

LGTM

if not s.timed_out(session_timeout_minutes):
return s

return _ServerSession(self.generation)

def return_server_session(
self, server_session: _ServerSession, session_timeout_minutes: Optional[int]
Copy link
Contributor

Choose a reason for hiding this comment

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

why was session_timeout_minutes removed here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because session_timeout_minutes was only used to clear stale sessions and it seems redundant to do that on both get_session and return_session. It's good enough to clear stale sessions only when getting a session from the pool.

@ShaneHarvey ShaneHarvey merged commit 8c35d1e into mongodb:master Jun 11, 2024
32 of 35 checks passed
@ShaneHarvey ShaneHarvey changed the title PYTHON-4347 Make _ServerSessionPool lock-free and still thread safe PYTHON-4482 Make _ServerSessionPool lock-free and still thread safe Jun 11, 2024
@ShaneHarvey ShaneHarvey deleted the PYTHON-4482 branch June 11, 2024 20:43
ShaneHarvey added a commit to ShaneHarvey/mongo-python-driver that referenced this pull request Jun 11, 2024
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.

3 participants