浏览代码

Upgrade ktor version and add "Coroutine IO" (CIO) engine variant (#3200)

Ilya Ryzhenkov 7 年之前
父节点
当前提交
7d264277b5

+ 5 - 0
frameworks/Kotlin/ktor/README.md

@@ -1,3 +1,8 @@
+# Ktor
+
+Ktor is a framework for building servers and clients in connected systems using Kotlin programming language.
+More information is available at [ktor.io](http://ktor.io). 
+
 # Setup
 # Setup
 
 
 * Java 8
 * Java 8

+ 24 - 0
frameworks/Kotlin/ktor/benchmark_config.json

@@ -49,6 +49,30 @@
         "display_name": "ktor-jetty",
         "display_name": "ktor-jetty",
         "notes": "http://ktor.io/",
         "notes": "http://ktor.io/",
         "versus": "servlet"
         "versus": "servlet"
+      },
+      "cio": {
+        "plaintext_url": "/plaintext",
+        "json_url": "/json",
+        "db_url": "/db",
+        "query_url": "/db?queries=",
+        "update_url": "/updates?queries=",
+        "fortune_url": "/fortunes",
+
+        "port": 9090,
+        "setup_file": "setup-cio",
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "MySQL",
+        "framework": "ktor",
+        "language": "Kotlin",
+        "orm": "Raw",
+        "platform": "ktor",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "ktor-cio",
+        "notes": "http://ktor.io/",
+        "versus": ""
       }
       }
     }
     }
   ]
   ]

+ 31 - 8
frameworks/Kotlin/ktor/pom.xml

@@ -15,8 +15,8 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <gson.version>2.8.2</gson.version>
         <gson.version>2.8.2</gson.version>
         <hikaricp.version>2.7.4</hikaricp.version>
         <hikaricp.version>2.7.4</hikaricp.version>
-        <kotlin.version>1.2.0</kotlin.version>
-        <ktor.version>0.9.0</ktor.version>
+        <kotlin.version>1.2.21</kotlin.version>
+        <ktor.version>0.9.1-alpha-10</ktor.version>
         <logback.version>1.2.3</logback.version>
         <logback.version>1.2.3</logback.version>
         <mysql-connector.version>5.1.44</mysql-connector.version>
         <mysql-connector.version>5.1.44</mysql-connector.version>
     </properties>
     </properties>
@@ -24,7 +24,7 @@
     <dependencies>
     <dependencies>
         <dependency>
         <dependency>
             <groupId>org.jetbrains.kotlin</groupId>
             <groupId>org.jetbrains.kotlin</groupId>
