Skip to content

Commit e77eb70

Browse files
committed
Add tapir framework and its variants
1 parent a0ebdee commit e77eb70

File tree

19 files changed

+700
-0
lines changed

19 files changed

+700
-0
lines changed

frameworks/Scala/tapir/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Tapir Benchmarking Test
2+
3+
This is a simple test to benchmark the performance of the Tapir libraries along with different backends in Scala.
4+
5+
### Test Type Implementation Source Code
6+
7+
* JSON
8+
* PLAINTEXT
9+
10+
## Software Versions
11+
12+
* [Java OpenJDK 21](https://adoptium.net/temurin/releases/)
13+
* [Scala 3.6.4](https://www.scala-lang.org/)
14+
* [Tapir 1.11.24](https://tapir.softwaremill.com)
15+
16+
### Backend Implementations
17+
* [Tapir running as zio-http server](https://tapir.softwaremill.com/en/latest/server/ziohttp.html)
18+
* [Tapir running as http4s server](https://tapir.softwaremill.com/en/latest/server/http4s.html)
19+
* [as an http4s server using ZIO](https://tapir.softwaremill.com/en/latest/server/zio-http4s.html)
20+
* [Tapir running as Netty-based server(Cats)](https://tapir.softwaremill.com/en/latest/server/netty.html)
21+
* [Tapir running as Netty-based server(ZIO)](https://tapir.softwaremill.com/en/latest/server/netty.html)
22+
* [Tapir running as pekko-http server](https://tapir.softwaremill.com/en/latest/server/pekkohttp.html)
23+
24+
## Test URLs
25+
26+
* JSON - http://localhost:8080/json
27+
* PLAINTEXT - http://localhost:8080/plaintext
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"framework": "tapir",
3+
"tests": [
4+
{
5+
"default": {
6+
"plaintext_url": "/plaintext",
7+
"json_url": "/json",
8+
"port": 8080,
9+
"database": "None",
10+
"approach": "Realistic",
11+
"classification": "Micro",
12+
"framework": "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": "tapir as zio-http server",
21+
"notes": "https://tapir.softwaremill.com/en/latest/server/ziohttp.html",
22+
"versus": "None"
23+
},
24+
"http4s": {
25+
"plaintext_url": "/plaintext",
26+
"json_url": "/json",
27+
"port": 8080,
28+
"database": "None",
29+
"approach": "Realistic",
30+
"classification": "Micro",
31+
"framework": "tapir",
32+
"language": "Scala",
33+
"flavor": "None",
34+
"orm": "Raw",
35+
"platform": "Netty",
36+
"webserver": "None",
37+
"database_os": "Linux",
38+
"os": "Linux",
39+
"display_name": "tapir as http4s server",
40+
"notes": "https://tapir.softwaremill.com/en/latest/server/http4s.html",
41+
"versus": "None"
42+
},
43+
"http4s-zio": {
44+
"plaintext_url": "/plaintext",
45+
"json_url": "/json",
46+
"port": 8080,
47+
"database": "None",
48+
"approach": "Realistic",
49+
"classification": "Micro",
50+
"framework": "tapir",
51+
"language": "Scala",
52+
"flavor": "None",
53+
"orm": "Raw",
54+
"platform": "Netty",
55+
"webserver": "None",
56+
"database_os": "Linux",
57+
"os": "Linux",
58+
"display_name": "tapir as http4s server using ZIO",
59+
"notes": "https://tapir.softwaremill.com/en/latest/server/zio-http4s.html",
60+
"versus": "None"
61+
},
62+
"netty-cats": {
63+
"plaintext_url": "/plaintext",
64+
"json_url": "/json",
65+
"port": 8080,
66+
"database": "None",
67+
"approach": "Realistic",
68+
"classification": "Micro",
69+
"framework": "tapir",
70+
"language": "Scala",
71+
"flavor": "None",
72+
"orm": "Raw",
73+
"platform": "Netty",
74+
"webserver": "None",
75+
"database_os": "Linux",
76+
"os": "Linux",
77+
"display_name": "tapir as netty(cats) server",
78+
"notes": "https://tapir.softwaremill.com/en/latest/server/netty.html",
79+
"versus": "None"
80+
},
81+
"netty-zio": {
82+
"plaintext_url": "/plaintext",
83+
"json_url": "/json",
84+
"port": 8080,
85+
"database": "None",
86+
"approach": "Realistic",
87+
"classification": "Micro",
88+
"framework": "tapir",
89+
"language": "Scala",
90+
"flavor": "None",
91+
"orm": "Raw",
92+
"platform": "Netty",
93+
"webserver": "None",
94+
"database_os": "Linux",
95+
"os": "Linux",
96+
"display_name": "tapir as netty(zio) server",
97+
"notes": "https://tapir.softwaremill.com/en/latest/server/netty.html",
98+
"versus": "None"
99+
},
100+
"pekko-http": {
101+
"plaintext_url": "/plaintext",
102+
"json_url": "/json",
103+
"port": 8080,
104+
"database": "None",
105+
"approach": "Realistic",
106+
"classification": "Micro",
107+
"framework": "tapir",
108+
"language": "Scala",
109+
"flavor": "None",
110+
"orm": "Raw",
111+
"platform": "Netty",
112+
"webserver": "None",
113+
"database_os": "Linux",
114+
"os": "Linux",
115+
"display_name": "tapir as netty(zio) server",
116+
"notes": "https://tapir.softwaremill.com/en/latest/server/pekkohttp.html",
117+
"versus": "None"
118+
}
119+
}
120+
]
121+
}

frameworks/Scala/tapir/build.sbt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name := "tapir-benchmark"
2+
3+
ThisBuild / version := "1.0.0"
4+
ThisBuild / scalaVersion := "3.6.4"
5+
6+
val tapirVersion = "1.11.24"
7+
8+
val commonAssemblySettings = assembly / assemblyMergeStrategy := {
9+
case x if x.contains("io.netty.versions.properties") => MergeStrategy.discard
10+
case x if x.contains("module-info.class") => MergeStrategy.discard
11+
case x =>
12+
val oldStrategy = (assembly / assemblyMergeStrategy).value
13+
oldStrategy(x)
14+
}
15+
16+
lazy val common = (project in file("common"))
17+
.settings(
18+
name := "tapir-benchmark-common"
19+
)
20+
21+
lazy val `zio-http-server` = (project in file("zio-http-server"))
22+
.dependsOn(common)
23+
.settings(
24+
name := "tapir-zio-http-server",
25+
libraryDependencies ++= Seq(
26+
"com.softwaremill.sttp.tapir" %% "tapir-zio-http-server" % tapirVersion,
27+
"com.softwaremill.sttp.tapir" %% "tapir-json-zio" % tapirVersion
28+
),
29+
commonAssemblySettings
30+
)
31+
32+
lazy val `http4s-server` = (project in file("http4s-server"))
33+
.dependsOn(common)
34+
.settings(
35+
name := "tapir-http4s-server",
36+
libraryDependencies ++= Seq(
37+
"com.softwaremill.sttp.tapir" %% "tapir-http4s-server" % tapirVersion,
38+
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion,
39+
"org.http4s" %% "http4s-blaze-server" % "0.23.17",
40+
),
41+
commonAssemblySettings
42+
)
43+
44+
lazy val `http4s-server-zio` = (project in file("http4s-server-zio"))
45+
.dependsOn(common)
46+
.settings(
47+
name := "tapir-http4s-server-zio",
48+
libraryDependencies ++= Seq(
49+
"com.softwaremill.sttp.tapir" %% "tapir-http4s-server-zio" % tapirVersion,
50+
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion,
51+
"org.http4s" %% "http4s-blaze-server" % "0.23.17",
52+
"dev.zio" %% "zio-interop-cats" % "23.1.0.5"
53+
),
54+
commonAssemblySettings
55+
)
56+
57+
lazy val `netty-zio-server` = (project in file("netty-zio-server"))
58+
.dependsOn(common)
59+
.settings(
60+
name := "tapir-netty-zio-server",
61+
libraryDependencies ++= Seq(
62+
"com.softwaremill.sttp.tapir" %% "tapir-netty-server-zio" % tapirVersion,
63+
"com.softwaremill.sttp.tapir" %% "tapir-json-zio" % tapirVersion,
64+
),
65+
commonAssemblySettings
66+
)
67+
68+
lazy val `netty-cats-server` = (project in file("netty-cats-server"))
69+
.dependsOn(common)
70+
.settings(
71+
name := "tapir-netty-cats-server",
72+
libraryDependencies ++= Seq(
73+
"com.softwaremill.sttp.tapir" %% "tapir-netty-server-cats" % tapirVersion,
74+
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion,
75+
"org.http4s" %% "http4s-blaze-server" % "0.23.17",
76+
),
77+
commonAssemblySettings
78+
)
79+
80+
lazy val `pekko-http-server` = (project in file("pekko-http-server"))
81+
.dependsOn(common)
82+
.settings(
83+
name := "tapir-pekko-http-server",
84+
libraryDependencies ++= Seq(
85+
"com.softwaremill.sttp.tapir" %% "tapir-pekko-http-server" % tapirVersion,
86+
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion,
87+
),
88+
commonAssemblySettings
89+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
case class Payload(message: String)

frameworks/Scala/tapir/config.toml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[framework]
2+
name = "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"
16+
17+
[http4s]
18+
urls.plaintext = "/plaintext"
19+
urls.json = "/json"
20+
approach = "Realistic"
21+
classification = "Micro"
22+
database = "None"
23+
database_os = "Linux"
24+
os = "Linux"
25+
orm = "Raw"
26+
platform = "Netty"
27+
webserver = "None"
28+
versus = "None"
29+
30+
[http4s-zio]
31+
urls.plaintext = "/plaintext"
32+
urls.json = "/json"
33+
approach = "Realistic"
34+
classification = "Micro"
35+
database = "None"
36+
database_os = "Linux"
37+
os = "Linux"
38+
orm = "Raw"
39+
platform = "Netty"
40+
webserver = "None"
41+
versus = "None"
42+
43+
[netty-cats]
44+
urls.plaintext = "/plaintext"
45+
urls.json = "/json"
46+
approach = "Realistic"
47+
classification = "Micro"
48+
database = "None"
49+
database_os = "Linux"
50+
os = "Linux"
51+
orm = "Raw"
52+
platform = "Netty"
53+
webserver = "None"
54+
versus = "None"
55+
56+
[netty-zio]
57+
urls.plaintext = "/plaintext"
58+
urls.json = "/json"
59+
approach = "Realistic"
60+
classification = "Micro"
61+
database = "None"
62+
database_os = "Linux"
63+
os = "Linux"
64+
orm = "Raw"
65+
platform = "Netty"
66+
webserver = "None"
67+
versus = "None"
68+
69+
[pekko-http]
70+
urls.plaintext = "/plaintext"
71+
urls.json = "/json"
72+
approach = "Realistic"
73+
classification = "Micro"
74+
database = "None"
75+
database_os = "Linux"
76+
os = "Linux"
77+
orm = "Raw"
78+
platform = "Netty"
79+
webserver = "None"
80+
versus = "None"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import io.circe.generic.auto.*
2+
import org.http4s.HttpRoutes
3+
import org.http4s.blaze.server.BlazeServerBuilder
4+
import org.http4s.server.Router
5+
import sttp.model.{Header, HeaderNames, StatusCode}
6+
import sttp.tapir.generic.auto.*
7+
import sttp.tapir.json.circe.*
8+
import sttp.tapir.server.http4s.ztapir.ZHttp4sServerInterpreter
9+
import sttp.tapir.ztapir.*
10+
import zio.*
11+
12+
import java.time.format.DateTimeFormatter
13+
import java.time.{Clock, LocalDateTime, ZoneOffset, ZonedDateTime}
14+
import java.util.Date
15+
import java.util.concurrent.locks.LockSupport
16+
import scala.concurrent.ExecutionContext
17+
import zio.interop.catz.*
18+
19+
object TapirHttp4sServerZioBenchmark extends ZIOAppDefault:
20+
private val STATIC_SERVER_NAME = "tapir-http4s-server-zio"
21+
22+
private val plainTextMessage: String = "Hello, World!"
23+
24+
private val plaintextEndpoint: ZServerEndpoint[Any, Any] =
25+
endpoint.get.in("plaintext")
26+
.out(header(HeaderNames.Server, STATIC_SERVER_NAME))
27+
.out(stringBody)
28+
.zServerLogic(_ => ZIO.succeed(plainTextMessage))
29+
30+
private val jsonEndpoint: ZServerEndpoint[Any, Any] =
31+
endpoint.get.in("json")
32+
.out(header(HeaderNames.Server, STATIC_SERVER_NAME))
33+
.out(jsonBody[Payload])
34+
.zServerLogic(_ => ZIO.succeed(Payload(plainTextMessage)))
35+
36+
37+
private val declaredPort = 8080
38+
private val declaredHost = "0.0.0.0"
39+
40+
private val routes: HttpRoutes[Task] = ZHttp4sServerInterpreter()
41+
.from(List(plaintextEndpoint, jsonEndpoint))
42+
.toRoutes
43+
44+
implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
45+
46+
override def run: URIO[Any, ExitCode] =
47+
ZIO.executor.flatMap(executor =>
48+
BlazeServerBuilder[Task]
49+
.withExecutionContext(executor.asExecutionContext)
50+
.bindHttp(8080, declaredHost)
51+
.withHttpApp(Router("/" -> routes).orNotFound)
52+
.serve
53+
.compile
54+
.drain
55+
).exitCode

0 commit comments

Comments
 (0)