Skip to content

Commit 071bb2b

Browse files
committed
Add kyo-tapir
1 parent 2d1364b commit 071bb2b

File tree

9 files changed

+147
-0
lines changed

9 files changed

+147
-0
lines changed

frameworks/Scala/kyo-tapir/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Kyo Tapir Benchmarking Test
2+
3+
This is a simple test to benchmark the performance of the Kyo and Tapir libraries in Scala.
4+
5+
### Test Type Implementation Source Code
6+
7+
* [JSON](src/main/scala/Main.scala)
8+
* [PLAINTEXT](src/main/scala/Main.scala)
9+
10+
## Software Versions
11+
12+
* [Java OpenJDK 21](https://adoptium.net/temurin/releases/)
13+
* [Scala 3.6.3](https://www.scala-lang.org/)
14+
* [Kyo 0.16.2](https://github.com/getkyo/kyo)
15+
* [Tapir 1.11.15](https://tapir.softwaremill.com)
16+
* [ZIO Json 0.7.32](https://zio.dev/zio-json/)
17+
18+
## Test URLs
19+
20+
* JSON - http://localhost:9999/json
21+
* PLAINTEXT - http://localhost:9999/plaintext
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"framework": "kyo-tapir",
3+
"tests": [
4+
{
5+
"default": {
6+
"plaintext_url": "/plaintext",
7+
"json_url": "/json",
8+
"port": 9999,
9+
"database": "None",
10+
"approach": "Realistic",
11+
"classification": "Micro",
12+
"framework": "kyo-tapir",
13+
"language": "Scala",
14+
"flavor": "None",
15+
"orm": "Raw",
16+
"platform": "Netty",
17+
"webserver": "None",
18+
"database_os": "Linux",
19+
"os": "Linux",
20+
"display_name": "kyo-tapir",
21+
"notes": "",
22+
"versus": "None"
23+
}
24+
}
25+
]
26+
}

frameworks/Scala/kyo-tapir/build.sbt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name := "kyo-tapir"
2+
version := "1.0.0"
3+
scalaVersion := "3.6.3"
4+
lazy val root = (project in file("."))
5+
.settings(
6+
libraryDependencies ++= Seq(
7+
"io.getkyo" %% "kyo-tapir" % "0.16.2",
8+
"com.softwaremill.sttp.tapir" %% "tapir-json-zio" % "1.11.15",
9+
"dev.zio" %% "zio-json" % "0.7.32"
10+
),
11+
assembly / assemblyMergeStrategy := {
12+
case x if x.contains("io.netty.versions.properties") => MergeStrategy.discard
13+
case x =>
14+
val oldStrategy = (assembly / assemblyMergeStrategy).value
15+
oldStrategy(x)
16+
}
17+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[framework]
2+
name = "kyo-tapir"
3+
4+
[main]
5+
urls.plaintext = "/plaintext"
6+
urls.json = "/json"
7+
approach = "Realistic"
8+
classification = "Micro"
9+
database = "None"
10+
database_os = "Linux"
11+
os = "Linux"
12+
orm = "Raw"
13+
platform = "Netty"
14+
webserver = "None"
15+
versus = "None"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM sbtscala/scala-sbt:eclipse-temurin-21.0.6_7_1.10.7_3.6.3
2+
3+
WORKDIR /kyo-tapir
4+
COPY src src
5+
COPY project project
6+
COPY build.sbt build.sbt
7+
RUN sbt assembly
8+
9+
EXPOSE 9999
10+
CMD ["java", "-Xms2G", "-Xmx2G", "-server", "-Dio.netty.leakDetection.level=disabled", "-Dio.netty.recycler.maxCapacityPerThread=0", "-jar", "/kyo-tapir/target/scala-3.6.3/kyo-tapir-assembly-1.0.0.jar"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version = 1.10.7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import kyo.*
2+
import sttp.model.{Header, HeaderNames}
3+
import sttp.tapir.*
4+
import sttp.tapir.json.zio.*
5+
import sttp.tapir.server.netty.*
6+
7+
object Main extends KyoApp {
8+
private val STATIC_SERVER_NAME = "kyo-tapir"
9+
10+
private val plainTextMessage: String = "Hello, World!"
11+
12+
run {
13+
val plaintextRoute: Unit < Routes =
14+
Routes.add(
15+
_.get.in("plaintext")
16+
.out(header(HeaderNames.Server, STATIC_SERVER_NAME))
17+
.out(header[String](HeaderNames.Date))
18+
.out(stringBody)
19+
) { _ =>
20+
for {
21+
now <- Clock.now
22+
} yield Header.toHttpDateString(now.toJava) -> plainTextMessage
23+
}
24+
25+
val jsonRoute: Unit < Routes =
26+
Routes.add(
27+
_.get.in("json")
28+
.out(header(HeaderNames.Server, STATIC_SERVER_NAME))
29+
.out(header[String](HeaderNames.Date))
30+
.out(jsonBody[Payload])
31+
) { _ =>
32+
for {
33+
now <- Clock.now
34+
} yield Header.toHttpDateString(now.toJava) -> Payload(plainTextMessage)
35+
}
36+
37+
val config = NettyConfig.default
38+
.withSocketKeepAlive
39+
.copy(lingerTimeout = None)
40+
41+
val server = NettyKyoServer(config).host("0.0.0.0").port(9999)
42+
43+
val binding: NettyKyoServerBinding < Async =
44+
Routes.run(server)(plaintextRoute.andThen(jsonRoute))
45+
46+
binding
47+
}
48+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sttp.tapir.Schema
2+
import zio.json.*
3+
4+
case class Payload(message: String)
5+
object Payload {
6+
given JsonCodec[Payload] = DeriveJsonCodec.gen
7+
given Schema[Payload] = Schema.derived
8+
}

0 commit comments

Comments
 (0)