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

More precise spinning with back off idle strategy #291

Closed
wants to merge 2 commits into from

Conversation

plokhotnyuk
Copy link
Contributor

@plokhotnyuk plokhotnyuk commented May 14, 2024

  • allows usage with zero for maxSpins and maxYields properties without redundant ThreadHints.onSpinWait() and Thread.yield() calls
  • fixes missing call of ThreadHints.onSpinWait() for 1st idle() call
  • fixes redundant empty spin without Thread.yield() after switching to PARKING state

@plokhotnyuk plokhotnyuk changed the title More precise spinning with back off strategy More precise spinning with back off idle strategy May 14, 2024
@plokhotnyuk
Copy link
Contributor Author

@mikeb01 @wojciech-adaptive @vyazelenko Could you please review and merge this PR with squashed commits?

@vyazelenko
Copy link
Contributor

@plokhotnyuk What is the motivation for this change? Have you considered writing a custom idle strategy instead?

@plokhotnyuk
Copy link
Contributor Author

plokhotnyuk commented Jun 5, 2024

@plokhotnyuk What is the motivation for this change? Have you considered writing a custom idle strategy instead?

The motivation is simple: it makes the strategy easier to configure, saves CPU cycles by avoiding redundant loops and reducing contention with other threads that allows to reduce latency and increase total system throughput.

Yes, I'm using the proposed version in our classpath but it could be beneficial for all users. Especially it matters a lot for cases when there are dozens of services with several agents that have different latency requirements.

@vyazelenko
Copy link
Contributor

/cc @mjpt777 @mikeb01

@mikeb01
Copy link
Contributor

mikeb01 commented Jun 6, 2024

The intention of the back off idle strategy is that it will always going through a back off process regardless of the configuration, hence the reason that it will always do at least one spin and one yield before parking. We want to retain that behaviour.

Given that IdleStrategy is an interface, you can copy the existing strategy and build a new idle strategy that has the behaviour you desire. If you wanted to submit that new IdleStrategy implementation as a PR, we would consider merging that.

@mikeb01 mikeb01 closed this Jun 6, 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.

None yet

3 participants