0

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!

江南薛
  • 35
  • 4

1 Answers1

0

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()

Solowalker
  • 2,431
  • 8
  • 13