Skip to content

Commit

Permalink
=vertx deploy vertical target instances to match the CPU cores. (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
He-Pin authored Jun 27, 2023
1 parent 15a84df commit 0da5bb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion java_vertx_grpc_bench/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def protobufVersion = '3.21.6'
def protocVersion = protobufVersion

dependencies {
implementation 'io.vertx:vertx-grpc-server:4.4.3'
implementation 'io.vertx:vertx-grpc-server:4.4.4'
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}"
implementation "com.google.protobuf:protobuf-java-util:${protobufVersion}"
Expand Down
13 changes: 10 additions & 3 deletions java_vertx_grpc_bench/src/main/java/vertx/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
Expand All @@ -14,9 +15,15 @@
public class Main {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
vertx.nettyEventLoopGroup().forEach(u -> {
vertx.deployVerticle(new ServerVerticle());
});
DeploymentOptions deploymentOptions = new DeploymentOptions();
int cores = Runtime.getRuntime().availableProcessors();
String GRPC_SERVER_CPUS = System.getenv("GRPC_SERVER_CPUS");
if (GRPC_SERVER_CPUS != null && GRPC_SERVER_CPUS.length() > 0) {
cores = Integer.parseInt(GRPC_SERVER_CPUS);
}
deploymentOptions.setInstances(cores);
vertx.deployVerticle(ServerVerticle::new, deploymentOptions);
System.out.println("Deploy vertical instances:"+cores);
}

static class ServerVerticle extends AbstractVerticle {
Expand Down

0 comments on commit 0da5bb4

Please sign in to comment.