Provide a way to run service code out of I/O event loops
Motivations:
When service devs are not very familiar with asynchronous programming, it is very easy to drive Armeria's core event loops into havoc by blocking them.
Framework devs may want to make sure Armeria at least handle I/O and function normally for a certain set of core services, such as PrometheusExpositionService or HealthCheckService, by isolating other non-core services from the I/O event loops.
Modifications:
- Add the
serviceWorkerGroup()builder methods toServerBuilderandAbstractServiceBindingBuilderso a user can specify the service worker groups as shown in the above example. - Change how Armeria assigns an event loop to a
ServiceRequestContext.- Modify the constructor of
DefaultServiceRequestContextso it accepts anEventLoop. - Modify
HttpServerHandler.handleRequest(), so it specifies an event loop from theserviceWorkerGroup.
- Modify the constructor of
Result:
- Closes #4099.
- Users can add per-service/virtual host/server
serviceWorkerGroupproperty that makes a service use a differentEventLoopGroupthanServerBuilder.workerGroup.
Codecov Report
Patch coverage: 67.61% and project coverage change: +74.21% :tada:
Comparison is base (
e344c96) 0.00% compared to head (f8e1c86) 74.21%.
Additional details and impacted files
@@ Coverage Diff @@
## main #4136 +/- ##
===========================================
+ Coverage 0 74.21% +74.21%
- Complexity 0 19880 +19880
===========================================
Files 0 1702 +1702
Lines 0 73231 +73231
Branches 0 9367 +9367
===========================================
+ Hits 0 54349 +54349
- Misses 0 14445 +14445
- Partials 0 4437 +4437
| Files Changed | Coverage Δ | |
|---|---|---|
| .../armeria/server/AbstractServiceBindingBuilder.java | 63.51% <0.00%> (ø) |
|
| ...java/com/linecorp/armeria/server/ServerConfig.java | 0.00% <ø> (ø) |
|
| ...linecorp/armeria/server/ServiceBindingBuilder.java | 62.68% <0.00%> (ø) |
|
| .../linecorp/armeria/server/ServiceConfigSetters.java | 100.00% <ø> (ø) |
|
| ...ver/VirtualHostAnnotatedServiceBindingBuilder.java | 38.29% <0.00%> (ø) |
|
| ...meria/server/VirtualHostServiceBindingBuilder.java | 42.62% <0.00%> (ø) |
|
| .../linecorp/armeria/server/ServiceConfigBuilder.java | 56.52% <33.33%> (ø) |
|
| .../server/AbstractAnnotatedServiceConfigSetters.java | 71.96% <50.00%> (ø) |
|
| ...armeria/server/AnnotatedServiceBindingBuilder.java | 58.13% <50.00%> (ø) |
|
| ...ava/com/linecorp/armeria/server/ServerBuilder.java | 82.04% <50.00%> (ø) |
|
| ... and 8 more |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@kezhenxu94 Sorry about the conflicts since your last commit here. Please feel free to let us know if you need any help with catching up the recent changes in master. 🙇
Thanks you @trustin and @ikhoon for your review, I'll take some time to catch up the latest branch and if need help will ask for your help 😇
Ooops, it's been ~1 month and I haven't found time to pick this up, sorry I have to close this for now and others can continue to work on this 😭
Thanks for your initial contribution. 🙇♂️ We are happy to take over the remaining work.
I think I can manage to find some time to continue this work. Just rebase from the master.
I think all comments are addressed now
I think all comments are addressed now
Welcome back! ❤️
Shouldn't we call httpService.serve(ctx, req) in the serviceWorkerGroup?
https://github.com/line/armeria/blob/master/core/src/main/java/com/linecorp/armeria/server/HttpServerHandler.java#L356
Added a merge commit due to a conflict with my PR
🔍 Build Scan® (commit: f8e1c8644a7da437b4ab5d0007cea1a7ef8f6f94)
| Job name | Status | Build Scan® |
|---|---|---|
| build-windows-latest-jdk-19 | ✅ | https://ge.armeria.dev/s/3hvt3bhixilsu |
| build-self-hosted-jdk-8 | ✅ | https://ge.armeria.dev/s/pqg34tq2rh3r4 |
| build-self-hosted-jdk-19-snapshot-blockhound | ✅ | https://ge.armeria.dev/s/mx5mmugjwfbne |
| build-self-hosted-jdk-17-min-java-17-coverage | ✅ | https://ge.armeria.dev/s/5ngc75rwtvjpg |
| build-self-hosted-jdk-17-min-java-11 | ✅ | https://ge.armeria.dev/s/qix6msycvoffg |
| build-self-hosted-jdk-17-leak | ✅ | https://ge.armeria.dev/s/rhhiv2wpbso3m |
| build-self-hosted-jdk-11 | ✅ | https://ge.armeria.dev/s/qsuns47tb4ynq |
| build-macos-12-jdk-19 | ✅ | https://ge.armeria.dev/s/ccy22lqbv3mda |
Let me close this PR and create a separate one 🙇