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

Use workaround to fix high CPU usage by LinkedTransferQueue #3756

Merged
merged 1 commit into from
Aug 14, 2023

Conversation

wborn
Copy link
Member

@wborn wborn commented Aug 13, 2023

This is a workaround for JDK-8301341 by using the Java 11 LinkedTransferQueue with the QueueingThreadPoolExecutor in the Core and jUPnP.


Using the Java 11 LinkedTransferQueue is probably the most stable option because it did not cause these issues with OH3.

To be able to use the same artifact with jUPnP, jUPnP also needs to be build with Java 11 or newer (it's currently still compatible with Java 8).

I put the Java 11 LinkedTransferQueue in a separate repo because it has a GPLv2+CE license.
Perhaps the repo can also be moved to the openHAB organization?
Because Java and OpenJDK are trademarks, it is probably best to avoid these in repo and package names etc.

Let me know if you agree with the proposed artifact GAV parameters.
After that I can build the artifacts and they can be added to Artifactory.

Closes #3755

This is a workaround for JDK-8301341 by using the Java 11 LinkedTransferQueue with the QueueingThreadPoolExecutor in the Core and jUPnP.

Signed-off-by: Wouter Born <[email protected]>
@wborn wborn added the bug An unexpected problem or unintended behavior of the Core label Aug 13, 2023
@wborn wborn requested a review from a team as a code owner August 13, 2023 19:09
@kaikreuzer
Copy link
Member

Perhaps the repo can also be moved to the openHAB organization?

If you grant me owner rights on your repo, I can transfer it to the openHAB org.

@wborn
Copy link
Member Author

wborn commented Aug 13, 2023

I can only add collaborators so I asked to transfer it to you so you can transfer it to openHAB and give me back permissions. 🙂

@kaikreuzer
Copy link
Member

Done: https://github.com/openhab/openhab-base-fixes
I have granted access to @openhab/core-maintainers and @openhab/distro-maintainers.

@wborn
Copy link
Member Author

wborn commented Aug 13, 2023

Great! Are the GAV parameters OK? If so, I can update the POM for the repo change and add a GitHub release.

@kaikreuzer
Copy link
Member

Are the GAV parameters OK?

Fine with me.

@wborn
Copy link
Member Author

wborn commented Aug 13, 2023

I've build the artifacts and added them to these releases:

So if you can upload those we can see if the build succeeds.

@kaikreuzer kaikreuzer added rebuild Triggers the Jenkins PR build and removed rebuild Triggers the Jenkins PR build labels Aug 13, 2023
@kaikreuzer
Copy link
Member

Thanks, I have uploaded both to Artifactory.

wborn added a commit to wborn/openhab-addons that referenced this pull request Aug 13, 2023
wborn added a commit to wborn/openhab-distro that referenced this pull request Aug 13, 2023
@wborn
Copy link
Member Author

wborn commented Aug 13, 2023

It seems to build pretty well except for #3257 acting up again.

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@kaikreuzer kaikreuzer merged commit aef57ed into openhab:main Aug 14, 2023
2 checks passed
@kaikreuzer kaikreuzer added this to the 4.1 milestone Aug 14, 2023
kaikreuzer pushed a commit to openhab/openhab-addons that referenced this pull request Aug 14, 2023
* Resolve runbundles for workaround

Related to openhab/openhab-core#3756

Signed-off-by: Wouter Born <[email protected]>
@wborn wborn deleted the base-fixes branch August 14, 2023 08:38
kaikreuzer pushed a commit to openhab/openhab-distro that referenced this pull request Aug 14, 2023
wborn added a commit that referenced this pull request Aug 14, 2023
This is a workaround for JDK-8301341 by using the Java 11 LinkedTransferQueue with the QueueingThreadPoolExecutor in the Core and jUPnP.

Signed-off-by: Wouter Born <[email protected]>
@wborn wborn added the patch A PR that has been cherry-picked to a patch release branch label Aug 14, 2023
wborn added a commit to openhab/openhab-addons that referenced this pull request Aug 14, 2023
* Resolve runbundles for workaround

Related to openhab/openhab-core#3756

Signed-off-by: Wouter Born <[email protected]>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-4-1-milestone-discussion/149502/32

austvik pushed a commit to austvik/openhab-addons that referenced this pull request Mar 27, 2024
* Resolve runbundles for workaround

Related to openhab/openhab-core#3756

Signed-off-by: Wouter Born <[email protected]>
Signed-off-by: Jørgen Austvik <[email protected]>
minwoox added a commit to minwoox/centraldogma that referenced this pull request Apr 22, 2024
…Executor

Motivation:
The use of `LinkedTransferQueue` in JDK 17 has a bug causing a thread to consume all of a CPU's usage: https://bugs.openjdk.org/browse/JDK-8301341.
Although this bug has been fixed, the patch has not been backported to JDK 17.
Since copying the code from JDK 11 poses licensing issues (openhab/openhab-core#3756), we need a different solution.

Switching to `LinkedBlockingQueue` offers a feasible workaround.
While `LinkedTransferQueue` is typically efficient under high multi-thread contention due to its use of CAS,
our current usage does not exhibit significant contention as the queue tasks' size remains close to 0.

Modifications:
- Replaced the use of `LinkedTransferQueue` with `LinkedBlockingQueue` in `ThreadPoolExecutor`.

Result:
- You no longer see an excessive CPU usage by a single thread.
minwoox added a commit to line/centraldogma that referenced this pull request Apr 23, 2024
…Executor (#946)

Motivation:
The use of `LinkedTransferQueue` in JDK 17 has a bug causing a thread to consume all of a CPU's usage: https://bugs.openjdk.org/browse/JDK-8301341. Although this bug has been fixed, the patch has not been backported to JDK 17. Since copying the code from JDK 11 poses licensing issues (openhab/openhab-core#3756), we need a different solution.

Switching to `LinkedBlockingQueue` offers a feasible workaround. While `LinkedTransferQueue` is typically efficient under high multi-thread contention due to its use of CAS, our current usage does not exhibit significant contention as the queue tasks' size remains close to 0.

Modifications:
- Replaced the use of `LinkedTransferQueue` with `LinkedBlockingQueue` in `ThreadPoolExecutor`.

Result:
- You no longer see an excessive CPU usage by a single thread.
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/jupnp-library-version-2-7-1-oh1-in-my-bundle-list/156221/9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core patch A PR that has been cherry-picked to a patch release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LinkedTransferQueue in OpenJDK 17 sometimes causes high CPU usage
3 participants