【发布时间】:2021-06-01 13:42:48
【问题描述】:
我编写了一个 FastAPI 并尝试使用不同的工具执行负载测试。我发现 Locust 的性能与 time() python 函数有很大不同:
- 蝗虫显示 min=17ms, max=2469ms, 99%=2000ms
- time() 函数显示 min()=3ms, max=1739ms
有人能解释一下这是为什么吗?哪个更准确?
以下是我的程序:
快速 API 功能:
app = FastAPI()
@app.post('/predict/')
def predict(request: PredictRequest):
logger.info('Invocation triggered')
start_time = time.time()
response = adapter.predict(request.dict())
latency_time = (time.time() - start_time) * 1000
latency_logger.info(f'Predict call latency: {latency_time} ms')
return response
蝗虫参数:
-u 500 -t 10 -r 500
蝗虫档案:
class User(HttpUser):
wait_time = between(1, 2.5)
host = "http://0.0.0.0:80"
@task
def generate_predict(self):
self.client.post("/predict/",
json={"cid": [],
"user_id": 5768586,
"store_ids": [2725, 2757],
"device_type": "ios"},
name='predict')
【问题讨论】:
-
您在非蝗虫测试中调用该函数的速率是多少?如果您想要准确的结果,请不要进行超快加速(-r 高于 50)。
标签: performance-testing locust