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 [1]. 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) known as RTT or Ping Time. The following figure shows the TCP connection and RTT.

Fig. 1: Round Trip Time

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. Simplified configuration is shown in Figure 2.

Fig. 2: Test Architecture

Server Application

EC2 Server consists of two server application:

  • Socket server

  • Flask Server

Socket server has three important tasks, the first task is creating and maintaining the connection between client and server, in order to do that a new thread will be created whenever a new connection 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 task which are:

  • Running a web framework

  • Retrieving data from Database

  • Representing data on graphs

Client Application

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.

Conclusion

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

  • etc.

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.

Fig. 3: Round Trip Time for client near to server

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.

Fig. 4: Round Trip Time for client far away from server

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 below, I’m curious to know them.

Add a Comment

Your email address will not be published. Required fields are marked *