How to measure the real time network traffic ‘from’ and ‘to’ your EC2 instances
Tags: iperf, throughput, networkmeasurement, ec2
Published: 2022-03-13 04:49:43

``When working with traffic and time sensitive applications and workflows, it is always a good practice to measure the actual available bandwidth for your application. 
This will help you in various ways, some of them are listed below:

1. Define the baseline of the actual bandwidth available.
2. Identify if there are any bottlenecks, and for troubleshooting purposes.
3. The Data will help business decisions 
4. Increase and improve the service and customer satisfaction.

Fortunately Amazon offers an extensive list of official resources  documentation, knowledge base articles, blogs, videos among others, while using with its cloud products and services.
I am not intend going into a detailed description about the use of each of them but rather sharing my experience how those tools have helped me, in conjunction with open sources tools, to  solve problems and come up with better solutions for my customers by gathering information needed to take decisions.

One of the tools, which I believe most of the networks engineers have used at some point of their career, is IPERF. which as per their website described: “iPerf3 is a tool for active measurements of the maximum achievable bandwidth on IP networks”.

If you ever search for tutorials about this tool, you will notice that the majority (based on my own search experience) only describe how to use it for TCP traffic. 

**<u>Wait!</u>** Before continuing, I am assuming that you have a basic knowledge of network concepts such as model OSI, particularly Transport Layer. But if this is not the case, I found these well explained articles that will help you understand a little bit more.  

1.[The OSI model explained and how to easily remember its 7 layers.](https://www.networkworld.com/article/3239677/the-osi-model-explained-and-how-to-easily-remember-its-7-layers.html)
2. [What is the OSI Model?](https://www.cloudflare.com/en-ca/learning/ddos/glossary/open-systems-interconnection-model-osi/)

Lets continue from where I left, in my previous experience using **IPERF3**  it was especially to verify that the available bandwidth is what  I  was told, for the simple reason the application was sensible to the bandwidth availability.

**For this blog I will measure both TCP and UDP Traffic.**

The Network topology I used is shown below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urgg0y74e6iaou5qtttr.png)

For this tests, I used **IPERF3**  version.

- Running the Iperf server's commands on the EC2 instance in AWS.
- Running the Iperf client's command on my laptop.

1. Server's side command (AWS): **iperf -S**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b5r3n7e2tkbnmit8oan.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bk0yto5wdybkfz7nb7q5.png)

2. Client's side command (Laptop):**iperf -C 'Server IP'**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ol290x1q81zuwa06iif8.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xrr2v38xd3if9l65268.png)

So far, this is something you will normally find as an examples while looking in how to use Iperf, but something is not as common is measuring UDP traffic, the main difference is you need to add the tag: -u and -b (bandwidth) on the client side as is shown below:

3. _**_UDP => _**_Client's side command (Laptop):
**iperf -C 'Server IP'-u -b 1M**

- where '1M' represents 1 Mbps

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vjp37u0rhgbbmfk6iicb.png)

You can also add the tag **'-p'**, in the below example I am sending two paralell connections to the server and the bandwith limit is applied separately to each stream.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vuwg9d3nkah4xcth0bbl.png)
```
Please review the official documentaion link, for further information [IPERF3 Documentation](https://iperf.fr/iperf-doc.php#:~:text=iPerf%20normally%20works%20by%20repeatedly,Default%20is%2010%20seconds.)

I hope this article help is useful for you!!