From 0da5bb4e47e90d70d384008d0373fe0f66d38b06 Mon Sep 17 00:00:00 2001 From: kerr Date: Tue, 27 Jun 2023 15:19:24 +0800 Subject: [PATCH] =vertx deploy vertical target instances to match the CPU cores. (#361) --- java_vertx_grpc_bench/build.gradle | 2 +- java_vertx_grpc_bench/src/main/java/vertx/Main.java | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/java_vertx_grpc_bench/build.gradle b/java_vertx_grpc_bench/build.gradle index 4cb561fa..1cab4abe 100644 --- a/java_vertx_grpc_bench/build.gradle +++ b/java_vertx_grpc_bench/build.gradle @@ -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}" diff --git a/java_vertx_grpc_bench/src/main/java/vertx/Main.java b/java_vertx_grpc_bench/src/main/java/vertx/Main.java index 5bb5f6c7..f09fe555 100644 --- a/java_vertx_grpc_bench/src/main/java/vertx/Main.java +++ b/java_vertx_grpc_bench/src/main/java/vertx/Main.java @@ -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; @@ -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 {