-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Project Loom is here and Jetty 10+ already supports it #82
Comments
From my perspective, I would pick approach 1 and provide an option to enable virtual-threads support explicitly. I'm not sure if there is any prerequisite for the clojure app, if it is to run on virtual-threads. Doors are open if there is scenario to customize something, these pro users can always provide their own |
For what it's worth, here is how such a pool could look like in pure clojure: (defn- jetty-vpool
([]
(jetty-vpool "jetty-"))
([^String thread-prefix]
(let [exec (-> (Thread/ofVirtual)
(.name thread-prefix 0)
.factory
Executors/newThreadPerTaskExecutor)]
(reify ThreadPool
(execute [_ runnable] ;; pass-through
(.execute exec runnable))
(join [_]
(try ;; block indefinitely
(.awaitTermination exec Long/MAX_VALUE TimeUnit/DAYS)
(catch InterruptedException _ (.shutdown exec))))
(getThreads [_]
(->> (Thread/getAllStackTraces)
.keySet
(filter (fn [^Thread t]
(and (.isVirtual t)
(-> (.getName t)
(.startsWith thread-prefix)))))
count))
(isLowOnThreads [_] false) ;; seems reasonable since the executor is unbounded
(getIdleThreads [_] Integer/MAX_VALUE))))) |
Thank you for providing the example. The pool implementation contains a few customization. I suggest to leave this to advanced user and use-cases. If we go approach 1 to use jetty's native support of virtual threads, are you interested in adding support for this new option? I believe its sufficient during the preview period of virtual threads feature. |
Ok yeah, I'll try to have a look at how to configure jetty... |
So I wasn't able to find any concrete info on how to to configure jetty for virtual-threads, but I did find the following class:
I'm not 100% sure I'm reading this correctly, but it seems to happen automatically (given that the runtime supports it). I find it hard to believe that they would do something so 'aggressive' without an opt-in mechanism, but without anything more explicit, that's what I'm inferring. |
I just tested JDK-19 with |
Ok so I tracked down the original commit that shows more or less the complete picture:
Looking at line 62 of |
Some good news here...It seems that the usual
If that's right, all you have to do is to expose a |
Sorry for late response. I haven't checked Jetty's |
Just leaving it out here in case it's of use to anyone. I managed to get it running using Jetty (doto (org.eclipse.jetty.util.thread.ExecutorThreadPool.)
(.setVirtualThreadsExecutor (java.util.concurrent.Executors/newVirtualThreadPerTaskExecutor))) the implementation of the |
Nice one @lispyclouds - i can confirm it works well with |
I think max and min threads are overridden if the thread pool is set? |
They are ignored here (on this library), but what about Jetty itself? For example, with |
Ah right, will try digging around more! Didn't know it was set to 200. |
I suppose |
This can also be closed 👍 |
Could you please provide the full example? |
This is how I'm using it. |
How have you configured it? Can we see the code? Also checking the thread count of just the JVM and if they are virtual threads could help too. |
@darkleaf Your code is correct (I'm actually using |
I've read The Ultimate Guide to Java Virtual Threads and enabled
|
@darkleaf Java has had an excellent http-client since version 9 😄 |
Maybe I'll switch to java.net.http.HttpClient.
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazySeq.java#L41-L66 Also, I use org.graalvm.js/js, it also has
|
FYI - https://clojure.atlassian.net/browse/CLJ-2771 |
As far as I can tell there are two viable options here:
org.eclipse.jetty.util.thread.ThreadPool
impl (via the:thread-pool
option)Unfortunately, none of the two options is free - so to speak...With the first option, someone has to figure out how to configure this (I can definitely help out), and you (as the author of this lib) would have to expose it. With the second option, things are kind of looser...
You could certainly say that there is not much to do here because option 2 is already supported...But think about this - everyone who wants to use virtual threads via option 2, has to write the same mundane Java class (which basically wraps this new executor). So I would say this actually belongs in the library.
Let me know of your thoughts...
The text was updated successfully, but these errors were encountered: