【问题标题】:Locust Performance different from time() function蝗虫性能与 time() 函数不同
【发布时间】: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


【解决方案1】:

蝗虫和时间是衡量两个不同的东西。时间正在衡量仅在服务器端运行 adapter.predict 函数所需的时间。 Locust 测量客户端从您的服务器路由获得响应所花费的时间,其中不仅包括您的 adapter.predict 呼叫,而且还包括谁知道在那之前和之后的所有其他事情。 “哪个更准确”取决于您要测量的是什么。如果您只是想知道拨打adapter.predict需要多长时间,那么时间会更准确。如果您想知道客户端需要多长时间才能获得/predict 路由的结果,Locust 更准确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 2019-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多