armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Provide a way to run service code out of I/O event loops

Open kezhenxu94 opened this issue 3 years ago • 10 comments

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 to ServerBuilder and AbstractServiceBindingBuilder so 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 DefaultServiceRequestContext so it accepts an EventLoop.
    • Modify HttpServerHandler.handleRequest(), so it specifies an event loop from the serviceWorkerGroup.

Result:

  • Closes #4099.
  • Users can add per-service/virtual host/server serviceWorkerGroup property that makes a service use a different EventLoopGroup than ServerBuilder.workerGroup.

kezhenxu94 avatar Mar 11 '22 13:03 kezhenxu94

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

... and 1684 files with indirect coverage changes

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Mar 12 '22 09:03 codecov[bot]

@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. 🙇

trustin avatar Mar 28 '22 08:03 trustin

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 😇

kezhenxu94 avatar Mar 28 '22 08:03 kezhenxu94

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 😭

kezhenxu94 avatar Apr 25 '22 04:04 kezhenxu94

Thanks for your initial contribution. 🙇‍♂️ We are happy to take over the remaining work.

ikhoon avatar Apr 26 '22 02:04 ikhoon

I think I can manage to find some time to continue this work. Just rebase from the master.

kezhenxu94 avatar Jul 10 '22 09:07 kezhenxu94

I think all comments are addressed now

kezhenxu94 avatar Jul 11 '22 02:07 kezhenxu94

I think all comments are addressed now

Welcome back! ❤️

ikhoon avatar Jul 13 '22 03:07 ikhoon

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

minwoox avatar Jul 18 '22 14:07 minwoox

Added a merge commit due to a conflict with my PR

jrhee17 avatar Aug 09 '22 08:08 jrhee17

🔍 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

github-actions[bot] avatar Sep 08 '23 05:09 github-actions[bot]

Let me close this PR and create a separate one 🙇

jrhee17 avatar Oct 12 '23 02:10 jrhee17