Network Latency
Summary
Network latency is the amount of time it takes for a packet of data to travel from its source to its destination. It is an important factor in determining the overall performance of a system, as it affects the amount of time it takes for data to be transferred between two devices.
Calculation formula: Network latency = (Transmission time + Propagation time + Queuing delay) / 2
Transmission time: the time it takes for the source device to send the packet Propagation time: the time it takes for the packet to travel from the source to the destination Queuing delay: the time it takes for the data to be stored in the network queues
Examples: If a packet of data takes 2 ms to send and 10 ms to travel from source to destination, and there is no queuing delay, the network latency would be calculated as follows:
Network latency = (2 ms + 10 ms + 0 ms) / 2 = 6 ms
Network latency can be affected by a variety of issues and can be measured with various metrics:
Metric | Description |
---|---|
Round Trip Time (RTT) | The total time it takes for a packet to travel from the source to the destination and then back to the source. |
Packet Loss Rate | The number of packets that are lost during the transmission from the source to the destination. |
Throughput | The rate of data transfer between the source and the destination. |
Connection Time | The time it takes to establish a connection between the source and the destination. |
Jitter | The variation in latency between consecutive packets. |
Latency Variance | The difference between the average latency and the maximum latency. |
Response Time | The time it takes for the destination to respond to the packet sent by the source. |
Avg. Transmission Time | The average time it takes for the packet to be sent from the source to the destination. |
Path MTU | The maximum size of a packet that can be sent from the source to the destination. |
Retransmission Rate | The rate of packet retransmissions due to packet loss or errors. |
Some ways to improve network latency
# | Action |
---|---|
1 | Switch to a faster/better ISP |
2 | Reduce the number of hops in the network |
3 | Use faster or higher bandwith hardware such as faster switches and routers |
4 | Implement Quality of Service (QoS) |
5 | Utilize caching techniques |
6 | Optimize network protocols |
7 | Utilize the latest network standards and technologies |
8 | Reduce packet fragmentation |
9 | Manage bandwidth usage |
10 | Utilize a Content Delivery Network (CDN) |
11 | Use compression |
12 | Increase Bandwidth |
13 | Improve Hardware |
Ways to improve network latency on the frontend:
# | Frontend Latency |
---|---|
1 | Use a CDN |
2 | Optimize your images |
3 | Minify and combine files |
4 | Use browser caching |
5 | Use HTTP/2 |
6 | Enable compression |
7 | Use a lightweight framework |
8 | Use pre-rendering |
9 | Use Chrome DevTools |
10 | Optimize client-side code |
Use a CDN – Using a content delivery network (CDN) to host static resources such as images, CSS, and JavaScript can greatly reduce the amount of time it takes for the browser to download them, thus reducing latency.
Optimize your images – Optimizing images that are being served to the client can significantly reduce the amount of time it takes for them to be loaded.
Minify and combine files – Minifying and combining JavaScript and CSS files into fewer files can reduce the number of requests the browser must make, thus reducing the amount of time it takes for each request to be processed.
Use browser caching – Setting up browser caching for static resources such as images, CSS, and JavaScript can reduce the amount of time it takes for the browser to download them, since they are already cached in the browser.
Use HTTP/2 – HTTP/2 allows multiple requests to be sent in parallel, reducing the amount of time it takes for the browser to download each resource.
Enable compression – Enabling compression on the server can reduce the size of the files being sent to the client, thus reducing the amount of time it takes for them to download.
Use a lightweight framework – Using a lightweight front-end framework such as React can reduce the amount of code that needs to be sent to the client, thus reducing the amount of time it takes for the browser to download it.
Use pre-rendering – Pre-rendering pages can reduce the amount of time it takes for the browser to render the page, since the content is already rendered on the server.
Use Chrome DevTools – Using Chrome DevTools can help identify areas of your website that are causing latency, and can provide insights into how to reduce it.
Optimize client-side code – Writing efficient client-side code can reduce the amount of time it takes for the browser to process it, thus reducing latency.
Examples of Latency differences by country - actual will vary based on many factors like infrastructure, peering and traffic routing will affect the latency
From San Francisco:
Region/Country Latency (ms) San Francisco 0 Los Angeles 5 Denver 20 New York 25 London 30 Frankfurt 35 Singapore 40 Mumbai 50 Sydney 55 Tokyo 60 Sao Paulo 70 Johannesburg 75 Hong Kong 80 Mumbai 85 Sydney 90