Roman is a QA engineer of ISSART . He has 3 years of experience in IT and 2 years of experience in software testing. His primary activities in software testing are performance testing and security testing.

Learn JMeter in 5 Hours

Start Learning
Slack

Run massively scalable performance tests on web, mobile, and APIs

Aug 08 2017

Load Testing UDP - The Ultimate Guide

UDP can be implemented in systems that communicate with multiple users, or in systems packet loss is prioritized over packet waiting. This blog post will explain how to load test UDP with open-source Apache JMeter™.

 

What is UDP?

 

UDP (User Datagram Protocol) is a message-oriented transport level protocol. Unlike TCP, it does not require a prior connection and doesn't use handshaking. This makes it faster and lighter than TCP and other protocols. On the other hand, it does not guarantee delivery, maintaining order or duplicate protection of the transmitted messages.

 

UDP is widely used in systems that need to communicate with a number of users, or systems in which packet loss is preferred to packet waiting. For example, UDP is used in media streaming applications, the DNS protocol and VPNs.

 

But despite the fact that the implementation of the protocol implies some loss of data, ideally users should not experience many losses. No one wants to watch a TV stream that looks like a slideshow since the server can’t receive a large number of clients׳ requests.

 

Configuring the UDP Request Sampler

 

To detect UDP performance issues, it is necessary to test these types of services before going to production. JMeter can be used to generate load over the UDP protocol, with the UDP Protocol Support plugin, which provides the UDP Request Sampler. The plugin can be installed via the Plugin Manager.

 

Step 1 - Add a thread group to a new JMeter test plan

 

Right click -> Add -> Threads -> Thread Group

 

Step 2 - Add the UDP Request Sampler as a child element to the thread group

 

Right click -> Sampler -> jp@gc - UDP Request

 

load testing udp with jmeter

 

The default sampler settings are shown in the screenshot above. We will show specific configurations later on.

 

UDP Request Configurations:

  • Hostname/IP and UDP Port  - The address and port of the UDP server. The address field can contain a URL.
  • Wait for Response and Response Timeout - These fields should be used  for cases when the server sends the response to a UDP request. If the checkbox is set, the UDP Sampler will be waiting for a response from the recipient. The waiting time (milliseconds) is taken from the Response Timeout field.
  • Close UDP Socket - If set, the UDP Socket will be closed at the end of the sampler work. Otherwise, the socket will be closed at the end of the thread iteration.
  • Request Data - the field for the information to be sent.
  • Bind Local Address and Bind Local Port - The local address and port that should be used to send the UDP request.
  • Data Encode/Decode class - Used for specifying classes for processing the output and input information. The UDP Sampler contains three class implementations:
    • kg.apc.jmeter.samplers.UDPSampler - This implementation does not convert data and is used as default. It is used when the field is empty or does not contain valid class name.
    • kg.apc.jmeter.samplers.HexStringUDPDecoder - This class converts the UDP Request data from Hex String to simple text.  The answer of the server converts from simple text to hex-string too. This implementation is the most useful, because a number of clients work with binary data. For example, if you write the string ‘48656c6c6f’ in Request Data, it will be converted to ‘Hello’.
    • kg.apc.jmeter.samplers.DNSJavaDecoder - This implementation is used for load testing DNS Servers that work via UDP. You need to install additional plugins to work with this implementation/class or just download jar file and add it to the /lib/ext folder of JMeter, because the UDP Request does not contain the class to work with DNS records. Request data must consist of 3 parts: name, type and class, for example “facebook.com A IN”.

You can also implement the kg.apc.jmeter.samplers.UDPTrafficDecoder interface and write your own data decoder/encoder.

 

UDP Request Implementations

 

Now, let’s consider the embedded implementations. In order to explain how the UDP Request sampler works, it’s necessary to run a simple UDP Server. The source code and jar of the server can be downloaded from here. The Server works in a two-way communication mode. It involves feedback from the receiver to the sender. In our examples the script sends the data to the server via the UDP Request sampler and gets responses from the server.

 

The Default Class Implementation (UDPSampler)

 

The UDP sampler has already been added to the demo script.  Now, you need to fill in Hostname (localhost), Port (9876) and Request Data (‘What is love?’ in our example) fields and start the UDP Server. You also need to add Listener to the Thread for the results monitoring, for example View Results Tree.

 

