From 662ceb44e455b08b61b636a6737c29891d9fb565 Mon Sep 17 00:00:00 2001 From: Amos Ng Date: Fri, 12 Jun 2020 20:05:45 +0800 Subject: [PATCH] Made Netty thread count global instead of per-cpu --- CHANGELOG.md | 1 + src/main/java/mdnet/base/ClientSettings.java | 14 +++++++------- src/main/kotlin/mdnet/base/Netty.kt | 3 +-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30a69ba..d2a8d27 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [2020-06-12] Raised ApacheClient socket limit to `2**18` by [@lflare]. - [2020-06-12] Changed gradle versioning to using `git describe` by [@lflare]. +- [2020-06-12] Made Netty thread count global instead of per-cpu by [@lflare]. ### Deprecated diff --git a/src/main/java/mdnet/base/ClientSettings.java b/src/main/java/mdnet/base/ClientSettings.java index 0677356..fdf55b2 100644 --- a/src/main/java/mdnet/base/ClientSettings.java +++ b/src/main/java/mdnet/base/ClientSettings.java @@ -16,17 +16,17 @@ public final class ClientSettings { private final int clientPort; @SerializedName("client_secret") private final String clientSecret; - @SerializedName("threads_per_cpu") - private final int threadsPerCpu; + @SerializedName("threads") + private final int threads; public ClientSettings(long maxCacheSizeMib, long maxBandwidthMibPerHour, long maxBurstRateKibPerSecond, - int clientPort, String clientSecret, int threadsPerCpu) { + int clientPort, String clientSecret, int threads) { this.maxCacheSizeMib = maxCacheSizeMib; this.maxBandwidthMibPerHour = maxBandwidthMibPerHour; this.maxBurstRateKibPerSecond = maxBurstRateKibPerSecond; this.clientPort = clientPort; this.clientSecret = Objects.requireNonNull(clientSecret); - this.threadsPerCpu = threadsPerCpu; + this.threads = threads; } public long getMaxCacheSizeMib() { @@ -49,15 +49,15 @@ public final class ClientSettings { return clientSecret; } - public int getThreadsPerCpu() { - return (threadsPerCpu > 0) ? threadsPerCpu : 16; + public int getThreads() { + return (threads > 0) ? threads : 16; } @Override public String toString() { return "ClientSettings{" + "maxCacheSizeMib=" + maxCacheSizeMib + ", maxBandwidthMibPerHour=" + maxBandwidthMibPerHour + ", maxBurstRateKibPerSecond=" + maxBurstRateKibPerSecond + ", clientPort=" - + clientPort + ", clientSecret='" + "" + '\'' + ", threadsPerCpu=" + getThreadsPerCpu() + '}'; + + clientPort + ", clientSecret='" + "" + '\'' + ", threads=" + getThreads() + '}'; } public static boolean isSecretValid(String clientSecret) { diff --git a/src/main/kotlin/mdnet/base/Netty.kt b/src/main/kotlin/mdnet/base/Netty.kt index 7efb315..175d732 100644 --- a/src/main/kotlin/mdnet/base/Netty.kt +++ b/src/main/kotlin/mdnet/base/Netty.kt @@ -37,8 +37,7 @@ import javax.net.ssl.SSLException private val LOGGER = LoggerFactory.getLogger("Application") class Netty(private val tls: ServerSettings.TlsCert, private val clientSettings: ClientSettings, private val stats: AtomicReference) : ServerConfig { - private val threadsToAllocate: Int - get() = Runtime.getRuntime().availableProcessors() * clientSettings.threadsPerCpu + private val threadsToAllocate = clientSettings.getThreads() override fun toServer(httpHandler: HttpHandler): Http4kServer = object : Http4kServer { private val masterGroup = NioEventLoopGroup(threadsToAllocate)