From 896923c1cbd07aba20781d64582cc7f578b07bbf Mon Sep 17 00:00:00 2001 From: Lloyd Date: Mon, 16 Nov 2015 10:33:13 +0900 Subject: [PATCH] Use thread multiplier instead --- .../scala/com/beachape/metascraper/ScraperActor.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/scala/com/beachape/metascraper/ScraperActor.scala b/src/main/scala/com/beachape/metascraper/ScraperActor.scala index a4296bb..9967e9d 100644 --- a/src/main/scala/com/beachape/metascraper/ScraperActor.scala +++ b/src/main/scala/com/beachape/metascraper/ScraperActor.scala @@ -35,6 +35,8 @@ object ScraperActor { connectionTimeoutInMs, requestTimeoutInMs ) + + private def coreCount = Runtime.getRuntime.availableProcessors() } /** @@ -44,7 +46,7 @@ object ScraperActor { * method */ class ScraperActor( - httpExecutorThreads: Int = 10, + threadMultiplier: Int = 3, maxConnectionsPerHost: Int = 30, connectionTimeout: Duration = 10.seconds, requestTimeout: Duration = 15.seconds) @@ -58,10 +60,10 @@ class ScraperActor( val followRedirects = true val connectionPooling = false - private val executorService = Executors.newFixedThreadPool(httpExecutorThreads) + private val executorService = Executors.newFixedThreadPool(threadMultiplier * ScraperActor.coreCount) private val config = new AsyncHttpClientConfig.Builder() .setExecutorService(executorService) - .setIOThreadMultiplier(1) + .setIOThreadMultiplier(threadMultiplier) .setMaxConnectionsPerHost(maxConnectionsPerHost) .setAllowPoolingConnections(connectionPooling) .setAllowPoolingSslConnections(connectionPooling)