Skip to content

Commit

Permalink
GRPC Server Executor pool
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster committed Jan 12, 2024
1 parent a93ca90 commit 10b2745
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/com/flipkart/gjex/core/config/GrpcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class GrpcConfig {
@JsonProperty("server.maxMessageSize")
private int maxMessageSize;

@JsonProperty("server.executorThreads")
private int executorThreads = 0;

public int getPort() {
return port;
}
Expand All @@ -40,4 +43,12 @@ public int getMaxMessageSize() {
public void setMaxMessageSize(int maxMessageSize) {
this.maxMessageSize = maxMessageSize;
}

public int getExecutorThreads() {
return executorThreads;
}

public void setExecutorThreads(int executorThreads) {
this.executorThreads = executorThreads;
}
}
6 changes: 4 additions & 2 deletions examples/src/main/resources/hello_world_config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Grpc:
server.port: 50051
server.executorThreads : 4

Dashboard:
service.port: 9999
Expand All @@ -16,7 +17,7 @@ Api:

Tracing:
collector.endpoint: http://localhost:9411/api/v2/spans

ScheduledJobs:
executorThreads: 5

Expand All @@ -27,4 +28,5 @@ apiProperties:
sayhello.deadline: 330

taskProperties:
hello.timeout: 200
hello.timeout: 200

17 changes: 12 additions & 5 deletions guice/src/main/java/com/flipkart/gjex/grpc/service/GrpcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@
import com.flipkart.gjex.grpc.interceptor.FilterInterceptor;
import com.flipkart.gjex.grpc.interceptor.StatusMetricInterceptor;
import com.flipkart.gjex.grpc.interceptor.TracingInterceptor;
import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.ServerInterceptors;
import io.grpc.*;
import io.grpc.internal.GrpcUtil;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.List;
import java.util.concurrent.Executors;

/**
* <code>GrpcServer</code> is a {@link Service} implementation that manages the GJEX Grpc Server instance lifecycle
Expand Down Expand Up @@ -74,7 +72,16 @@ public GrpcServer(GJEXConfiguration configuration,
this.maxMessageSize = configuration.getGrpc().getMaxMessageSize();
info("Creating GrpcServer with maximum message size allowed : " + maxMessageSize);
}
this.grpcServerBuilder = ServerBuilder.forPort(this.port).maxInboundMessageSize(this.maxMessageSize);
this.grpcServerBuilder = Grpc.newServerBuilderForPort(this.port, InsecureServerCredentials.create()).maxInboundMessageSize(this.maxMessageSize);

if (configuration.getGrpc().getExecutorThreads() > 0) {
this.grpcServerBuilder.executor(
Executors.newFixedThreadPool(
configuration.getGrpc().getExecutorThreads(),
GrpcUtil.getThreadFactory("grpc-executor-%d", true)));
}


this.filterInterceptor = filterInterceptor;
this.tracingInterceptor = tracingInterceptor;
this.statusMetricInterceptor = statusMetricInterceptor;
Expand Down

0 comments on commit 10b2745

Please sign in to comment.