Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Avoid notifying when no one is waiting on proceedLock #1657

Merged
merged 4 commits into from
Jan 10, 2017

Conversation

pankajroark
Copy link
Contributor

@pankajroark pankajroark commented Jan 7, 2017

In one of our Heron jobs we found that the spout is spending 20-30% time in just calling notify in SlaveLooper. Notify happens to be an expensive call and in this case it seems that the invocation of notify is almost always redundant since SpoutInstance calls SlaveLooper from a single thread. Optimizing that here. The cost of optimization is two extra volatile writes while waiting and one extra volatile read in wakeUp. volatile reads are pretty fast so wouldn't add much overhead to wakeUp. volatile writes are slower but waits are less common and cost of volatile writes is much lower compared to wait.

@objmagic
Copy link
Contributor

objmagic commented Jan 7, 2017

LGTM 👍 Please investigate CI failure.

@maosongfu
Copy link
Contributor

I don't understand why "they cannot occur at the same time"?

wakeUp() can be expected to be invoked in other threads rather than the one waiting.

@pankajroark
Copy link
Contributor Author

@maosongfu They are guarded by the same lock. If wait is executing then execution cannot reach notify and vice versa.

@pankajroark
Copy link
Contributor Author

@maosongfu It was my rusty understanding of how wait works. Wait actually gives up the monitor and waits for another thread to enter the same monitor and call notify. So you're right and that's why the test is failing. Let me change the implementation.

@pankajroark pankajroark changed the title Remove notify in SlaveLooper.wakeUp. It is useless and affects performance Avoid notifying when no one is waiting on proceedLock Jan 8, 2017
@pankajroark
Copy link
Contributor Author

Proposed a different way of optimizing, changed the title to reflect that.

@maosongfu
Copy link
Contributor

@pankajroark Hi Can you add more comments on it, and describe the case this pull request covers in this pr's description?

@pankajroark
Copy link
Contributor Author

@maosongfu I changed the description and added more information. Let me know if any more info is required. Thanks

@maosongfu
Copy link
Contributor

looks good to me. 👍

@kramasamy kramasamy merged commit e6976fc into apache:master Jan 10, 2017
congwang pushed a commit that referenced this pull request Jan 30, 2017
nicknezis pushed a commit that referenced this pull request Sep 14, 2020
Avoid notifying when no one is waiting on proceedLock
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants