【效率】【性能】接口响应时间(使用fiddler工具、pythton request的elapsed方法)

时间:2024-03-15 12:50:20

一、使用fiddler工具查看接口响应时间

测试项:http接口响应时间

测试工具:fiddler

查看方法:

(1)选中单条URL,在右侧的视图中选择statistics->overalll elapsed 的值为接口响应时间

【效率】【性能】接口响应时间(使用fiddler工具、pythton request的elapsed方法)

(2)设置把此字段列出来的方法:

在URL那一栏右键点击,选择customize columns,然后在弹框中选择session timers、overall_elapsed

【效率】【性能】接口响应时间(使用fiddler工具、pythton request的elapsed方法)

 

点击add,添加成功后,效果如下:

【效率】【性能】接口响应时间(使用fiddler工具、pythton request的elapsed方法)

通过监控此响应时间,比如发现一个接口响应时间超过5S,设置超过10S了,可暴露出具体哪个接口慢,通过优化接口的响应时间提升产品的性能,用户体验(对应的质量指标是效率)。

二、python+request查看接口响应时间

#encoding:utf-8

 

import requests

import logging

logging.basicConfig(level=logging.NOTSET)

url="http://cn.python-requests.org/zh_CN/latest/"

r = requests.get(url)

logging.info("begin")

s=r.elapsed.total_seconds()

logging.info("%s接口响应时间:%s",url,s)

logging.info("finish")

 

【效率】【性能】接口响应时间(使用fiddler工具、pythton request的elapsed方法)

elapsed方法的官方文档地址:http://cn.python-requests.org/zh_CN/latest/api.html#requests.Response

elapsed = None

The amount of time elapsed between sending the request and the arrival of the response (as a timedelta). This property specifically measures the time taken between sending the first byte of the request and finishing parsing the headers. It is therefore unaffected by consuming the response content or the value of the stream keyword argument.

翻译:【效率】【性能】接口响应时间(使用fiddler工具、pythton request的elapsed方法)