Round Trip Time (RTT) with Python
RTT is the length of time it takes for a signal to be sent plus the length of time it takes for an acknowledgment of that signal to be received . In other words, a small packet will be sent to a specific computer and it will send the packet back. The time difference between sending and receiving of the packet (in client side) is known as RTT or Ping Time. The following figure shows the TCP connection and RTT.
In this regard, I want to measure RTT for 2 computers and a server which is an AWS EC2 instance located in Frankfurt. One of the computers located in Berlin, the other one is another EC2 instance which is located in Frankfurt and is near to the server. The simplified configuration is shown in Figure 2.
EC2 Server consists of two server applications:
Socket server has three important tasks. The first task is creating and maintaining the connection between the client and the server. To this end, a new thread will be created whenever a new connection is established. The second task is measuring RTT value and the last one is timestamping and saving RTT values on the database, in this case, Influxdb is used. So Flask server is able to retrieve the values.
Flask server has also three important tasks which are:
Running a web framework
Retrieving data from Database
Representing data on graphs
The application of the client-side is relatively easy. It connects to the server and whenever gets a packet from the server; it just sends it back.
RTT value depends on various parameters such as:
Physical distance (Geographical location) between computers
Number of hubs/nodes between source and destination
Internet connection quality, Data Transfer Rate
Medium types such as LAN or WiFi
The following figures show the values of RTT for both connections. X-Axis number of samples and Y-Axis demonstrate the calculated RTT value in [ms]. It is important to notice that every three seconds the server will send a byte data to each client and by receiving it back, the server will calculate the RTT value.
As we can see in Figure 3, the RTT values for EC2 near to the server is lower than 1.35 ms, i.e. the maximum value would be around 1.35 ms.
On the other hand, RTT values for the computer located in Berlin is much higher than the other one, as shown in Figure 4. The maximum value, in this case, reaches 125 ms.
You can download the source code from my Github repository and test it on your server and client. Please share the result on the comment section below; I’ll glad to know them.