Browse Source

upgrade http4k, perf changes to apache implementation and db pool size. (#3942)

* tweaks to apache implementation and db pool size for perf.

* upgrade http4k

* change to use const
David Denton 7 years ago
parent
commit
05c2a967d7

+ 28 - 2
frameworks/Kotlin/http4k/apache/src/main/kotlin/Http4kApacheServer.kt

@@ -1,6 +1,32 @@
+import org.apache.http.config.SocketConfig
+import org.apache.http.impl.bootstrap.ServerBootstrap
+import org.http4k.core.HttpHandler
+import org.http4k.server.Http4kRequestHandler
+import org.http4k.server.Http4kServer
+import org.http4k.server.ServerConfig
+import java.util.concurrent.TimeUnit
 
-import org.http4k.server.ApacheServer
+private const val PORT = 9000
 
 fun main(args: Array<String>) {
-    Http4kBenchmarkServer().start(ApacheServer(9000))
+    Http4kBenchmarkServer().start(object : ServerConfig {
+        override fun toServer(httpHandler: HttpHandler): Http4kServer = object : Http4kServer {
+            override fun port() = PORT
+
+            private val server = ServerBootstrap.bootstrap()
+                    .setListenerPort(PORT)
+                    .setSocketConfig(SocketConfig.custom()
+                            .setTcpNoDelay(true)
+                            .setSoKeepAlive(true)
+                            .setSoReuseAddress(true)
+                            .setBacklogSize(512)
+                            .build())
+                    .registerHandler("*", Http4kRequestHandler(httpHandler))
+                    .create()
+
+            override fun start() = apply { server.start() }
+
+            override fun stop() = server.shutdown(15, TimeUnit.SECONDS)
+        }
+    })
 }

+ 1 - 1
frameworks/Kotlin/http4k/build.gradle

@@ -1,6 +1,6 @@
 buildscript {
     ext.kotlin_version = "1.2.50"
-    ext.http4k_version = "3.32.1"
+    ext.http4k_version = "3.33.1"
 
     repositories {
         mavenCentral()

+ 1 - 1
frameworks/Kotlin/http4k/core/src/main/kotlin/Database.kt

@@ -28,7 +28,7 @@ open class Database(private val dataSource: DataSource) {
 
             val config = HikariConfig()
             config.jdbcUrl = postgresqlUrl
-            config.maximumPoolSize = 100
+            config.maximumPoolSize = 256
             config.username = "benchmarkdbuser"
             config.password = "benchmarkdbpass"
             return Database(HikariDataSource(config))