-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
feat: Add loom Support. #159
base: master
Are you sure you want to change the base?
Conversation
example/minimalApplicationWithLoom/app/src/MinimalApplicationWithLoom.scala
Show resolved
Hide resolved
fc79bd2
to
0340772
Compare
In Mill you use |
@lihaoyi I think this pr is ready now, seems the virtual thread only improves the performance when heavy blocking. |
@He-Pin looks good overall, please summarize your benchmark results into a short summary table to include in the documentation with a link back to this PR for people to view the full details |
@lihaoyi I have updated with a summary table and added another note about classloading |
Thanks @He-Pin, I'll leave the PR open a few more days to see if anyone else wants to comment before merging |
@sorumehta Hi, this pr is ready, would you like to take a look at this, thanks. |
@He-Pin Quick question: once this is merged, do virtual threads become the default execution method? Or this happens based on certain condition(s)? |
@samikrc thanks for intresting. Short answer: No. it will only enabled once
Because, with the current implementation of JDK, virtual threads can lead to deadlock if they are not configured properly, we encountered this in production when a virtual thread and platform threads both tried to load the same class The JVM team at Alibaba helped us with a tweaked AJDK, which will add one more carrier thread for this, and they backported the JDK24 features into AJDK21 too. So, virtual threads help us reduce 50% ygc and 10 pt CPU usage under heavy load. Our system is fully async, so we can only see these improvements. For any user who tries to use Virtual threads in production, I would suggest:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to see this PR 😍 Was curious and checked out the code. I've noticed one or two things.
globalLogger.exception(e) | ||
throw new UnsupportedOperationException("Failed to create newThreadPerTaskExecutor.", e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exception is both logged and re-thrown.
case NonFatal(e) => | ||
globalLogger.exception(e) | ||
//--add-opens java.base/java.lang=ALL-UNNAMED | ||
throw new UnsupportedOperationException("Failed to create virtual thread factory.", e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exception is both logged and re-thrown.
protected def handlerExecutor(): Executor = { | ||
if (enableVirtualThread) { | ||
Util.createDefaultCaskVirtualThreadExecutor.orNull | ||
} else null | ||
} | ||
|
||
protected def enableVirtualThread: Boolean = { | ||
val enableVirtualThread = System.getProperty(Main.VIRTUAL_THREAD_ENABLED) | ||
enableVirtualThread != null && enableVirtualThread.toBoolean | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this 2 methods instead of just one?
protected def handlerExecutor(): Option[Executor] = {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this way, it can support our box, otherwise, I need to do some kind of conditional compiling with an additional source folder and only include that folder when compiling with Java 21.
But the current one is better because the user can enable it with only a property, we use this kind in production too.
Motivation:
Add Loom support.
refs: #90 , again
Modification:
handlerExecutor()
and some helper methods for virtual threads.Result:
Virtual threads supported.
wrk
is needed to run the benchmarkResults of same 4 Carrier/Platform threads:
Some design choices:
--add-opens java.base/java.lang=ALL-UNNAMED
handleExecutor
directly too.