-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add support to provide your own executor #114
Conversation
eb4fc03
to
7554ed6
Compare
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.
The change looks good to me. +1 for merging. Thanks for providing this PR @slinkydeveloper.
+1 for adding a test to our e2e test suite.
sdk-http-vertx/src/main/java/dev/restate/sdk/http/vertx/RequestHttpServerHandler.java
Outdated
Show resolved
Hide resolved
Do you need to use a beta version of the Kotlin plugin to make the SDK work with Java 21? What should be the minimum required Java version for the SDK? Currently it is Java 11, right? Are there some benefits of running the services in a virtual thread? I guess when doing blocking I/O. Would this also help when waiting on a future result? |
Yes, Kotlin on JDK 21 is not GA yet. Will be in december I think, the JDK 21 is just too new.
Yes, we had no reason to bump it to 17 yet. 21 is the latest LTS, 17 is the previous LTS.
As the current status quo of the sdk, when combined with the Vert.x http implementation, you get synchronous coding style in java (no futures, callbacks, etc) very cheaply on top of async i/o. Without virtual threads, you would use vertx.executeBlocking which under the hood uses a thread pool to achieve the same result. This thread pool is also unbounded, meaning that it potentially spawns one OS thread per connection in the worst case.
In the virtual threads world you don't use futures. I think in general, independently from virtual threads or not, this change is useful, as I can see users that want to bring their own executors to run their own code. |
This is beneficial if the users calls an external service from a side effect closure via some http client, I assume, right? For the communication between the vertx based Restate communication layer and the service code we block on some |
I guess so, also this is also beneficial if you have many concurrent requests to this service endpoint, because for each of them you spawn one of these virtual threads.
As far as i understood, all the locking primitives are virtual threads aware, so it would not block the OS thread but rather execute another virtual thread. But i'm fuzzy on the details TBH: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Thread.html#virtual-threads |
7554ed6
to
b6a14c8
Compare
Add method to support providing your own executor for blocking services.
This allows to integrate with virtual threads:
I tested this feature locally with the virtual thread executor and it works. Unfortunately I couldn't easily setup a test within this project because i need to change the minimum jdk version, and i need to use a beta version of the kotlin plugin. Perhaps we can add a test to the e2e repo.