zoukankan      html  css  js  c++  java
  • 链路压测中各接口性能统计

    在之前的文章中很多次提到了链路压测,在链路压测的统计结果中,只统计了链路的执行的耗时和相对应的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,欢迎关注。

  • 相关阅读:
    ETL Pentaho Data Integration (Kettle) 插入/更新 问题 etl
    Value Investment
    sqlserver 2008r2 表分区拆分问题
    HTTP与HTTPS的区别与联系
    别人分享的面经
    饥人谷开放接口(教程)
    java内存泄漏
    单例模式
    Maven项目上有小红叉咋办
    Socket通信1.0
  • 原文地址:https://www.cnblogs.com/FunTester/p/14547793.html
Copyright © 2011-2022 走看看