美文网首页
Locust请求响应时间分析

Locust请求响应时间分析

作者: Lutous | 来源:发表于2021-01-28 10:09 被阅读0次
以为这样就结束了吗?你永远不知道明天和意外哪个先来。。。 响应时间.jpg

验证步骤:

  1. 在Locust框架clients.py中添加以下代码,记录接口发送单调时钟值
    kwargs["headers"]["lee_start_time"] = str(time.monotonic())


    企业微信截图_16117418549773.png
  2. 编写脚本获取网卡发送时间,并计算差值
# -*- coding: utf-8 -*-
# @Time    : 2020/12/20 16:47
# @Author  : Lee
# @File    : python_net_package.py
import time
from scapy.all import *


def get_print(packet):
   packet_str = packet.sprintf("%.time% {Raw:%Raw.load%}")
   res = re.match(r".*lee_start_time: (\d+)", packet_str)
   if res:
       print("时间差为:{} 毫秒".format((time.monotonic() - float(res.group(1))) * 1000))


if __name__ == '__main__':
   sniff(iface='以太网', prn=get_print, lfilter=lambda p: "GET" in str(p), filter="http")

  1. 验证结果居然有秒级延迟,见过最大的都超6秒了。。。


    image.png

相关文章

网友评论

      本文标题:Locust请求响应时间分析

      本文链接:https://www.haomeiwen.com/subject/kjydzktx.html