Repository navigation
Wait for daemon incr/decr asynchronously - #166
Conversation
|
@khsrali can I get your eyes on this? 🙏 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #166 +/- ##
=======================================
Coverage 89.05% 89.06%
=======================================
Files 49 49
Lines 2029 2030 +1
=======================================
+ Hits 1807 1808 +1
Misses 222 222
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| @@ -156,7 +157,7 @@ async def increase_daemon_worker() -> DaemonStatus: | |||
|
|
|||
| initial = client.get_numprocesses()['numprocesses'] | |||
There was a problem hiding this comment.
| initial = client.get_numprocesses()['numprocesses'] |
| initial = client.get_numprocesses()['numprocesses'] | ||
| client.increase_workers(1) | ||
| num_workers = _wait_for_num_workers(initial + 1) | ||
| num_workers = await _wait_for_num_workers(initial + 1) |
There was a problem hiding this comment.
| num_workers = await _wait_for_num_workers(initial + 1) | |
| num_workers = client.get_numprocesses()['numprocesses'] |
Bud-Macaulay
left a comment
There was a problem hiding this comment.
Hi Edan, could you try avoiding using this wait_for_number... altogether.
Looking at the daemon client I can't see a reason why this wouldn't work?
Then we can drop this wait_for... etc.
Reducing the logic of and pinging it consistently gives the correct (future) number of workers. However... doing this for decrease interestingly consistently gives the wrong (past) number of workers 🤔 Note that with the implementation done in this PR, I get correct counts for both ops. |
|
Hmm interesting, looks like a bug or a race condition in teh daemon-manager/circus somewhere. I guess we can keep the repoll timeout for now but would be great to revisit this when we have a new daemon. Merge with whatever changes you see fit. |
Yeah, that's racing is expected, welcome to async battles😆. Perhaps because you already had send in increase request before and you are "awaiting it" elsewhere and at the same time are sending asynchronous request to decrease it. All messages gets acknowledged by circus but the number that each function call is expecting is not gonna what they've expected because it's changed by the other one. Note this is entirely unrelated to circus being sync or async. Even if we were using async interface of circus this 100% would happen again. The solution is to use asyncio.lock, or even better limit the number of your RESTapi calls on daemon with semaphore to 1 and exactly 1. So as you see in the end, even an asynchronous DaemonClient if we would have implement is not gonna be as glamorous as it sounds. |
Instead of repolling I suggest the solution of aiidateam/aiida-core#7500 (comment) |
cf7d1fd to
8f66382
Compare
In my testing, I was getting the wrong count from a decrease op starting fresh, so no previous calls.
Can you explain why in more detail?
I've heard you say "semaphore" a few times now. I'm afraid I don't know what this is 🥲 |
This PR implements your suggestion from that issue. Unless you mean the recent comment you made to elevate it to aiida-core via |
yes, the links goes to the latest suggestion, |
I would be in favor of this. Just to move things along, I'm going to merge this one as is. Ping me on #159 once you guys have it implemented in aiida-core 🙏 |
Closes #162