diff --git a/java_hotspot_grpc_sgc_bench/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java b/java_hotspot_grpc_sgc_bench/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java index 33606ed2..b66bea15 100644 --- a/java_hotspot_grpc_sgc_bench/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java +++ b/java_hotspot_grpc_sgc_bench/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java @@ -57,7 +57,7 @@ private void start() throws IOException { *

*

*

* @@ -66,7 +66,7 @@ private void start() throws IOException { * this value. */ private ServerBuilder configureExecutor(ServerBuilder sb) { - var threads = System.getenv("JVM_EXECUTOR_THREADS"); + var threads = System.getenv("GRPC_SERVER_CPUS"); var i_threads = Runtime.getRuntime().availableProcessors(); if (threads != null && !threads.isEmpty()) { i_threads = Integer.parseInt(threads); diff --git a/java_micronaut_workstealing_bench/src/main/java/helloworld/ServerBuilderListener.java b/java_micronaut_workstealing_bench/src/main/java/helloworld/ServerBuilderListener.java index 9eab2ed0..97eac5e6 100644 --- a/java_micronaut_workstealing_bench/src/main/java/helloworld/ServerBuilderListener.java +++ b/java_micronaut_workstealing_bench/src/main/java/helloworld/ServerBuilderListener.java @@ -27,7 +27,7 @@ public ServerBuilder onCreated(BeanCreatedEvent> event) { *

*

*

* @@ -36,7 +36,7 @@ public ServerBuilder onCreated(BeanCreatedEvent> event) { * this value. */ private ServerBuilder configureExecutor(ServerBuilder sb) { - var threads = System.getenv("JVM_EXECUTOR_THREADS"); + var threads = System.getenv("GRPC_SERVER_CPUS"); var i_threads = Runtime.getRuntime().availableProcessors(); if (threads != null && !threads.isEmpty()) { i_threads = Integer.parseInt(threads); diff --git a/kotlin_grpc_bench/src/main/kotlin/io/grpc/examples/helloworld/HelloWorldServer.kt b/kotlin_grpc_bench/src/main/kotlin/io/grpc/examples/helloworld/HelloWorldServer.kt index 892b776d..c250c606 100644 --- a/kotlin_grpc_bench/src/main/kotlin/io/grpc/examples/helloworld/HelloWorldServer.kt +++ b/kotlin_grpc_bench/src/main/kotlin/io/grpc/examples/helloworld/HelloWorldServer.kt @@ -28,7 +28,7 @@ class HelloWorldServer(val port: Int) { val server: Server init { - val threads = System.getenv("JVM_EXECUTOR_THREADS") + val threads = System.getenv("GRPC_SERVER_CPUS") var i_threads = Runtime.getRuntime().availableProcessors() if (threads != null && !threads.isEmpty()) { i_threads = Integer.parseInt(threads) diff --git a/scala_fs2_bench/src/main/scala/com/example/helloworld/GreeterServer.scala b/scala_fs2_bench/src/main/scala/com/example/helloworld/GreeterServer.scala index 56e7507e..7aaaa447 100644 --- a/scala_fs2_bench/src/main/scala/com/example/helloworld/GreeterServer.scala +++ b/scala_fs2_bench/src/main/scala/com/example/helloworld/GreeterServer.scala @@ -23,7 +23,7 @@ object GreeterServer extends IOApp { *

*

*

* @@ -31,7 +31,7 @@ object GreeterServer extends IOApp { * availableProcessors(). Only the workStealing and fixed executors will use * this value. */ - val threads = System.getenv("JVM_EXECUTOR_THREADS") + val threads = System.getenv("GRPC_SERVER_CPUS") var i_threads = Runtime.getRuntime.availableProcessors if (threads != null && !threads.isEmpty) i_threads = threads.toInt val value = System.getenv.getOrDefault("JVM_EXECUTOR_TYPE", "workStealing") diff --git a/scala_zio_bench/src/main/scala/com/example/helloworld/GreeterServer.scala b/scala_zio_bench/src/main/scala/com/example/helloworld/GreeterServer.scala index 0b9a6604..1e9a1ecd 100644 --- a/scala_zio_bench/src/main/scala/com/example/helloworld/GreeterServer.scala +++ b/scala_zio_bench/src/main/scala/com/example/helloworld/GreeterServer.scala @@ -1,10 +1,45 @@ package com.example.helloworld -import scalapb.zio_grpc.{ServerMain, ServiceList} +import scalapb.zio_grpc.{Server, ServerLayer, ServerMain, ServiceList} +import zio.ZLayer + +import java.util.concurrent.Executors object GreeterServer extends ServerMain { def services: ServiceList[Any] = ServiceList.add(GreeterImpl) // Default port is 9000 override def port = 50051 + + override def serverLive: ZLayer[Any, Throwable, Server] = { + val sb = builder + + /** + * Allow customization of the Executor with two environment variables: + * + *

+ *

+ *

+ * + * The number of Executor Threads will default to the number of + * availableProcessors(). Only the workStealing and fixed executors will use + * this value. + */ + val threads = System.getenv("GRPC_SERVER_CPUS") + var i_threads = Runtime.getRuntime.availableProcessors + if (threads != null && !threads.isEmpty) i_threads = threads.toInt + val value = System.getenv.getOrDefault("JVM_EXECUTOR_TYPE", "workStealing") + value match { + case "direct" => sb.directExecutor + case "single" => sb.executor(Executors.newSingleThreadExecutor) + case "fixed" => sb.executor(Executors.newFixedThreadPool(i_threads)) + case "workStealing" => sb.executor(Executors.newWorkStealingPool(i_threads)) + case "cached" => sb.executor(Executors.newCachedThreadPool) + } + + ServerLayer.fromServiceList(sb, services) + } }