@@ -22,16 +22,18 @@ trait Client(name: Uid) {
22
22
def read (key : String ): Unit = handleOp(KVOperation .Read (key))
23
23
def write (key : String , value : String ): Unit = handleOp(KVOperation .Write (key, value))
24
24
25
- def multiget (key : String , times : Int ): Unit = {
25
+ def multiget (key : String , times : Int , offset : Int = 0 ): Unit = {
26
26
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))
28
28
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 " )
29
30
}
30
31
31
- def multiput (key : String , value : String , times : Int ): Unit = {
32
+ def multiput (key : String , value : String , times : Int , offset : Int = 0 ): Unit = {
32
33
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))
34
35
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 " )
35
37
}
36
38
37
39
def mixed (min : Int , max : Int , times : Int = 1 ): Unit = {
@@ -44,10 +46,11 @@ trait Client(name: Uid) {
44
46
write(f " key $num" , f " value $num" )
45
47
}
46
48
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 " )
47
50
}
48
51
49
52
def benchmark (mode : BenchmarkMode , times : Int , min : Int = 1 , max : Int = 10000 ): Unit = {
50
- printResults = false
53
+ // printResults = false
51
54
52
55
println(" Initializing" )
53
56
@@ -68,11 +71,18 @@ trait Client(name: Uid) {
68
71
69
72
doBenchmark = true
70
73
74
+ val start = System .currentTimeMillis()
75
+
71
76
mode match
72
77
case BenchmarkMode .Read => multiget(" key%n" , times)
73
78
case BenchmarkMode .Write => multiput(" key%n" , " value%n" , times)
74
79
case BenchmarkMode .Mixed => mixed(min, max, times)
75
80
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
+
76
86
saveBenchmark(name)
77
87
}
78
88
@@ -82,7 +92,7 @@ trait Client(name: Uid) {
82
92
println(" Initializing" )
83
93
84
94
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 )
86
96
case BenchmarkMode .Write =>
87
97
88
98
println(" Warmup" )
@@ -91,23 +101,31 @@ trait Client(name: Uid) {
91
101
92
102
while (System .currentTimeMillis() - warmupStart) < warmup * 1000 do {
93
103
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 )
97
107
}
98
108
99
109
println(" Measurement" )
100
110
101
111
val measurementStart = System .currentTimeMillis()
102
112
doBenchmark = true
103
113
114
+ var queries = 0
115
+
104
116
while (System .currentTimeMillis() - measurementStart) < measurement * 1000 do {
105
117
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
109
122
}
110
123
124
+ val duration = System .currentTimeMillis() - measurementStart
125
+
126
+ println(s " \n Did $queries queries in ${duration}ms " )
127
+ println(s " Did ${queries / (duration / 1000 )} op/s " )
128
+
111
129
saveBenchmark(name)
112
130
}
113
131
0 commit comments