「All right reserved, any unauthorized reproduction or transfer is prohibitted」
在之前的文章中很多次提到了链路压测,在链路压测的统计结果中,只统计了链路的执行的耗时和相对应的QPS
,但是缺乏统计链路中各个接口的请求耗时,特别在针对接口响应时间的变化曲线统计,今天就补上这一块的内容。
旧文回顾:
思路
由于没有在性能测试框架中对链路压测中的,每个HTTP和其他协议请求的响应时间记录,所以统计响应结果的需要对日志进行分类统计。
- 读取日志中关于接口响应时间和requestID的内容。
- 根据不同的URL区分不同接口,存入不同的
list
中。 - 使用
StatisticsUtil
类的统计画图功能完成数据展示。
日志信息
这里分享一部分日志,日志的格式千差万别,在读取日志中关于接口响应时间的代码需要使用者自己完成。需要提前将日志文件清空或者临时指定其他日志文件,需要正确预估日志量和log4j 2
的配置,最后所有日志都在一个文件中,省得麻烦。
WARN-> 创建订单号:f1615455162cXCQX
INFO-> 请求uri:https://****/api/public/v1/order/refund,耗时:1181 ms, requestId:Fun20210311173240XNwf
INFO-> 请求uri:https://****/api/public/v1/order/create,耗时:1336 ms, requestId:Fun20210311173240NBiR
INFO-> 请求uri:https://****/api/public/v1/order/refund,耗时:853 ms, requestId:Fun20210311173241jBqr
INFO-> 请求uri:https://****/api/public/v1/order/create,耗时:895 ms, requestId:Fun20210311173241lYiS
WARN-> 创建订单号:f1615455160YBAgE
WARN-> 创建订单号:f1615455161Ia2GC
INFO-> 请求uri:https://****/api/public/v1/order/refund,耗时:1163 ms, requestId:Fun20210311173240aNZO
INFO-> 请求uri:https://****/api/public/v1/order/refund,耗时:1600 ms, requestId:Fun20210311173240SScO
INFO-> 请求uri:https://****/api/public/v1/order/refund,耗时:1289 ms, requestId:Fun20210311173240UPSB
INFO-> 请求uri:https://****/api/public/v1/order/refund,耗时:35 ms, requestId:Fun20210311173242QENp
INFO-> 请求uri:https://****/api/public/v1/order/create,耗时:44 ms, requestId:Fun20210311173242LcGa
WARN-> 创建订单号:f1615455162qrVq0
INFO-> 请求uri:https://****/api/public/v1/order/refund,耗时:40 ms, requestId:Fun20210311173242fxJg
INFO-> 请求uri:https://****/api/public/v1/order/create,耗时:31 ms, requestId:Fun20210311173242XWel
WARN-> 创建订单号:f1615455162baA6B
INFO-> 请求uri:https://****/api/public/v1/order/create,耗时:27 ms, requestId:Fun20210311173242LnwA
WARN-> 创建订单号:f1615455162SajUw
可以看出,这里的请求日志除了两个接口的响应时间以外,就是WARN
打印的订单号,需要的日志内容格式比较统一。
脚本
脚本依然用Groovy
编写,因为实在太好用了。
def lines = RWUtil.readTxtFileByLine(getLongFile("link.log"), "public/v1/order", true)
def create = []
def refund = []
lines.each {
def first = (Regex.findFirst(it, /\d+ ms/) - " ms") as int
if (it.contains(OrderApi.CREATE)) create << first
else if (it.contains(OrderApi.REFUND)) refund << first
else println it
}
println StatisticsUtil.statistics(create, "创建订单接口", 200)
println StatisticsUtil.statistics(refund, "退款", 200)
这里的线程数200需要自己传参,用来生成标题的,无其他实际用途。
控制台输出
由于字体原因,这里只能放图了。
FunTester,腾讯云年度作者、Boss 直聘签约作者,非著名测试开发 er,欢迎关注。
TesterHome 为用户提供「保留所有权利,禁止转载」的选项。
除非获得原作者的单独授权,任何第三方不得转载标注了「All right reserved, any unauthorized reproduction or transfer is prohibitted」的内容,否则均视为侵权。
具体请参见TesterHome 知识产权保护协议。
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
No Reply at the moment.