Right click -> Add -> Listeners-> View Results Tree

 

udp load testing with jmeter

 

run performance tests for udp with jmeter

 

udp performance testing

 

After that, you can run the JMeter script.

 

As you can see, the UDP Sampler finished successfully. In the Response data tab you can see the Server response.

 

HexStringUDPDecoder

 

Now, let’s add kg.apc.jmeter.samplers.HexStringUDPDecoder class to the Data Encode/Decode field and change Request Data to the Hex-string ‘’536f20776861742069732072696768743f20416e6420776861742069732077726f6e673f” (“So what is right? And what is wrong?”).The Configuration of The UDP Request Sampler for this case you can see in the screenshot below.

 

udp open source load test

 

After the script execution you can see the server response that was converted to the Hex-string “5768617420656c73652063616e2049207361793f204974277320757020746f20796f752e” (“What else can I say? It's up to you.”).

 

testing udp with jmeter

 

In addition, all messages are displayed in the console, in which our UDP server was launched.

 

open-source load testing udp

 

DNSJavaDecoder

 

The last embedded implementation is the DNSJava Decoder. To demonstrate the work of this class we will send a DNS request to the Google Public DNS for IP searching. Let’s test it.

 

First change the address and port to 8.8.8.8 and 53 correspondingly. Then, change the class in the Data Encode/Decode field to the  kg.apc.jmeter.samplers.DNSJavaDecoder and add DNS Request (“facebook.com. A IN” in our example) to Data Request field.

 

udp jmeter load testing performance testing

 

After execution you can see DNS Server’s response. If you put the IP address from the  Response in your browser’s address bar of your browser, you will see the Facebook page.

 

Creating a UDP Test Scenario

 

After the UDP Sampler review, let’s try to load test our server. In this scenario, we will use The Default Class Implementation. The settings for the sampler correspond to settings for this implementation, used above. Now, you need to add some new elements to the JMeter script.

 

Add the Thread Group and UDP Sampler as shown above, with the Default Class Implementation.

 

Now you’re ready to move on to step 3 - Add the CSV Data Config as a child element to the Test plan to load messages from it to UDP requests.

 

Right click -> Config elements->  CSV Data Config

 

how to load test udp

 

The sharing mode of CSV Data config is set to the current thread group. Also, do not forget to enter the variable of data config in the Request Data field of UDP Request Sampler. The CSV file for our server looks like this:

 

how can i load test udp

 

4. Add a Constant Timer as a child element to the Thread Group to regulate request rates.

 

Right click -> Timer->  Constant Timer

 

5. Add a Response Assertion as a child element to the UDP Request to control the server responses

 

Right click -> Assertions ->  Response Assertion

 

how can i performance test udp

 

With the help of the Response Assertion we can check the UDP server responses. This assertion validates each response. If a response contains a specific string, the assertion executes successfully. Our server will return an error message when it cannot recognize the input message. In our example the CSV file contains several unrecognizable messages for demonstration.

 

The final structure and the result of the script execution are shown in the screenshot below.

 

performance testing udp

 

As you remember, the Response Assertion was configured to pass all responses of the server that did not contain the error text. The CSV file contains two incorrect request messages and, as you can see on the screenshot above, the server did not recognize the two messages and two Response Assertions finished unsuccessfully.

 

As you can see, the script works correctly and if you want to scale up the script, you can change the number of threads and ramp-up period in the Thread Group element. To confirm the  Response Assertion works, you can see the server log in console which shows the responses and the requests.

 

udp load testing

 

That’s it! You now know how to load test a UDP server. As you can see, the UDP Sampler provides an interface for working with different UDP servers. You can also manipulate data conversion with the help of embedded classes, or you can just implement the basic interface and write your own converter.

 

To learn JMeter, check out our free JMeter academy.

 

To try out BlazeMeter, which enhances JMeter features, just request a demo or put your URL or JMX file in the box below and your test will start in minutes.

 

Click here to subscribe to our newsletter.

Interested in writing for our Blog?Send us a pitch!

Your email is required to complete the test. If you proceed, your test will be aborted.