-
Notifications
You must be signed in to change notification settings - Fork 232
async_ssh: Use async semaphore instead of manual locking #7018
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7018 +/- ##
==========================================
- Coverage 77.61% 77.60% -0.00%
==========================================
Files 566 566
Lines 43501 43491 -10
==========================================
- Hits 33758 33746 -12
- Misses 9743 9745 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
af1042c to
f9a3503
Compare
| async with self._semaphore: | ||
| try: | ||
| await self.async_backend.put( | ||
| localpath=localpath, | ||
| remotepath=remotepath, | ||
| dereference=dereference, | ||
| preserve=preserve, | ||
| recursive=False, | ||
| ) | ||
| except OSError as exc: | ||
| raise OSError(f'Error while uploading file {localpath}: {exc}') |
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.
Just look at the code, the equivalent change should be put async with _semaphore inside the try block right before the put().
But I think it is a correct change.
pinning @khsrali for review since you implement it.
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.
Okay, I overlooked what @danielhollas already wrote: "nd fixes a bug since the number of file IO connections was not decreased when an OsError exception was thrown.".
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.
Changes looks all good to me.
Out of curiosity, is a transport object tight (its lifetime) with a calcjob or it is tight with a worker?
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.
LGTM
|
@unkcpz @khsrali thank you for the review! @khsrali do you think you could benchmark this PR in the same way you benchmarked the original async_ssh implemetation to see if this fixes the regression you saw for small files? I am planning to write a regression test here to make sure we're releasing the resources in case of exceptions. |
|
@danielhollas, is there a particular reason you're holding off on merging this? If you're waiting for me to benchmark, unfortunately, I'm not getting any time to unearth the old tests and do it again. In any case, you can always run your tests after merging, hooking the commit number. |
f9a3503 to
45deedd
Compare
|
Thanks for the ping, I plan to merge this today, but want to write a test first that is failing in main due to the lock release issue that this PR is fixing. I still want to do the benchmarking as well, but agree that can be done after merge |
This should improve performance of async_ssh plugin for lots of small files since we're no longer sleeping 500ms when waiting for a lock.
https://docs.python.org/3/library/asyncio-sync.html#asyncio.Semaphore
Also makes the code more safe since one doesn't need to manually lock and unlock, and fixes a bug since the number of file IO connections was not decreased when an OsError exception was thrown.