diff --git a/src/main/java/mdnet/base/ClientSettings.java b/src/main/java/mdnet/base/ClientSettings.java index de17707..fe21099 100644 --- a/src/main/java/mdnet/base/ClientSettings.java +++ b/src/main/java/mdnet/base/ClientSettings.java @@ -17,16 +17,16 @@ public final class ClientSettings { @SerializedName("client_secret") private final String clientSecret; @SerializedName("threads_per_cpu") - private final int threadsPerCPU; + private final int threadsPerCpu; public ClientSettings(long maxCacheSizeMib, long maxBandwidthMibPerHour, long maxBurstRateKibPerSecond, - int clientPort, String clientSecret, int threadsPerCPU) { + int clientPort, String clientSecret, int threadsPerCpu) { this.maxCacheSizeMib = maxCacheSizeMib; this.maxBandwidthMibPerHour = maxBandwidthMibPerHour; this.maxBurstRateKibPerSecond = maxBurstRateKibPerSecond; this.clientPort = clientPort; this.clientSecret = Objects.requireNonNull(clientSecret); - this.threadsPerCPU = threadsPerCPU; + this.threadsPerCpu = threadsPerCpu; } public long getMaxCacheSizeMib() { @@ -49,15 +49,15 @@ public final class ClientSettings { return clientSecret; } - public int getThreadsPerCPU() { - return threadsPerCPU; + public int getThreadsPerCpu() { + return threadsPerCpu; } @Override public String toString() { return "ClientSettings{" + "maxCacheSizeMib=" + maxCacheSizeMib + ", maxBandwidthMibPerHour=" + maxBandwidthMibPerHour + ", maxBurstRateKibPerSecond=" + maxBurstRateKibPerSecond + ", clientPort=" - + clientPort + ", clientSecret='" + "" + '\'' + ", threadsPerCPU=" + threadsPerCPU + "}"; + + clientPort + ", clientSecret='" + "" + '\'' + ", threadsPerCPU=" + threadsPerCpu + "}"; } 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 36dace2..7efb315 100644 --- a/src/main/kotlin/mdnet/base/Netty.kt +++ b/src/main/kotlin/mdnet/base/Netty.kt @@ -35,12 +35,14 @@ import java.util.concurrent.atomic.AtomicReference import javax.net.ssl.SSLException private val LOGGER = LoggerFactory.getLogger("Application") -private val THREADS_TO_ALLOCATE = Runtime.getRuntime().availableProcessors() 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 + override fun toServer(httpHandler: HttpHandler): Http4kServer = object : Http4kServer { - private val masterGroup = NioEventLoopGroup(THREADS_TO_ALLOCATE * clientSettings.getThreadsPerCPU()) - private val workerGroup = NioEventLoopGroup(THREADS_TO_ALLOCATE * clientSettings.getThreadsPerCPU()) + private val masterGroup = NioEventLoopGroup(threadsToAllocate) + private val workerGroup = NioEventLoopGroup(threadsToAllocate) private lateinit var closeFuture: ChannelFuture private lateinit var address: InetSocketAddress @@ -54,7 +56,7 @@ class Netty(private val tls: ServerSettings.TlsCert, private val clientSettings: override fun start(): Http4kServer = apply { if (LOGGER.isInfoEnabled) { - LOGGER.info("Starting webserver with {} threads", THREADS_TO_ALLOCATE * clientSettings.getThreadsPerCPU()) + LOGGER.info("Starting webserver with {} threads", threadsToAllocate) } val (mainCert, chainCert) = getX509Certs(tls.certificate)