Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
He-Pin committed Jan 12, 2025
1 parent d70974c commit d882e14
Showing 1 changed file with 40 additions and 62 deletions.
102 changes: 40 additions & 62 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,10 @@ object benchmark extends Cross[BenchmarkModule](build.scalaVersions) with RunMod
}
}

def runBenchmark() = T.command {
if (os.proc("which", "wrk").call(check = false).exitCode != 0) {
println("Error: wrk is not installed. Please install wrk first.")
sys.exit(1)
}

val duration = "30s"
val threads = "4"
val connections = "100"
val url = "http://localhost:8080/"

println("Testing with regular threads...")

val projectRoot = T.workspace
println("projectRoot: " + projectRoot)

def runMillBackground(example: String, vt:Boolean) = {
def runBenchMark(projectRoot: os.Path, example: String, vt: Boolean) = {
def runMillBackground(example: String, vt: Boolean) = {
println(s"Running $example with vt: $vt")

println("projectRoot: " + projectRoot)
os.proc(
"mill",
s"example.$example.app[$scala213].run")
Expand All @@ -138,54 +123,45 @@ object benchmark extends Cross[BenchmarkModule](build.scalaVersions) with RunMod
stderr = os.Inherit)
}

for (example <- Seq(
"staticFilesWithLoom",
"todoDbWithLoom",
"minimalApplicationWithLoom")) {
val duration = "30s"
val threads = "4"
val connections = "100"
val url = "http://localhost:8080/"
val serverApp = runMillBackground(example, vt)

val regularApp = runMillBackground(example, vt = false)
println(s"Waiting for server to start..., vt:$vt")
if (!waitForServer(url)) {
serverApp.destroy()
println("Failed to start regular server")
sys.exit(1)
}

println("Waiting for regular server to start...")
if (!waitForServer(url)) {
regularApp.destroy()
println("Failed to start regular server")
sys.exit(1)
}
val results = os.proc("wrk",
"-t", threads,
"-c", connections,
"-d", duration,
url
).call(stderr = os.Pipe)
serverApp.destroy()

println("target server started, starting run benchmark with wrk")
val regularResults = os.proc("wrk",
"-t", threads,
"-c", connections,
"-d", duration,
url
).call(stderr = os.Pipe)
regularApp.destroy()

println("\nRegular Threads Results:")
println(regularResults.out.text())

Thread.sleep(1000)
println("\nTesting with virtual threads, please use Java 21+...")
val virtualApp = runMillBackground(example, vt = true)

println("Waiting for virtual server to start...")
if (!waitForServer(url)) {
virtualApp.destroy()
println("Failed to start virtual server")
sys.exit(1)
}
println(s"\nResults with $vt:")
println(results.out.text())
}

println("target server started, starting run benchmark with wrk")
val virtualResults = os.proc("wrk",
"-t", threads,
"-c", connections,
"-d", duration,
url
).call(stderr = os.Pipe)
virtualApp.destroy()

println("\nVirtual Threads Results:")
println(virtualResults.out.text())
def runBenchmarks() = T.command {
val projectRoot = T.workspace
if (os.proc("which", "wrk").call(check = false).exitCode != 0) {
println("Error: wrk is not installed. Please install wrk first.")
sys.exit(1)
}
for (example <- Seq(
"staticFilesWithLoom",
"todoDbWithLoom",
"minimalApplicationWithLoom")) {
println(s"target server started, starting run benchmark with wrk for :$example with VT:false")
runBenchMark(projectRoot, example, vt = false)
println(s"target server started, starting run benchmark with wrk for :$example with VT:true")
runBenchMark(projectRoot, example, vt = true)
}

}
Expand All @@ -196,6 +172,8 @@ trait LocalModule extends CrossScalaModule{
def moduleDeps = Seq(cask(crossScalaVersion))
}



def zippedExamples = T {
val vcsState = VcsVersion.vcsState()

Expand Down

0 comments on commit d882e14

Please sign in to comment.