-
Notifications
You must be signed in to change notification settings - Fork 893
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
Support for virtual threads (Java 21) #9534
Comments
Here's my understanding on this topic, I've implemented the virtual thread support in the elastic apm agent. Thread LocalsThe usage of thread locals prior to virtual threads can be roughly divided into two categories:
The first use case is still fine with virtual threads: It is just a necessary tool and the lifetime of the thread local is usually limited (e.g. via the closeable The second use case is the one which can be problematic. A good example is the TemporaryBuffers class from the SDK. With non-virtual threads this was super nice, especially because your typical web application would use a thread-pool of worker threads. After every thread in the pool has been used, With virtual threads the intended usage would be to not pool threads, but create a new virtual thread for each request. Where things get really bad is if the Imagine an HTTP Gateway which just forwards the HTTP requests to other services which take 10s on avergage. Alternatives
Suggestion for next stepsIn my opinion it would make sense to go through both the Otel Agent and the SDK and to look at all usages of ThreadLocals.
We (elastic) can definitely contribute the object pooling implementation and it's JMH benchmark suite to Otel if desired. We've been using this pooling implementation for a few years now to minimize allocation rates prior to virtual threads, so it is battle tested. ExecutorsThe newly added Executors are Executors.newVirtualThreadPerTaskExecutor() and Executors.newThreadPerTaskExecutor(ThreadFactory). I think the former builds on the latter. Chances are high that our instrumentation already covers these, so maybe just adding tests for those should be good enough. This is at least how it was for the elastic agent. |
I looked for all usages of Usages might needing workAPI: TemporaryBuffers
SDK: JdkHttpSender
SDK: ProtoSerializer
For the agent I think no changes are needed, all usages seem fine to me! Usages looking fine to meI checked the following usages across API, SDK and Agent but classified them as non-problematic for virtual threads: API:
SDK:
Agent:
TL;DR
Some Feedback on whether you agree / disagree would be great! |
Virtual threads are out of preview and included in new Java 21 (LTS) release (https://openjdk.org/jeps/444).
Notes/references from weekly Java meeting:
The text was updated successfully, but these errors were encountered: