shell笔记之压测与数据统计

本文介绍了如何使用Go语言进行压力测试,包括设置不同并发数和请求速率的基准测试,以及后续的数据统计和分析。详细展示了如何生成CPU和内存 profiling 文件,并通过实例演示了如何计算平均响应时间、命中率等关键指标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

go压测

#!/usr/bin/env bash

split="_"

for count in 100 200 400 800; do
  for rate in 40 60 80 100; do
    bench_name="$count$split$rate"
    rm -rf $bench_name
    mkdir -p $bench_name
    logDir["$index"]="$bench_name"
    let "index=$index+1"
    ## cpu 指定4核
    go test -bench="ABClientLog$bench_name" -benchmem -cpu=4  -benchtime=1x -cpuprofile=$bench_name/single_cpu.pprof -memprofile=$bench_name/single_mem.pprof >> $bench_name/single_bench.log
    go test -bench="ABClientBatchLogId$bench_name" -benchmem -cpu=4 -benchtime=1x -cpuprofile=$bench_name/batch_cpu.pprof -memprofile=$bench_name/batch_mem.pprof >> $bench_name/batch_bench.log
  done
done

数据统计

#!/usr/bin/env bash

split="_"
num1="1"
for count in 100 200 400 800; do
  for rate in 40 60 80 100; do
    bench_name="$count$split$rate"
    cd $bench_name
    sum=0
    for cost in $(egrep "GetLogIdByUid" single_bench.log | awk -F " " '{print $7}' | less)
    do
      sum=$(awk "BEGIN{print $sum+$cost}")
    done
    nums=$(egrep "GetLogIdByUid" single_bench.log | wc -l)
    avg_cost=$(awk "BEGIN{print $sum/$nums}")
    hit_total=$(egrep "hit" single_bench.log | wc -l)
    not_hit=$(egrep "not hit" single_bench.log | wc -l)
    hit_rate=$(awk "BEGIN{print $not_hit / $hit_total}")
    max_ts=$(egrep "GetLogIdByUid" single_bench.log | awk -F " " '{print $7}' | sort -nr | head -n 1)
    echo $count, $rate, $sum, $nums, $(awk "BEGIN{print $num1-$hit_rate}"), $avg_cost, $max_ts
    cd ..
  done
done
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疾风先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值