'Hello, how should I set the server response time when using Locust to test UDP server?
I am using Locust to test the UDP server. My aim is to simulate a large number of user logins and test the load on the server. Refer to the official documentation. After reading the relevant documents, I inherited the socket class and added this code to the SendTo and recvfrom methods.
def recvfrom(self, bufsize):
recv_data = b''
start_time = time.time()
try:
recv_data, address = super(UdpSocketClient, self).recvfrom(bufsize)
except Exception as e:
total_time = int(time.time() - start_time) * 1000
events.request_failure.fire(request_type="udpsocket", name="recvfrom", response_time=total_time, exception=e)
else:
total_time = int(time.time() - start_time) * 1000
events.request_success.fire(request_type="udpsocket", name="recvfrom", response_time=total_time, response_length=0)
return recv_data, address
The running result is shown in the picture below. It seems to have no effect. Does anyone know where I am wrong?
Name # reqs # fails | Avg Min Max Median | req/s failures/s
------------------------------------------------------------------------------------------------------------------------
udpsocket recvfrom 39 0(0.00%) | 0 0 0 0 | 2.40 0.00
udpsocket sendto 39 0(0.00%) | 0 0 0 0 | 2.40 0.00
------------------------------------------------------------------------------------------------------------------------
Aggregated 78 0(0.00%) | 0 0 0 0 | 4.80 0.00
English is not my mother tongue, please forgive my grammatical mistakes.
Thank you for reading and look forward to your answers!
Solution 1:[1]
Check out the example of testing non-http systems here.
http://docs.locust.io/en/stable/testing-other-systems.html#example-writing-an-xml-rpc-user-client
Your code looks correct but the time it takes to receive the data could be fast enough that your response time is being calculated as 0. You could try to prove this by adding a time.sleep(1) after instantiating start_time. You could try using time.perf_counter() instead of time.time() like the example in the docs uses. For more information about the difference between those two calls, see Understanding time.perf_counter() and time.process_time()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Solowalker |
