From ac682e98c337ec157ca13bd80bcc62779e8e99dd Mon Sep 17 00:00:00 2001 From: Amos Ng Date: Fri, 12 Jun 2020 02:47:43 +0800 Subject: [PATCH] Made more changes to the numbers used for threading --- src/main/kotlin/mdnet/base/Application.kt | 4 +--- src/main/kotlin/mdnet/base/Netty.kt | 9 +++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/mdnet/base/Application.kt b/src/main/kotlin/mdnet/base/Application.kt index d3b3dc2..4c7e8c9 100644 --- a/src/main/kotlin/mdnet/base/Application.kt +++ b/src/main/kotlin/mdnet/base/Application.kt @@ -45,7 +45,7 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting val executor = Executors.newCachedThreadPool() if (LOGGER.isInfoEnabled) { - LOGGER.info("Starting ApacheClient with {} threads", THREADS_TO_ALLOCATE) + LOGGER.info("Starting image retriever") } val client = ApacheClient(responseBodyMode = BodyMode.Stream, client = HttpClients.custom() @@ -144,7 +144,6 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting if (LOGGER.isTraceEnabled) { LOGGER.trace("Upstream query for $sanitizedUri errored with status {}", mdResponse.status) } - mdResponse.close() Response(mdResponse.status) } else { if (LOGGER.isTraceEnabled) { @@ -195,7 +194,6 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting } respondWithImage(mdResponse.body.stream, contentLength, contentType, lastModified) } - mdResponse.close() } } } diff --git a/src/main/kotlin/mdnet/base/Netty.kt b/src/main/kotlin/mdnet/base/Netty.kt index 2846c92..070cdb2 100644 --- a/src/main/kotlin/mdnet/base/Netty.kt +++ b/src/main/kotlin/mdnet/base/Netty.kt @@ -35,11 +35,12 @@ 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() * 32 / 2 class Netty(private val tls: ServerSettings.TlsCert, private val clientSettings: ClientSettings, private val stats: AtomicReference) : ServerConfig { override fun toServer(httpHandler: HttpHandler): Http4kServer = object : Http4kServer { - private val masterGroup = NioEventLoopGroup(Runtime.getRuntime().availableProcessors() * 30 / 2) - private val workerGroup = NioEventLoopGroup(Runtime.getRuntime().availableProcessors() * 30 / 2) + private val masterGroup = NioEventLoopGroup(THREADS_TO_ALLOCATE) + private val workerGroup = NioEventLoopGroup(THREADS_TO_ALLOCATE) private lateinit var closeFuture: ChannelFuture private lateinit var address: InetSocketAddress @@ -52,6 +53,10 @@ 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) + } + val (mainCert, chainCert) = getX509Certs(tls.certificate) val sslContext = SslContextBuilder .forServer(getPrivateKey(tls.privateKey), mainCert, chainCert)