Skip to content

Commit d8380df

Browse files
committed
update timed benchmark mode
1 parent c49979d commit d8380df

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

Modules/Examples/Protocol Benchmarks/src/main/scala/probench/cli.scala

+8
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,18 @@ object cli {
236236
abort.closeRequest = true
237237
executor.shutdownNow()
238238
},
239+
subcommand("etcd-client-timed", "starts a benchmark client") {
240+
val client = EtcdClient(name.value, endpoints.value)
241+
242+
client.benchmarkTimed(warmup.value, measurement.value, mode.value)
243+
244+
executor.shutdownNow()
245+
},
239246
subcommand("etcd-client", "starts a client to interact with an etcd cluster") {
240247
val client = EtcdClient(name.value, endpoints.value)
241248

242249
ClientCLI(name.value, client).startCLI()
250+
243251
executor.shutdownNow()
244252
},
245253
)

Modules/Examples/Protocol Benchmarks/src/main/scala/probench/clients/Client.scala

+30-12
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ trait Client(name: Uid) {
2222
def read(key: String): Unit = handleOp(KVOperation.Read(key))
2323
def write(key: String, value: String): Unit = handleOp(KVOperation.Write(key, value))
2424

25-
def multiget(key: String, times: Int): Unit = {
25+
def multiget(key: String, times: Int, offset: Int = 0): Unit = {
2626
val start = System.nanoTime()
27-
for i <- 1 to times do read(key.replace("%n", i.toString))
27+
for i <- (offset + 1) to (times + offset) do read(key.replace("%n", i.toString))
2828
println(s"Did $times get queries in ${(System.nanoTime() - start) / 1_000_000}ms")
29+
println(s"Did ${times.toDouble / ((System.nanoTime() - start) / 1_000_000_000d)} ops/s")
2930
}
3031

31-
def multiput(key: String, value: String, times: Int): Unit = {
32+
def multiput(key: String, value: String, times: Int, offset: Int = 0): Unit = {
3233
val start = System.nanoTime()
33-
for i <- 1 to times do write(key.replace("%n", i.toString), value.replace("%n", i.toString))
34+
for i <- (offset + 1) to (times + offset) do write(key.replace("%n", i.toString), value.replace("%n", i.toString))
3435
println(s"Did $times put queries in ${(System.nanoTime() - start) / 1_000_000}ms")
36+
println(s"Did ${times.toDouble / ((System.nanoTime() - start) / 1_000_000_000d)} ops/s")
3537
}
3638

3739
def mixed(min: Int, max: Int, times: Int = 1): Unit = {
@@ -44,10 +46,11 @@ trait Client(name: Uid) {
4446
write(f"key$num", f"value$num")
4547
}
4648
println(s"Did $times mixed queries in ${(System.nanoTime() - start) / 1_000_000}ms")
49+
println(s"Did ${times.toDouble / ((System.nanoTime() - start) / 1_000_000_000d)} ops/s")
4750
}
4851

4952
def benchmark(mode: BenchmarkMode, times: Int, min: Int = 1, max: Int = 10000): Unit = {
50-
printResults = false
53+
// printResults = false
5154

5255
println("Initializing")
5356

@@ -68,11 +71,18 @@ trait Client(name: Uid) {
6871

6972
doBenchmark = true
7073

74+
val start = System.currentTimeMillis()
75+
7176
mode match
7277
case BenchmarkMode.Read => multiget("key%n", times)
7378
case BenchmarkMode.Write => multiput("key%n", "value%n", times)
7479
case BenchmarkMode.Mixed => mixed(min, max, times)
7580

81+
val duration = System.currentTimeMillis() - start
82+
83+
println(s"Did $times queries in ${duration}ms")
84+
println(s"Did ${times / (duration / 1000)} op/s")
85+
7686
saveBenchmark(name)
7787
}
7888

@@ -82,7 +92,7 @@ trait Client(name: Uid) {
8292
println("Initializing")
8393

8494
mode match
85-
case BenchmarkMode.Read | BenchmarkMode.Mixed => multiput(s"${name.delegate}-key%n", "value%n", 1000)
95+
case BenchmarkMode.Read | BenchmarkMode.Mixed => multiput("key%n", "value%n", 1000)
8696
case BenchmarkMode.Write =>
8797

8898
println("Warmup")
@@ -91,23 +101,31 @@ trait Client(name: Uid) {
91101

92102
while (System.currentTimeMillis() - warmupStart) < warmup * 1000 do {
93103
mode match
94-
case BenchmarkMode.Read => multiget(s"${name.delegate}-key", 1000)
95-
case BenchmarkMode.Write => multiput(s"${name.delegate}-key", "value", 1000)
96-
case BenchmarkMode.Mixed => mixed(1, 1000, 1000)
104+
case BenchmarkMode.Read => multiget("key%n", 10, Math.round(Math.random() * 990).toInt)
105+
case BenchmarkMode.Write => multiput("key%n", "value%n", 10, Math.round(Math.random() * 990).toInt)
106+
case BenchmarkMode.Mixed => mixed(1, 1000, 10)
97107
}
98108

99109
println("Measurement")
100110

101111
val measurementStart = System.currentTimeMillis()
102112
doBenchmark = true
103113

114+
var queries = 0
115+
104116
while (System.currentTimeMillis() - measurementStart) < measurement * 1000 do {
105117
mode match
106-
case BenchmarkMode.Read => multiget(s"${name.delegate}-key", 1000)
107-
case BenchmarkMode.Write => multiput(s"${name.delegate}-key", "value", 1000)
108-
case BenchmarkMode.Mixed => mixed(1, 1000, 1000)
118+
case BenchmarkMode.Read => multiget("key%n", 10, Math.round(Math.random() * 990).toInt)
119+
case BenchmarkMode.Write => multiput("key%n", "value%n", 10, Math.round(Math.random() * 990).toInt)
120+
case BenchmarkMode.Mixed => mixed(1, 10)
121+
queries += 10
109122
}
110123

124+
val duration = System.currentTimeMillis() - measurementStart
125+
126+
println(s"\nDid $queries queries in ${duration}ms")
127+
println(s"Did ${queries / (duration / 1000)} op/s")
128+
111129
saveBenchmark(name)
112130
}
113131

Modules/Examples/Protocol Benchmarks/src/main/scala/probench/clients/ClientCLI.scala

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ClientCLI(name: Uid, client: Client) {
1818
private val mp: Regex = """mp ([\d_]+)""".r
1919
private val benchmark: Regex = """benchmark""".r
2020
private val saveBenchmark: Regex = """save-benchmark""".r
21+
private val printResults: Regex = """print-results""".r
2122

2223
private def parseInt(str: String): Int = str.replace("_", "").toInt
2324

@@ -38,6 +39,9 @@ class ClientCLI(name: Uid, client: Client) {
3839
client.doBenchmark = true
3940
case Some(saveBenchmark()) =>
4041
client.saveBenchmark(name)
42+
case Some(printResults()) =>
43+
client.printResults = !client.printResults
44+
println(s"Printing Results: ${client.printResults}")
4145
case None | Some("exit") => running = false
4246
case _ =>
4347
println("assuming put")

0 commit comments

Comments
 (0)