Skip to content

Commit

Permalink
feat: latency display avg and p99
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie committed Jul 25, 2024
1 parent 60cb07f commit 0ed9bc6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
11 changes: 7 additions & 4 deletions runner/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,23 @@ func (c *Counter) Report(title string, totalns int64, concurrent int, total int6
tps = float64(c.Total) / (float64(totalns) / float64(sec))
}

var sum float64
costs := make([]float64, len(c.costs))
for i := range c.costs {
costs[i] = float64(c.costs[i])
sum += float64(c.costs[i])
}
avg := sum / float64(len(c.costs))
tp99, _ := stats.Percentile(costs, 99)
tp999, _ := stats.Percentile(costs, 99.9)

var result string
if tp999/1000 < 1 {
result = fmt.Sprintf("[%s]: TPS: %.2f, TP99: %.2fus, TP999: %.2fus (b=%d Byte, c=%d, qps=%d, n=%d)",
title, tps, tp99/1000, tp999/1000, echoSize, concurrent, qps, total)
result = fmt.Sprintf("[%s]: TPS: %.2f, AVG: %.2fus, TP99: %.2fus, TP999: %.2fus (b=%d Byte, c=%d, qps=%d, n=%d)",
title, tps, avg/1000, tp99/1000, tp999/1000, echoSize, concurrent, qps, total)
} else {
result = fmt.Sprintf("[%s]: TPS: %.2f, TP99: %.2fms, TP999: %.2fms (b=%d Byte, c=%d, qps=%d, n=%d)",
title, tps, tp99/1000000, tp999/1000000, echoSize, concurrent, qps, total)
result = fmt.Sprintf("[%s]: TPS: %.2f, AVG: %.2fms, TP99: %.2fms, TP999: %.2fms (b=%d Byte, c=%d, qps=%d, n=%d)",
title, tps, avg/1000000, tp99/1000000, tp999/1000000, echoSize, concurrent, qps, total)
}
logInfo(result)
return nil
Expand Down
2 changes: 2 additions & 0 deletions scripts/benchmark_compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ function log_prefix() {
}

function prepare_old() {
git checkout go.mod go.sum
go get -v github.com/cloudwego/kitex@$old
go mod tidy
}

function prepare_new() {
git checkout go.mod go.sum
go get -v github.com/cloudwego/kitex@$new
go mod tidy
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/benchmark_pb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source $CURDIR/env.sh
echo "Check finished."

srepo=("grpc" "kitex" "kitex-mux" "rpcx" "arpc")
crepo=${srepo[@]}
crepo=("grpc" "kitex" "kitex-mux" "rpcx" "arpc")
ports=(8000 8001 8002 8003 8004)

echo "Building pb services by exec build_pb.sh..."
Expand Down
8 changes: 4 additions & 4 deletions scripts/reports/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

'''CSV Format Example
Kind,Concurrency,Data Size,TPS,P99,P999,Server_CPU,Client_CPU
Kind,Concurrency,Data Size,TPS,AVG,P99,Server_CPU,Client_CPU
[GRPC],100,1024,101152.29,3.36,5.30,188.04,423.07
'''

Expand All @@ -23,7 +23,7 @@ class bcolors:
def diff(from_csv, to_csv):
from_reader = list(csv.reader(open(from_csv)))
to_reader = csv.reader(open(to_csv))
title = ['Kind', 'Concurrency', 'Data Size', 'QPS', 'P99', 'P999', 'Client CPU', 'Server CPU']
title = ['Kind', 'Concurrency', 'Data Size', 'QPS', 'AVG', 'P99', 'Client CPU', 'Server CPU']
results = []

for line_num, line in enumerate(to_reader):
Expand All @@ -33,8 +33,8 @@ def diff(from_csv, to_csv):
result.append(line[2]) # data size

result.append(diff_cell(from_reader[line_num][3], line[3])) # tps
result.append(diff_cell(from_reader[line_num][4], line[4])) # p99
result.append(diff_cell(from_reader[line_num][5], line[5])) # p999
result.append(diff_cell(from_reader[line_num][4], line[4])) # avg
result.append(diff_cell(from_reader[line_num][5], line[5])) # p99
result.append(diff_cell(from_reader[line_num][6], line[6])) # Server CPU
result.append(diff_cell(from_reader[line_num][7], line[7])) # Client CPU

Expand Down
4 changes: 2 additions & 2 deletions scripts/reports/to_csv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# csv
# usage: to_csv.sh xxx.log
output_dir=$(dirname "$1")
# Kind,Concurrency,Data_Size,TPS,P99,P999,Server_CPU,Client_CPU
grep TPS "$1" | awk '{print $2" "$11" "$9" "$4" "$6" "$8}' | awk '{gsub(/[:c=,(b=msAVG%]/, "")} 1' > $output_dir/tps.out
# Kind,Concurrency,Data_Size,TPS,AVG,P99,Server_CPU,Client_CPU
grep TPS "$1" | awk '{print $2" "$13" "$11" "$4" "$6" "$8}' | awk '{gsub(/[:c=,(b=msAVG%]/, "")} 1' > $output_dir/tps.out
grep '@Server' "$1" | grep CPU | awk '{print $14}' | awk '{gsub(/[:c=,(b=msAVG%]/, "")} 1' > $output_dir/server.out
grep '@Client' "$1" | grep CPU | awk '{print $14}' | awk '{gsub(/[:c=,(b=msAVG%]/, "")} 1' > $output_dir/client.out
# combine each line, replace space by comma
Expand Down

0 comments on commit 0ed9bc6

Please sign in to comment.