Browse Source

Update ktor dependencies, do minor cleanup (#3102)

- Update kotlin from 1.1.2 to 1.2.0, which should make this
  forward-compatible with Java 9.

- Update ktor itself from 0.3.3 to 0.9.0, which comes with a package name
  change for the framework, from "org.jetbrains.ktor" to "io.ktor".

- Remove the empty test and the now-unused JUnit dependency.

- Remove the SampleCollLogging debug class which broke with the ktor
  update.  If someone else feels like fixing it later and adding it back,
  that's fine with me.

- Remove unnecessary TYPE_FORWARD_ONLY and CONCUR_READ_ONLY parameters,
  which are the default.

- Un-obfuscate the database username and password.  There's no reason to
  obfuscate them.

- Inline the database hostname "TFB-database" instead of reading the
  DBHOST environment variable, since that's how we're defining the
  database host nowadays.

- Raise the root logging threshold from TRACE to INFO, because TRACE
  includes stuff we don't care about, such as connections being added to
  the HikariCP pool.
Michael Hixson 7 years ago
parent
commit
b06047d472

+ 17 - 22
frameworks/Kotlin/ktor/pom.xml

@@ -13,10 +13,12 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <kotlin.version>1.1.2-5</kotlin.version>
-        <junit.version>4.12</junit.version>
-
-        <ktor.version>0.3.3</ktor.version>
+        <gson.version>2.8.2</gson.version>
+        <hikaricp.version>2.7.4</hikaricp.version>
+        <kotlin.version>1.2.0</kotlin.version>
+        <ktor.version>0.9.0</ktor.version>
+        <logback.version>1.2.3</logback.version>
+        <mysql-connector.version>5.1.44</mysql-connector.version>
     </properties>
 
     <dependencies>
@@ -27,45 +29,38 @@
         </dependency>
         <dependency>
             <groupId>org.jetbrains.kotlin</groupId>
-            <artifactId>kotlin-test-junit</artifactId>
+            <artifactId>kotlin-reflect</artifactId>
             <version>${kotlin.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>${junit.version}</version>
-            <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.jetbrains.ktor</groupId>
-            <artifactId>ktor-netty</artifactId>
+            <groupId>io.ktor</groupId>
+            <artifactId>ktor-server-netty</artifactId>
             <version>${ktor.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.jetbrains.ktor</groupId>
-            <artifactId>ktor-jetty</artifactId>
+            <groupId>io.ktor</groupId>
+            <artifactId>ktor-server-jetty</artifactId>
             <version>${ktor.version}</version>
         </dependency>
         <dependency>
             <groupId>com.google.code.gson</groupId>
             <artifactId>gson</artifactId>
-            <version>2.7</version>
+            <version>${gson.version}</version>
         </dependency>
         <dependency>
             <groupId>com.zaxxer</groupId>
             <artifactId>HikariCP</artifactId>
-            <version>2.6.1</version>
+            <version>${hikaricp.version}</version>
         </dependency>
         <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
-            <version>5.1.41</version>
+            <version>${mysql-connector.version}</version>
         </dependency>
         <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
-            <version>1.2.1</version>
+            <version>${logback.version}</version>
         </dependency>
     </dependencies>
 
@@ -133,7 +128,7 @@
                             </descriptors>
                             <archive>
                                 <manifest>
-                                    <mainClass>org.jetbrains.ktor.netty.DevelopmentHost</mainClass>
+                                    <mainClass>io.ktor.server.netty.DevelopmentEngine</mainClass>
                                 </manifest>
                             </archive>
                         </configuration>
@@ -152,7 +147,7 @@
                             </descriptors>
                             <archive>
                                 <manifest>
-                                    <mainClass>org.jetbrains.ktor.jetty.DevelopmentHost</mainClass>
+                                    <mainClass>io.ktor.server.jetty.DevelopmentEngine</mainClass>
                                 </manifest>
                             </archive>
                         </configuration>

+ 1 - 1
frameworks/Kotlin/ktor/setup-jetty.sh

@@ -2,6 +2,6 @@
 
 fw_depends mysql java maven
 
-./mvnw clean package -DskipTests=true
+./mvnw clean package
 nohup java -jar target/tech-empower-framework-benchmark-1.0-SNAPSHOT-jetty-bundle.jar &
 

+ 1 - 1
frameworks/Kotlin/ktor/setup-netty.sh

@@ -2,6 +2,6 @@
 
 fw_depends mysql java maven
 
-./mvnw clean package -DskipTests=true
+./mvnw clean package
 nohup java -jar target/tech-empower-framework-benchmark-1.0-SNAPSHOT-netty-bundle.jar &
 

+ 1 - 1
frameworks/Kotlin/ktor/src/main/assembly/jetty-bundle.xml

@@ -15,7 +15,7 @@
             <useTransitiveDependencies>true</useTransitiveDependencies>
 
             <excludes>
-                <exclude>*:ktor-netty</exclude>
+                <exclude>*:ktor-server-netty</exclude>
             </excludes>
         </dependencySet>
     </dependencySets>

+ 1 - 1
frameworks/Kotlin/ktor/src/main/assembly/netty-bundle.xml

@@ -14,7 +14,7 @@
             <scope>runtime</scope>
 
             <excludes>
-                <exclude>*:ktor-jetty:*</exclude>
+                <exclude>*:ktor-server-jetty:*</exclude>
             </excludes>
         </dependencySet>
     </dependencySets>

+ 25 - 28
frameworks/Kotlin/ktor/src/main/kotlin/org/jetbrains/ktor/benchmarks/Hello.kt

@@ -3,30 +3,27 @@ package org.jetbrains.ktor.benchmarks
 import com.google.gson.*
 import com.mysql.jdbc.*
 import com.zaxxer.hikari.*
-import kotlinx.coroutines.experimental.*
-import org.jetbrains.ktor.application.*
-import org.jetbrains.ktor.content.*
-import org.jetbrains.ktor.features.*
-import org.jetbrains.ktor.http.*
-import org.jetbrains.ktor.routing.*
-import org.jetbrains.ktor.util.*
-import java.sql.ResultSet.*
+import io.ktor.application.*
+import io.ktor.content.*
+import io.ktor.features.*
+import io.ktor.http.*
+import io.ktor.response.respond
+import io.ktor.response.respondText
+import io.ktor.routing.*
 import java.util.concurrent.*
 import java.util.concurrent.atomic.*
 import javax.sql.*
-
+import kotlinx.coroutines.experimental.*
 
 data class Message(val message: String = "Hello, World!")
 data class World(val id: Int, var randomNumber: Int)
 
 fun Application.main() {
-    val (a, b) = hex("62656e63686d61726b6462757365723a62656e63686d61726b646270617373").toString(Charsets.ISO_8859_1).split(":")
     val gson = GsonBuilder().create()
     val DbRows = 10000
     Driver::class.java.newInstance()
     val pool by lazy {
-        val dbHost = System.getenv("DBHOST") ?: error("DBHOST environment variable is not set")
-        hikari(dbHost, a, b)
+        hikari()
     }
 
     val counter = AtomicInteger()
@@ -35,26 +32,26 @@ fun Application.main() {
     }
     val databaseDispatcher = databaseExecutor.asCoroutineDispatcher()
 
-    install(SamplingCallLogging) {
-        samplingFactor = 50000L
-    }
-
     install(DefaultHeaders)
+
     routing {
-        get("/plaintext") { call ->
-            call.respond(TextContent("Hello, World!", ContentType.Text.Plain, HttpStatusCode.OK))
+
+        get("/plaintext") {
+            call.respondText("Hello, World!", ContentType.Text.Plain)
         }
-        get("/json") { call ->
-            call.respond(TextContent(gson.toJson(Message()), ContentType.Application.Json, HttpStatusCode.OK))
+
+        get("/json") {
+            call.respondText(gson.toJson(Message()), ContentType.Application.Json)
         }
-        get("/db") { call ->
+
+        get("/db") {
             val response = run(databaseDispatcher) {
                 pool.connection.use { connection ->
                     val random = ThreadLocalRandom.current()
                     val queries = call.queries()
                     val result = mutableListOf<World>()
 
-                    connection.prepareStatement("SELECT * FROM World WHERE id = ?", TYPE_FORWARD_ONLY, CONCUR_READ_ONLY).use { statement ->
+                    connection.prepareStatement("SELECT * FROM World WHERE id = ?").use { statement ->
                         for (i in 1..(queries ?: 1)) {
                             statement.setInt(1, random.nextInt(DbRows) + 1)
 
@@ -75,6 +72,7 @@ fun Application.main() {
 
             call.respond(response)
         }
+
         get("/updates") {
             val t = run(databaseDispatcher) {
                 pool.connection.use { connection ->
@@ -82,7 +80,7 @@ fun Application.main() {
                     val random = ThreadLocalRandom.current()
                     val result = mutableListOf<World>()
 
-                    connection.prepareStatement("SELECT * FROM World WHERE id = ?", TYPE_FORWARD_ONLY, CONCUR_READ_ONLY).use { statement ->
+                    connection.prepareStatement("SELECT * FROM World WHERE id = ?").use { statement ->
                         for (i in 1..(queries ?: 1)) {
                             statement.setInt(1, random.nextInt(DbRows) + 1)
 
@@ -124,17 +122,16 @@ fun ApplicationCall.queries() = try {
     1
 }
 
-private fun hikari(dbHost: String, a: String, b: String): DataSource {
+private fun hikari(): DataSource {
     val config = HikariConfig()
-    config.jdbcUrl = "jdbc:mysql://$dbHost:3306/hello_world?useSSL=false"
-    config.username = a
-    config.password = b
+    config.jdbcUrl = "jdbc:mysql://TFB-database:3306/hello_world?useSSL=false"
+    config.username = "benchmarkdbuser"
+    config.password = "benchmarkdbpass"
     config.addDataSourceProperty("cachePrepStmts", "true")
     config.addDataSourceProperty("prepStmtCacheSize", "250")
     config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048")
     config.driverClassName = Driver::class.java.name
     config.connectionTimeout = 10000
     config.maximumPoolSize = 100
-
     return HikariDataSource(config)
 }

+ 0 - 63
frameworks/Kotlin/ktor/src/main/kotlin/org/jetbrains/ktor/benchmarks/SamplingCallLogging.kt

@@ -1,63 +0,0 @@
-package org.jetbrains.ktor.benchmarks
-
-import org.jetbrains.ktor.application.*
-import org.jetbrains.ktor.http.*
-import org.jetbrains.ktor.logging.*
-import org.jetbrains.ktor.pipeline.*
-import org.jetbrains.ktor.request.*
-import org.jetbrains.ktor.util.*
-import java.util.concurrent.atomic.*
-
-// utility logging feature useful for debugging benchmark
-internal class SamplingCallLogging(private val log: ApplicationLog) {
-    private val counter = AtomicLong()
-    var samplingFactor = 10000L
-
-    fun log(call: ApplicationCall) {
-        val v = counter.incrementAndGet()
-        if (v < 0) counter.set(0)
-
-        if (v % samplingFactor == 0L) {
-            logSuccess(call)
-        }
-    }
-
-    private fun logSuccess(call: ApplicationCall) {
-        val status = call.response.status() ?: "Unhandled"
-
-        when (status) {
-            HttpStatusCode.Found -> log.trace("$status: ${call.request.logInfo()} -> ${call.response.headers[HttpHeaders.Location]}")
-            else -> log.trace("$status: ${call.request.logInfo()}")
-        }
-    }
-
-    private fun ApplicationRequest.logInfo() = "${httpMethod.value} - ${path()}"
-
-    companion object : ApplicationFeature<Application, SamplingCallLogging, SamplingCallLogging> {
-        override val key = AttributeKey<SamplingCallLogging>("SamplingCallLogging")
-
-        override fun install(pipeline: Application, configure: SamplingCallLogging.() -> Unit): SamplingCallLogging {
-            pipeline.environment.monitor.logEvents()
-
-            val feature = SamplingCallLogging(pipeline.log)
-            configure(feature)
-
-            val loggingPhase = PipelinePhase("SLogging")
-
-            pipeline.phases.insertBefore(ApplicationCallPipeline.Infrastructure, loggingPhase)
-            pipeline.intercept(loggingPhase) { call ->
-                proceed()
-                feature.log(call)
-            }
-
-            return feature
-        }
-
-        private fun ApplicationMonitor.logEvents() {
-            applicationStarted += { it.log.trace("Application started: $it") }
-            applicationStopped += { it.log.trace("Application stopped: $it") }
-            applicationStarting += { it.log.trace("Application starting: $it") }
-            applicationStopping += { it.log.trace("Application stopping: $it") }
-        }
-    }
-}

+ 1 - 1
frameworks/Kotlin/ktor/src/main/resources/logback.xml

@@ -5,7 +5,7 @@
         </encoder>
     </appender>
 
-    <root level="trace">
+    <root level="INFO">
         <appender-ref ref="STDOUT"/>
     </root>
 

+ 0 - 8
frameworks/Kotlin/ktor/src/test/kotlin/org/jetbrains/ktor/benchmarks/HelloTest.kt

@@ -1,8 +0,0 @@
-package org.jetbrains.ktor.benchmarks
-
-import org.junit.Test
-import kotlin.test.assertEquals
-
-class HelloTest {
-
-}