From 0ed9bc62183078b6db58eb0ae7e5f08e97c923a9 Mon Sep 17 00:00:00 2001 From: xiezhengyao Date: Thu, 25 Jul 2024 11:50:44 +0800 Subject: [PATCH] feat: latency display avg and p99 --- runner/counter.go | 11 +++++++---- scripts/benchmark_compare.sh | 2 ++ scripts/benchmark_pb.sh | 2 +- scripts/reports/diff.py | 8 ++++---- scripts/reports/to_csv.sh | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/runner/counter.go b/runner/counter.go index 8a3c925..488c072 100644 --- a/runner/counter.go +++ b/runner/counter.go @@ -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 diff --git a/scripts/benchmark_compare.sh b/scripts/benchmark_compare.sh index 9cdada8..b180baf 100755 --- a/scripts/benchmark_compare.sh +++ b/scripts/benchmark_compare.sh @@ -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 } diff --git a/scripts/benchmark_pb.sh b/scripts/benchmark_pb.sh index 936cf2d..27b5942 100755 --- a/scripts/benchmark_pb.sh +++ b/scripts/benchmark_pb.sh @@ -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..." diff --git a/scripts/reports/diff.py b/scripts/reports/diff.py index e4e57ba..7eed81d 100644 --- a/scripts/reports/diff.py +++ b/scripts/reports/diff.py @@ -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 ''' @@ -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): @@ -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 diff --git a/scripts/reports/to_csv.sh b/scripts/reports/to_csv.sh index 4550e0a..1fcb5e6 100755 --- a/scripts/reports/to_csv.sh +++ b/scripts/reports/to_csv.sh @@ -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