Network Time Protocol Performance Testing using Apache JMeter
Tags: ntp, jmeter, performancetesting
Published: 2019-11-04 20:14:06

---
title: Network Time Protocol Performance Testing using Apache JMeter
published: true
description: This blog post explains how you can script Network Time Protocol in Apache JMeter for performance testing
tags: ntp, jmeter, performance testing
---

# Introduction
Recently, Cloudflare released its newer implementation of Network Time Security in Rust. Network Time Security (NTS) is the next iteration of Network Time Protocol (NTP). You can learn more about NTP in [Wikipedia](https://en.wikipedia.org/wiki/Network_Time_Protocol). Surprisingly there is no information found in the internet about NTP performance testing using Apache JMeter.

**Do not perform high volume tests unless you are an authorized user.**

[Detailed instructions can be read in here] (https://qainsights.com/performance-testing-network-time-protocol-using-apache-jmeter/)

## Prerequisites
* Basic understanding of JMeter
* Basic understanding of Wireshark

# How to script NTP using Apache JMeter?
As many of the developers aware, that Apache JMeter is an 100% pure Java application and an open source load testing tool which supports most of the protocol including HTTP(S), DNS, NTP, FTP, Database via JDBC, SMTP(S) etc. 

Scripting NTP in JMeter is not a straight forward like HTTP(S) or Web Services. By leveraging Wireshark tool, it is possible and easy to script NTP requests.

Wireshark is the widely used network protocol analyzer. It is simple to use and you can trace the requests by attaching your local interface. 

For scripting purpose, we are going to leverage Cloudflare's time service URL time.cloudflare.com at the port 123.

## JMeter Setup
You need to install Plugins Manager for JMeter to install the [UDP Request Sampler](https://jmeter-plugins.org/wiki/UDPRequest/). 

Add the following elements to your test plan.

* Thread Group
* UDP Request
* View Results Tree

In UDP Request, enter the Hostname/IP as `time.cloudflare.com`, Port as `123`, and Data Encode/Decode Class as `kg.apc.jmeter.samplers.HexStringUDPDecoder`.

Now, launch Wireshark and attach your network interface (usually it will be your WiFi or LAN) and filter out the traffic using the filter `udp.port == 123`.

Fire up your `cmd` prompt and enter `w32tm /stripchart /computer:time.cloudflare.com` and hit enter. To stop getting time, hit `Ctrl + C`.

Go back to Wireshark to see the NTP requests and responses.

Copy the Hex Stream data of the NTP request and paste the data into JMeter UDP Request. Below image has the NTP request for time.windows.com.

![JMeter UDP Request for time.windows.com](https://qainsights.com/wp-content/uploads/2019/11/image-8.png)

Hit Save and run your test plan for one thread. Now go to View Results Tree to check the response which will be in Hex Stream format.

If you compare your JMeter NTP request and response data in Wireshark, both should matchy.

If you keep firing the NTP requests, you could see the response data varies. It's because, every instance the current timestamp changes. All the responses will be in UTC.

# Conclusion
By leveraging the Wireshark and JMeter, it is easy to test the performance of NTP servers.