首页 > 解决方案 > 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" 

标签: load-testinglocust

解决方案


推荐阅读