-            <artifactId>kotlin-stdlib-jre8</artifactId>
+            <artifactId>kotlin-stdlib-jdk8</artifactId>
             <version>${kotlin.version}</version>
             <version>${kotlin.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
@@ -39,12 +39,17 @@
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>io.ktor</groupId>
             <groupId>io.ktor</groupId>
-            <artifactId>ktor-html-builder</artifactId>
+            <artifactId>ktor-server-jetty</artifactId>
             <version>${ktor.version}</version>
             <version>${ktor.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>io.ktor</groupId>
             <groupId>io.ktor</groupId>
-            <artifactId>ktor-server-jetty</artifactId>
+            <artifactId>ktor-server-cio</artifactId>
+            <version>${ktor.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>io.ktor</groupId>
+            <artifactId>ktor-html-builder</artifactId>
             <version>${ktor.version}</version>
             <version>${ktor.version}</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
@@ -71,7 +76,6 @@
 
 
     <build>
     <build>
         <sourceDirectory>src/main/kotlin</sourceDirectory>
         <sourceDirectory>src/main/kotlin</sourceDirectory>
-        <testSourceDirectory>src/test/kotlin</testSourceDirectory>
 
 
         <plugins>
         <plugins>
             <plugin>
             <plugin>
@@ -86,8 +90,8 @@
                             <goal>compile</goal>
                             <goal>compile</goal>
                         </goals>
                         </goals>
                         <configuration>
                         <configuration>
-                            <languageVersion>1.1</languageVersion>
-                            <apiVersion>1.1</apiVersion>
+                            <languageVersion>1.2</languageVersion>
+                            <apiVersion>1.2</apiVersion>
                             <args>
                             <args>
                                 <arg>-Xcoroutines=enable</arg>
                                 <arg>-Xcoroutines=enable</arg>
                             </args>
                             </args>
@@ -119,6 +123,25 @@
                 <version>3.0.0</version>
                 <version>3.0.0</version>
 
 
                 <executions>
                 <executions>
+                    <execution>
+                        <id>cio</id>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+
+                        <phase>package</phase>
+
+                        <configuration>
+                            <descriptors>
+                                <descriptor>src/main/assembly/cio-bundle.xml</descriptor>
+                            </descriptors>
+                            <archive>
+                                <manifest>
+                                    <mainClass>io.ktor.server.cio.DevelopmentEngine</mainClass>
+                                </manifest>
+                            </archive>
+                        </configuration>
+                    </execution>
                     <execution>
                     <execution>
                         <id>netty</id>
                         <id>netty</id>
                         <goals>
                         <goals>

+ 7 - 0
frameworks/Kotlin/ktor/setup-cio.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+fw_depends mysql java maven
+
+./mvnw clean package
+nohup java -jar target/tech-empower-framework-benchmark-1.0-SNAPSHOT-cio-bundle.jar &
+

+ 30 - 0
frameworks/Kotlin/ktor/src/main/assembly/cio-bundle.xml

@@ -0,0 +1,30 @@
+<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+    <id>cio-bundle</id>
+    <formats>
+        <format>jar</format>
+    </formats>
+
+    <includeBaseDirectory>false</includeBaseDirectory>
+
+    <dependencySets>
+        <dependencySet>
+            <unpack>true</unpack>
+            <scope>runtime</scope>
+
+            <useTransitiveDependencies>true</useTransitiveDependencies>
+
+            <excludes>
+                <exclude>*:ktor-server-netty</exclude>
+                <exclude>*:ktor-server-jetty</exclude>
+            </excludes>
+        </dependencySet>
+    </dependencySets>
+
+    <fileSets>
+        <fileSet>
+            <directory>${project.build.outputDirectory}</directory>
+            <outputDirectory>/</outputDirectory>
+        </fileSet>
+    </fileSets>
+</assembly>

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

@@ -16,6 +16,7 @@
 
 
             <excludes>
             <excludes>
                 <exclude>*:ktor-server-netty</exclude>
                 <exclude>*:ktor-server-netty</exclude>
+                <exclude>*:ktor-server-cio</exclude>
             </excludes>
             </excludes>
         </dependencySet>
         </dependencySet>
     </dependencySets>
     </dependencySets>

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

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

+ 4 - 5
frameworks/Kotlin/ktor/src/main/kotlin/org/jetbrains/ktor/benchmarks/Hello.kt

@@ -36,10 +36,9 @@ fun Application.main() {
 
 
     install(DefaultHeaders)
     install(DefaultHeaders)
 
 
-    val okContent = TextContent("Hello, World!", ContentType.Text.Plain, HttpStatusCode.OK).also { it.contentLength() }
+    val okContent = TextContent("Hello, World!", ContentType.Text.Plain, HttpStatusCode.OK).also { it.contentLength }
 
 
     routing {
     routing {
-
         get("/plaintext") {
         get("/plaintext") {
             call.respond(okContent)
             call.respond(okContent)
         }
         }
@@ -50,7 +49,7 @@ fun Application.main() {
         }
         }
 
 
         get("/db") {
         get("/db") {
-            val response = run(databaseDispatcher) {
+            val response = withContext(databaseDispatcher) {
                 pool.connection.use { connection ->
                 pool.connection.use { connection ->
                     val random = ThreadLocalRandom.current()
                     val random = ThreadLocalRandom.current()
                     val queries = call.queries()
                     val queries = call.queries()
@@ -80,7 +79,7 @@ fun Application.main() {
 
 
         get("/fortunes") {
         get("/fortunes") {
             val result = mutableListOf<Fortune>()
             val result = mutableListOf<Fortune>()
-            run(databaseDispatcher) {
+            withContext(databaseDispatcher) {
                 pool.connection.use { connection ->
                 pool.connection.use { connection ->
                     connection.prepareStatement("select id, message from fortune").use { statement ->
                     connection.prepareStatement("select id, message from fortune").use { statement ->
                         statement.executeQuery().use { rs ->
                         statement.executeQuery().use { rs ->
@@ -114,7 +113,7 @@ fun Application.main() {
         }
         }
 
 
         get("/updates") {
         get("/updates") {
-            val t = run(databaseDispatcher) {
+            val t = withContext(databaseDispatcher) {
                 pool.connection.use { connection ->
                 pool.connection.use { connection ->
                     val queries = call.queries()
                     val queries = call.queries()
                     val random = ThreadLocalRandom.current()
                     val random = ThreadLocalRandom.current()

+ 1 - 0
frameworks/Kotlin/ktor/src/main/resources/application.conf

@@ -3,6 +3,7 @@ ktor {
         port = 9090
         port = 9090
         autoreload = false
         autoreload = false
         watch = [ ]
         watch = [ ]
+        shareWorkGroup = true
     }
     }
 
 
     application {
     application {