Sunday 27 April 2014

How to find latency to Azure Virtual Machines?

Before looking at a way to measure latency to Azure Virtual Machines, let’s see traditional way to measure latency to any device connected on network / internet.
I won’t be talking much about what is latency for which you can Google or Bing, But in layman language latency is all about the time it takes for a packet to reach from Node A to Node B and response / acknowledgement of the same packet comes from Node B to Node A.
Note: Here node refers to any communicable device.

There are many blogs / website, which completely describes about the term latency so you can refer that.
To begin with understanding about the latency, below figure describe the traditional way of measuring latency between the systems.
We use Ping Command to typically find latency between source and destination by just pinging to Destination IP Address. In Below Image you can see latency from the machine (192.168.1.5) I ran ping to destination server with IP Address 192.168.1.4 is 1ms.
Note: Here latency is 1ms (very less) because the node resides in the same LAN network.


Figure 1: Traditional way to find latency

Ping uses ICMP protocol in background to test the reachability between the nodes, wherein two ICMP types are involved to make this activity successful i.e. Type 0 (Echo Reply) and Type 8 (Echo Request). So this means ICMP Protocol needs to be open between nodes for ping to work properly, and scenario where ICMP protocol is block in firewall, Ping will not be able to provide expected result.

Let’s move further now to understand how we can find latency of Azure VM’s.
Unlike previous method to measure the latency of node we used ping utility to get the latency with the help of ICMP protocol. But here on Azure, every VM is protected with firewall and it doesn’t support (or allow) inbound ICMP protocol to  reach virtual machines running inside azure.
Note: Here Azure Endpoint act as a firewall.

So how we can find out latency other than using ICMP protocol?
If you look at below image, Endpoint Rule doesn’t allow ICMP for inbound access; But only TCP or UDP Protocol

Figure 2: Azure Endpoint

So we can use TCP or UDP Protocol instead ICMP to ping Azure Virtual Machines.

Since default Ping Utility only supports ICMP we would need to use special ping tool which can work on TCP or UDP, and one of such tool I am aware of is PSPing which comes as a part of PSTool in SysInternals.
To Ping using PSPing on UDP or TCP Port, that port needs to be reachable from Source. For E.g. If you want to Ping on Port 80, this port needs to be open in Firewall (Endpoint) and application (Web Server running on Port 80) needs to be running on Virtual Machine (Destination / Target)

To understand this concept, I have used following Lab to demonstrate the entire concept.

Step 1: Windows Azure
-Here I have created 1 VM on Azure namely:
a.      VM1: SSTest1 (Running Windows 2012 R2)



Figure: VM running on Azure

Step 2: Add IIS role on VM1
I have installed this role so that VM will open port for web server and listen on Port 80.I will be using TCP protocol (port 80) to find the latency of Azure VM’s instead of ICMP protocol, As Azure Endpoint allows only TCP and UDP protocol for communication.

Step 3: Add endpoint on VM1 allowing TCP public and private port 80.

Figure: VM1 i.e. SSTEST1 Endpoint configuration

Step 4: Download Tool on source Node

                                

Download PSTools tool from below mentioned URL, then extract the downloaded package and copy the psping.exe utility from that package and paste in location C:\Windows\System32 so that you can use the psping utility via cmd prompt.
Link: http://technet.microsoft.com/en-us/sysinternals/jj729731.aspx

Step 5: Test the latency
Open cmd prompt from your computer and type the cmd shown in below image to test the latency of Azure VM using PSPing.

Figure: psping output

Conclusion: Latency between my Laptop (India, Mumbai) and Azure VM hosted in South East Asia is 103.65ms