armeria icon indicating copy to clipboard operation
armeria copied to clipboard

[Issue-4917] Add blockingTaskExecutor in Thrift services

Open ChangguHan opened this issue 10 months ago โ€ข 5 comments

Motivation:

Add blockingTaskExecutor in Thrift services #4917

Modifications:

  • Add useBlockingTaskExecutor into THttpServiceBuilder.java
  • Apply useBlockingTaskExecutor into THttpService.java

Result:

  • Closes #4917. (If this resolves the issue.)
  • User can use useBlockingTaskExecutor from THttpServiceBuilder.java

ChangguHan avatar Apr 18 '24 05:04 ChangguHan

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 18 '24 05:04 CLAassistant

๐Ÿ” Build Scanยฎ (commit: 7876ae5459e6a633115982364d720e6b557f46e6)

Job name Status Build Scanยฎ
build-windows-latest-jdk-21 โœ… https://ge.armeria.dev/s/zyv5ychb74cyi
build-self-hosted-unsafe-jdk-8 โœ… https://ge.armeria.dev/s/5gbtn7jfo3hbk
build-self-hosted-unsafe-jdk-21-snapshot-blockhound โœ… https://ge.armeria.dev/s/mkiwhxqqwo4bc
build-self-hosted-unsafe-jdk-17-min-java-17-coverage โœ… https://ge.armeria.dev/s/axbcmxzdpuqvy
build-self-hosted-unsafe-jdk-17-min-java-11 โœ… https://ge.armeria.dev/s/yjdw3q4vjeymi
build-self-hosted-unsafe-jdk-17-leak โŒ (failure) https://ge.armeria.dev/s/yq5kpsjeqryju
build-self-hosted-unsafe-jdk-11 โœ… https://ge.armeria.dev/s/owj3lbzt64qjw
build-macos-12-jdk-21 โœ… https://ge.armeria.dev/s/pjwk7fj7hxgpq

github-actions[bot] avatar Apr 18 '24 06:04 github-actions[bot]

Oops, I realized that we also need to fix ThriftCallService not to use blocking task executor twice: https://github.com/line/armeria/blob/10424c711cb22a2b001f9bd737453a25743dc18d/thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java#L186

private static void invoke(
        ServiceRequestContext ctx,
        Object impl, ThriftFunction func, List<Object> args, CompletableRpcResponse reply) {

    try {
        final TBase<?, ?> tArgs = func.newArgs(args);
        if (func.isAsync()) {
            invokeAsynchronously(impl, func, tArgs, reply);
        } else if (ctx.eventLoop().inEventLoop()) {
            invokeSynchronously(ctx, impl, func, tArgs, reply);
        } else {
            invokeSynchronously0(ctx, impl, func, tArgs, reply);
        }
    } catch (Throwable t) {
        reply.completeExceptionally(t);
    }
}

private static void invokeSynchronously(
        ServiceRequestContext ctx, Object impl,
        ThriftFunction func, TBase<?, ?> args, CompletableRpcResponse reply) {
    ctx.blockingTaskExecutor().execute(() -> invokeSynchronously0(ctx, impl, func, args, reply));
}

private static void invokeSynchronously0(
        ServiceRequestContext ctx, Object impl,
        ThriftFunction func, TBase<?, ?> args, CompletableRpcResponse reply) {
    ...
}

minwoox avatar Apr 23 '24 11:04 minwoox

@trustin I fix to decide whether to check useBlockingTaskExecutor in ThriftCallService instead of THttpService. Would you check this?

https://github.com/line/armeria/blob/096390525fcc3835a21004e466c39109e2f8b490/thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java#L125-L139

ChangguHan avatar Apr 24 '24 12:04 ChangguHan

Oops, I realized that we also need to fix ThriftCallService not to use blocking task executor twice:

https://github.com/line/armeria/blob/10424c711cb22a2b001f9bd737453a25743dc18d/thrift/thrift0.13/src/main/java/com/linecorp/armeria/server/thrift/ThriftCallService.java#L186

private static void invoke(
        ServiceRequestContext ctx,
        Object impl, ThriftFunction func, List<Object> args, CompletableRpcResponse reply) {

    try {
        final TBase<?, ?> tArgs = func.newArgs(args);
        if (func.isAsync()) {
            invokeAsynchronously(impl, func, tArgs, reply);
        } else if (ctx.eventLoop().inEventLoop()) {
            invokeSynchronously(ctx, impl, func, tArgs, reply);
        } else {
            invokeSynchronously0(ctx, impl, func, tArgs, reply);
        }
    } catch (Throwable t) {
        reply.completeExceptionally(t);
    }
}

private static void invokeSynchronously(
        ServiceRequestContext ctx, Object impl,
        ThriftFunction func, TBase<?, ?> args, CompletableRpcResponse reply) {
    ctx.blockingTaskExecutor().execute(() -> invokeSynchronously0(ctx, impl, func, args, reply));
}

private static void invokeSynchronously0(
        ServiceRequestContext ctx, Object impl,
        ThriftFunction func, TBase<?, ?> args, CompletableRpcResponse reply) {
    ...
}

@minwoox Thank you for your review. I fix to check in ThriftCallService!

ChangguHan avatar Apr 24 '24 12:04 ChangguHan

Revised and cleaned up the PR description and commit message.

trustin avatar Jun 20 '24 13:06 trustin

Nice work @ChangguHan !!! ๐Ÿ‘๐Ÿ‘

injae-kim avatar Jun 24 '24 08:06 injae-kim