load-testing - Get the number of concurrent users under a specific time in Locust
问题描述
I am using Locust and everything is working fine so far. Now, I have a requirement to break the test and get the number of concurrent users my server could take until I get an average response time of 200 ms. I know it is not possible to get from the report. How can I change my locustfile to implement this feature?
My locustfile looks as below
from locust import HttpUser, TaskSet, task, between
from locust.env import Environment
import json
from locust.contrib.fasthttp import FastHttpUser
class RecommenderTasks(TaskSet):
def __init__(self, parent):
super().__init__(parent)
self.global_header = None
self.cold_start_url = "https://my-url.com"
def on_start(self):
""" Use this code to login to GAIA server (if needed)
"""
self.global_header = self.login()
def login(self):
call_url = self.cold_start_url + "/oauth/token"
headers = {'Authorization': 'Basic c2ItZGV2IXQ1Nzc6TU01U0poMUtGZ3lnR1c4dXsdfdsPcUdzREhrMTVNPQ=='}
response = self.client.post(call_url, {'grant_type': 'client_credentials'}, headers=headers, verify=False)
access_token = json.loads(response.text.encode('utf8'))['access_token']
headers = {'Authorization': 'Bearer ' + access_token}
return headers
@task
def test_recommender_multiple_platforms(self):
params = {'rec_id': str(0),
'platform': ['text'],
'k': 10}
self.client.request("GET", '/recommendations', name='Test recommender',
params=params,
headers=self.global_header,
verify=False)
class RecommenderUser(HttpUser):
tasks = [RecommenderTasks]
wait_time = between(1, 5)
host = "https://my-url.com"
解决方案
推荐阅读
- python - 对动态范围内的列求和
- javascript - 用javascript处理表单提交时formdata事件的目的是什么?
- sql - Postgresql左连接问题
- flash - 使用 OpenFL 将 Haxe Flash 应用程序编译到 Adobe AIR
- javascript - Vue过渡动画不播放但保持其动画持续时间
- ios - Swift CollectionView ReloadData 暂时更改顺序
- javascript - 如何让 onclick 事件用于更改 CSS 属性?
- python - 使用 matplotlib 为不同的 y 值创建带有彩色线条的折线图
- node.js - UnhandledPromiseRejectionWarning:错误 [ERR_HTTP_HEADERS_SENT]
- javascript - 解析来自 Google Sheet Web App 的字符串化 JSON