This commit is contained in:
carbotaniuman 2020-06-11 15:02:07 -05:00
parent 522c96f70f
commit a70381eea4
2 changed files with 12 additions and 10 deletions

View file

@ -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='" + "<hidden>" + '\'' + ", threadsPerCPU=" + threadsPerCPU + "}";
+ clientPort + ", clientSecret='" + "<hidden>" + '\'' + ", threadsPerCPU=" + threadsPerCpu + "}";
}
public static boolean isSecretValid(String clientSecret) {

View file

@ -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<Statistics>) : 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)