mgr/vol: some improvements for async_job.py#60002
mgr/vol: some improvements for async_job.py#60002rishabh-d-dave wants to merge 2 commits intoceph:mainfrom
Conversation
The attribute self.stopping of class AsyncJob is an instance of threading.Event that is only used to set and check if it is set. For such a case, threading.Event is an overkill, using a boolean variable instead would suffice perfectly. Signed-off-by: Rishabh Dave <ridave@redhat.com>
Signed-off-by: Rishabh Dave <ridave@redhat.com>
|
jenkins test api |
|
jenkins test windows |
|
jenkins test make check arm64 |
|
jenkins test api |
|
jenkins test windows |
1 similar comment
|
jenkins test windows |
|
jenkins test make check arm64 |
|
This PR is under test in https://tracker.ceph.com/issues/68354. |
batrick
left a comment
There was a problem hiding this comment.
The attribute self.stopping of class AsyncJob is an instance of
threading.Event that is only used to set and check if it is set. For
such a case, threading.Event is an overkill, using a boolean variable
instead would suffice perfectly.
huh? Why is it overkill?
Events are used for thread synchronization. And since we aren't doing anything even remotely close there's no reason to use Event. A boolean variable exactly the job. |
Except |
Right. But we don't use any features that class Event provides (like |
Yes, you do. Simply notifying on a condition variable will create a memory barrier. That is essential so that |
I really would not bother micro-optimizing this code. |
@vshankar |
rishabh-d-dave
left a comment
There was a problem hiding this comment.
QA run was successful - https://tracker.ceph.com/projects/cephfs/wiki/Main#2024-Oct-18
The point to note here is that event uses its own internal lock. Switching to boolean for this specific case is fine since it's a validation check for the |
|
|
||
| def shutdown(self): | ||
| self.stopping.set() | ||
| self.stopping = True |
There was a problem hiding this comment.
This is called by module shutdown (which is not even used anymore) but, despite that, the shutdown method would be called from a separate thread. (I mean, that's the entire point of a stopping flag. Why would you need it if it's only set by the thread itself?)
It's entirely conventional for a stopping flag on a thread to be a threading.Event. I really don't understand the motivation to change this.
There was a problem hiding this comment.
It's entirely conventional for a stopping flag on a thread to be a threading.Event.
It is conventional to have lock on a boolean value when multiple threads will attempt to modify the boolean value. But since there's only one thread in this case, a boolean value without a lock is equally fine and therefore usage of threading.Event is unnecessary.
There was a problem hiding this comment.
Sorry, no. Anyone coming in the future that wants to stop threads now must play roulette with the cache lines hoping that the shutdown method actually does what you would think in a properly multi-threaded class.
I urge you to consider this to be defensive programming and let the matter rest. There is no real performance gain to squeeze from this.
There was a problem hiding this comment.
I urge you to consider this to be defensive programming
Defensive programming from the POV of possible future attempt to extend use of self.stopping is a good point.
There is no real performance gain to squeeze from this.
Performance was never the main concern for this PR.
|
What has come up through discussions is that it's fine to merge this patch since in this particular case it would have no negative effect. But in order to prevent accidental introduction of bugs in future, we would like to take the defensive approach and not merge this patch. Closing this PR. |
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume toxjenkins test windowsjenkins test rook e2e