<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vilmar on Medium]]></title>
        <description><![CDATA[Stories by Vilmar on Medium]]></description>
        <link>https://medium.com/@rossetv?source=rss-1ffb2fdc10e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*4ZpujyirsMAx5B9l</url>
            <title>Stories by Vilmar on Medium</title>
            <link>https://medium.com/@rossetv?source=rss-1ffb2fdc10e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:20:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rossetv/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Advanced Networking Performance on A EC2 Linux: Achieving high throughput and low latency]]></title>
            <link>https://medium.com/doit-international/advanced-networking-performance-on-a-ec2-linux-achieving-high-throughput-and-low-latency-85457294f822?source=rss-1ffb2fdc10e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/85457294f822</guid>
            <category><![CDATA[ec2-instance]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Vilmar]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 09:17:11 GMT</pubDate>
            <atom:updated>2024-06-10T09:17:11.033Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced Networking Performance on Amazon EC2 Linux: Achieving high throughput and low latency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h_xs-jRZtcoacJjaM5IWcw.png" /><figcaption>AI-generated image</figcaption></figure><h4>Table of Contents</h4><p>∘ <a href="#3517">Enhanced Networking Performance</a><br> ∘ <a href="#8752">Understanding ENA and Its Importance</a><br> ∘ <a href="#72ce">Emphasis on Using the Latest Versions</a><br> ∘ <a href="#f649">The oversimplified life of a network packet</a><br> ∘ <a href="#eab1">ENA Queues</a><br> ∘ <a href="#82de">CPU Starvation</a><br> ∘ <a href="#1d5a">Receive Packet Steering (RPS)</a><br> ∘ <a href="#df2e">Interrupt Moderation</a><br> ∘ <a href="#0abd">Memory Constraints</a><br> ∘ <a href="#1a71">Let&#39;s have a chat!</a></p><h4>Enhanced Networking Performance</h4><p>In cloud computing, network performance is critical for the scalability and efficiency of applications that demand high throughput and low latency. Modern generations of EC2 instance types feature Enhanced Networking with the Elastic Network Adapter (ENA), and Amazon’s proprietary ENA driver, providing significant performance improvements over traditional virtual machines. This article delves into advanced networking techniques and best practices to optimise network performance on EC2 Linux instances and enhance your application’s performance.</p><h4>Understanding ENA and Its Importance</h4><p>Older generations of EC2 instances are virtualised in Xen, and do not support ENA. The modern generations, on the other hand, are virtualised using KVM and have AWS’ proprietary ENA drivers for networking.</p><p>With Xen, there’s a concept of <em>dom0</em>, which is the management domain through which every I/O request will go through, and where services for the underlying host would live.</p><p>Network I/O would exit the virtual machines<em> (domU) </em>via the <em>netfront/netback</em> drivers, while disk I/O would use the <em>blockfront/blockback</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*pbSzdFvwkW88Qdbd.png" /></figure><p>For every I/O request, the virtual machine <em>(domU)</em> has to process and pass it to <em>dom0</em> via these drivers, which then would use the actual drivers to pass it on to the actual hardware.</p><p>In summary, for every I/O request of the virtual machine <em>(domU)</em>, there would always be a middle-man involved <em>(dom0)</em> between the virtual machine and the actual hardware, which results in poor performance, and more importantly, significant jitter, delivering a very unpredictable I/O performance.</p><p>Additionally, <em>dom0</em> would be involved in the I/O requests for ALL virtual machines in that underlying host, which can be a significant number, with possibly up to 100s of virtual machines in the same underlying host. This only adds to the unpredictability of the I/O performance and introduces a significant problem with noisy neighbours.</p><p>With Amazon’s proprietary network driver (ENA), this problem is resolved by allowing the virtual machines to communicate directly to the hardware, without the need of a middle-man.</p><p>On the <a href="https://docs.aws.amazon.com/ec2/latest/instancetypes/pg.html">modern generations of EC2 instances</a> built on <a href="https://aws.amazon.com/ec2/nitro/">Nitro</a>, there’s no longer a <em>dom0</em>, and AWS moved from Xen altogether, and started using KVM as a hypervisor.</p><h4>Emphasis on Using the Latest Versions</h4><p>These improvements have been progressively significant in newer generations of EC2 instances, which underscores the <strong>importance of always selecting the latest generation of EC2 instances when maximum performance is required.</strong></p><p>It is equally crucial to <strong>ensure that your Linux system is using the latest version of the ENA driver,</strong> which includes all the new performance optimisations and bug fixes.</p><h4>The oversimplified life of a network packet</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x9-kUoWEnZ48ACUpDeC7sQ.png" /></figure><p>Oversimplifying, the life of a network packet coming from the internet into a Linux system, starts at the arrival in the network interface card, which then would generate an interrupt to signal to the CPU that data has arrived.</p><p>The CPU will then pause what it was doing, and handle the interrupt. This involves executing an interrupt handler routine, that processes the incoming packet.</p><p>After that, the kernel’s network stack then takes over, and the packet is processed by it. This includes various layers like IP handling, TCP/UDP handling, and more. The kernel checks the packet’s integrity and determines its destination on the system, and handles routing.</p><p>If the packet is intended for an application running in the system, it is moved to a socket buffer. These are the endpoints for sending and receiving data on a computer, which sits in the RAM memory.</p><p>For the purpose of this article, we will focus on two different steps of the life of a network packet: <strong>interrupt handling</strong>, which signals the arrival of new data from the hardware, and the <strong>ENA queues</strong> which handle processing of the network packets within the Linux stack.</p><p>For interrupt handling, Linux uses mechanisms such as SoftIRQs and NAPI to efficiently handle network packet processing.</p><p>Rather than immediately stopping what the CPU is doing whenever any network packet arrives, using software interrupts <em>(SoftIRQs)</em> the system can accommodate a deferred execution, that allows the kernel to defer its processing in favour of something more urgent.</p><p>NAPI is an interface designed to improve network performance under high load. It changes how packets are processed from an interrupt-driven model to a polling model when the network traffic reaches a certain threshold, reducing the overhead caused by excessive interrupts.</p><h4>ENA Queues</h4><p>In simple terms, an ENA queue is like a set of conveyor belts that helps manage internet traffic, by handling the network packets in and out of the system. These <em>conveyor belts</em> are organised into two types:</p><p>Transmit Queues <em>(Tx)</em>, which is where the system puts data that it wants to send out to the internet; and Receive Queues <em>(Rx)</em> which is where incoming data from the internet is received, and then placed into a buffer to process the received data.</p><p>Each of these queues has a <em>submission</em> section and a <em>completion</em> section. Initially, the data is placed in the <em>submission</em> section either to be sent out <em>(Tx)</em> or to prepare for receiving incoming data <em>(Rx)</em>. The <em>completion</em> section confirms whether the data has been successfully sent or received.</p><p>Having this picture of the ENA queues, it’s easy to see how these can become a bottleneck and hinder network performance. EC2 instances can have multiple ENA queues <em>(up to a maximum of 32 per ENI)</em> based on the size of the instance type. This multi-queue support allows for network traffic to be spread across multiple CPU cores, reducing bottlenecks, and improving overall data handling efficiency, with lower latencies and higher throughput.</p><p>Using ethtool<em>,</em> we can monitor metrics provided by Amazon&#39;s ENA driver, and further understand how the system is handling the traffic load in these queues.</p><p>One of the important metrics available is the number of <em>stops</em> in these queues. These mean that packets were submitted to the <em>Tx</em> rings faster than they could be processed, hence causing a drop.</p><pre>[root@aws rossetv]# ethtool -S eth0|grep stop<br>     queue_0_tx_queue_stop: 0<br>     queue_1_tx_queue_stop: 0</pre><p>When there’s a significant number of <em>stops</em> in the ENA queues, this typically indicates throttling by either <strong>AWS throttling</strong>, due to exceeding instance network limits, or <strong>resource starvation</strong>, where there is not enough processing power or buffers available to handle the incoming packets.</p><p>To narrow this issue further, we can check for throttling by looking at the <em>exceeded</em> metrics, with the command below.</p><pre>[root@aws rossetv]# ethtool -S eth0|grep stop<br>     bw_in_allowance_exceeded: 0<br>     bw_out_allowance_exceeded: 0<br>     pps_allowance_exceeded: 0<br>     conntrack_allowance_exceeded: 0<br>     linklocal_allowance_exceeded: 0</pre><p>If there is a non-zero value in any of these counters, refer to a previous article of mine on <a href="https://engineering.doit.com/troubleshooting-aws-network-throttling-a-comprehensive-guide-368811424148">Troubleshooting AWS network throttling</a>, which I am linking here.</p><p>When there is confirmation that no throttling occurred from the AWS side, this would mean that your system is likely facing resource starvation for networking.</p><h4>CPU Starvation</h4><p>Expanding further on the ENA queues, these will process network packets. Before that point, there will also be IRQ handling by the kernel, which handles the interrupts coming from the network card, signalling to the CPU that new data has arrived. The CPU then stops its current task to handle the interrupt, and further down the road this data will be handled by ENA as a network packet.</p><p>If the vCPUs of an instance are overloaded or unevenly utilised, it might cause delays in network traffic processing, leading to packet drops on the <em>Rx</em> side and completion timeouts on the <em>Tx</em> side, which results in low performance and increased highly variable latency.</p><p>To achieve high and stable network performance, it’s essential to ensure that the vCPUs in charge of handling the network traffic <em>(the ENA queues)</em> are available and given sufficient processing time for this task.</p><p>Most of the network processing occurs in NAPI routing, running in <em>softirq</em> context. These CPU cores involved in NAPI processing can be identified by running the following command:</p><pre>[root@aws rossetv]# egrep &#39;CPU|eth0&#39; /proc/interrupts<br>           CPU0       CPU1       <br> 28:       4531       1535   PCI-MSI 81921-edge      eth0-Tx-Rx-0<br> 29:        460       4311   PCI-MSI 81922-edge      eth0-Tx-Rx-1<br>[root@aws rossetv]#</pre><p>In some cases, you might also see that the <em>ksoftirqd</em> threads are consuming nearly 100% of the CPU core. These threads are in charge of handling these interrupts, before the traffic reaches the ENA queues.</p><p>There are several potential causes for CPU starvation in network processing: it could simply be that the system is overloaded with other CPU-intensive tasks, detectable by utilities such as htop, or using perf to determine where the cores spend most of their time.</p><p>Sometimes, the high CPU utilisation has a spiky nature, resulting in <strong>short-lasting peaks of high CPU usage. </strong>In these cases, you can increase the size of the <em>Rx</em> ring, to compensate for temporary CPU unavailability.</p><p>By default, the ENA <em>Rx</em> ring size is 1K entries, but it can be dynamically increased up to 16K entries by using ethtool. To increase the <em>Rx</em> ring size on <em>eth0</em> to 4096 for example, you could use the command below.</p><pre>sudo ethtool -G eth0 rx 4096</pre><p>If the CPU cores that are responsible for network processing are constantly overloaded and approach 100% utilisation, while the overall CPU usage isn’t that high, this might indicate uneven load distribution across the available vCPUs.</p><p>This can be fixed by reassigning other tasks running on the overloaded vCPUs to other less loaded vCPUs that don’t participate in network processing with either taskset or numactl Linux utilities.</p><p>It is also possible to <strong>steer away network interrupts from already overloaded vCPUs,</strong> by setting the IRQBALANCE_BANNED_CPUS in your system&#39;s /etc/sysconfig/irqbalance, to the CPU mask indicating CPUs that you want to exclude, and then restart the irqbalance service.</p><p>With this approach, you can ensure that the CPU cores that handle the ENA queues are not also busy handling network IRQs.</p><p>If there are more CPU cores in your EC2 instance than there are ENA queues, you can also enable receive packet steering<em> (RPS)</em> to offload part of the <em>Rx</em> traffic processing to other vCPUs. It is advised however to <strong>keep the RPS vCPU cores at the same NUMA node as the vCPU nodes processing ENA IRQs.</strong> Also <strong>avoid having RPS vCPU on sibling cores of IRQ vCPUs,</strong> when hyperthreading is enabled.</p><p>The above indicated approaches can give you a very fine control over what CPU cores handle which aspects of the network processing work on Linux, to ensure absolute maximum performance.</p><h4>Receive Packet Steering (RPS)</h4><p>Receive packet steering <em>(RPS)</em> is a method for directing network packets for specific CPUs for processing. This can be implemented to help prevent the hardware queue of a single network interface card from becoming a bottleneck in network traffic.</p><p>RPS is configured for each network device and receive queue, specifically within the /sys/class/net/eth0/queues/rx-0/rps_cpus file, where eth0 is the network device and rx-0 denotes the appropriate receive queue.</p><p>By default, the rps_cpus file is set to 0, which effectively disables RPS, meaning that the same CPU core handling the network interrupt also process the packet. To enable RPS, you can configure the appropriate rps_cpus file with the CPUs that should process the packets from the specified network device and receive queue.</p><p>The configuration in the rps_cpus files use comma-separated CPU bitmaps. To enable a CPU to manage interrupts for a receive queue on an interface, you must set the values in the bitmap to 1.</p><p>You can identify which CPUs are affiliated with which NUMA nodes using the lscpu command, as shown below:</p><pre>[root@aws rossetv]# lscpu | grep NUMA<br>NUMA node(s): 2<br>NUMA node0 CPU(s): 0-15,32-47<br>NUMA node1 CPU(s): 16-31,48-63</pre><p>With the above example, let’s enable RPS for cores 48 to 63. This system has 64 cores, and each hexadecimal character in the bitmask represents 4 bits, so we will need 16 hexadecimal characters to represent 64 bits. To enable the last 16 cores <em>(48–63)</em> for RPS, we need the last 16 bits set to 1 and all other bits set to 0. The hexadecimal representation for 1111 1111 1111 1111 <em>(16 bits for cores 48-63)</em> is FFFF.</p><p>Since we are working with a 64-bit representation, and need to enable the highest 16 bits, the bitmask would be 0000,00000000,00000000,0000FFFF.</p><p>To apply this setting across multiple receive queues, you can use the following commands to loop through Rx queues rx-0 to rx-15 on the eth0 interface, setting them to use only cores 48 to 63:</p><pre>sudo bash -c &#39;for i in $(seq 0 15); do echo &quot;0000,00000000,00000000,0000FFFF&quot; &gt; /sys/class/net/eth0/queues/rx-$i/rps_cpus; done&#39;</pre><p>This change will not persist after a reboot though. To make it persistent, after testing we can write a simple script and add it to run upon boot, with the commands below.</p><pre>sudo su<br>echo &#39;for i in `seq 0 15`; do echo $(printf &quot;0000,00000000,00000000,0000FFFF&quot;) | sudo tee /sys/class/net/eth0/queues/rx-$i/rps_cpus; done&#39; &gt; /sbin/rps_core<br>chmod +x /sbin/rps_core<br>echo &quot;/sbin/rps_core&quot; &gt;&gt; /etc/rc.local<br>chmod +x /etc/rc.local</pre><p>Please note, if the irqbalance service is active, IRQ processing may migrate to different vCPUs, potentially diminishing the effectiveness of RPS. While it is not advisable to disable irqbalance, you can specify which CPU cores to exclude from IRQ processing by setting the IRQBALANCE_BANNED_CPUS variable in /etc/sysconfig/irqbalance.</p><p>The CPU mask would be calculated the same way as above, so in this specific example we would set IRQBALANCE_BANNED_CPUS=0000,00000000,00000000,FFFF and restart irqlbalance with the commands below.</p><pre>sudo su<br>echo &quot;IRQBALANCE_BANNED_CPUS=0000,00000000,00000000,FFFF&quot; &gt;&gt; /etc/sysconfig/irqbalance<br>sudo systemctl restart irqbalance</pre><h4>Interrupt Moderation</h4><p>High network throughput and low latency are key goals in high performance cloud environments. However, there is a trade-off between latency and throughput from the perspective of an Ethernet controller.</p><p>To achieve lower latency, the controller usually minimises the interval between interrupts to speed up small packet processing at the price of causing higher CPU usage and lower throughput.</p><p>On the other hand, to improve throughput and minimise the overhead caused by frequent interrupts, larger interrupt intervals are desirable. So an appropriate interrupt interval is critical to getting the best performance balance.</p><p>Interrupt moderation is a driver feature supported by the Nitro powered instance types using ENA, that allows the user to manage the rate of interrupts to the CPU during packet transmission and reception.</p><p>Without any interrupt moderation, the system triggers an interrupt for every transmitted and received packet. Although this can minimise latency on each packet, extra CPU resources are spent on interrupt processing overhead, which can significantly reduce the throughput.</p><p>When interruption moderation is enabled, multiple packets are handled for each interrupt, so that the overall interrupt processing efficiency is improved, and CPU utilisation is decreased, in exchange of a higher latency as the CPU waits for multiple packets before handling.</p><p>In EC2 instances using the ENA driver, for <em>Tx</em> the static interrupt delay is set to 64 µsec by default.</p><p>As for <em>Rx</em> moderation rate, its setting might vary depending on the instance type. In some instances, types <em>Rx </em>moderation is disabled by default, while in others it is enabled in adaptive mode.</p><p>This can be checked using ethtool with the command below.</p><pre>[root@aws rossetv]# ethtool -c eth0<br>Coalesce parameters for eth0:<br>Adaptive RX: off  TX: n/a<br>stats-block-usecs: n/a<br>sample-interval: n/a<br>pkt-rate-low: n/a<br>pkt-rate-high: n/a</pre><pre>rx-usecs: 0<br>rx-frames: n/a<br>rx-usecs-irq: n/a<br>rx-frames-irq: n/a</pre><pre>tx-usecs: 64<br>tx-frames: n/a<br>tx-usecs-irq: n/a<br>tx-frames-irq: n/a</pre><pre>rx-usecs-low: n/a<br>rx-frame-low: n/a<br>tx-usecs-low: n/a<br>tx-frame-low: n/a</pre><pre>rx-usecs-high: n/a<br>rx-frame-high: n/a<br>tx-usecs-high: n/a<br>tx-frame-high: n/a</pre><pre>CQE mode RX: n/a  TX: n/a</pre><pre>[root@aws rossetv]#</pre><p>In the example above, interrupt moderation for <em>Rx</em> is disabled.</p><p>If you have a high interrupt rate, it would be recommended to enable adaptive <em>Rx</em> moderation, which dynamically adjusts the interrupt rate based on the packet size and average throughput. This can be done with the command below.</p><pre>sudo ethtool -C eth0 adaptive-rx on</pre><h4>Memory Constraints</h4><p>While we heavily covered CPU starvation for network processing, memory can also be a significant constraint, as if the buffers are exhausted, it will start to drop packets.</p><p>You should ensure that your reserved kernel memory is sufficient to sustain a high rate of packet buffer allocations. This can be set by tweaking the parameter vm.min_free_kbytes from /etc/sysctl.conf.</p><p>As a rule of thumb, you should set this value to around 3% of the available system memory. This can be set with the commands below, setting the value in <em>kbytes</em>.</p><pre>echo &quot;vm.min_free_kbytes = 1048576&quot; &gt;&gt; /etc/sysctl.conf<br>sudo sysctl -p</pre><p>For applications that are heavily using UDP, the buffers specific to UDP should also be increased, since by default Linux places very restrictire limits on the performance of UDP protocol by limiting the size of the UDP traffic that is allowed to buffer on the receive socket.</p><p>Below commands would set the UDP buffers to 128MB <em>(in kbytes)</em>, for example.</p><pre>sudo su<br>echo &quot;net.core.rmem_max=134217728&quot; &gt;&gt; /etc/sysctl.conf<br>echo &quot;net.core.rmem_default=134217728&quot; &gt;&gt; /etc/sysctl.conf<br>sysctl -p</pre><h4>Let&#39;s have a chat!</h4><p>To summarize, attaining high throughput with low latency involves overcoming three key challenges: A<strong>WS Throttling, CPU Starvation, and Memory Starvation.</strong></p><p>By tackling these issues, you can enhance networking performance to achieve maximum throughput and minimum latency.</p><p>In the previous sections, we explored various ways to address these constraints under different conditions. Although the strategies mentioned generally apply to many settings, each environment has its unique aspects.</p><p><strong>With this in mind, why not start a conversation?</strong> <a href="https://www.doit.com/services/#areas-of-expertise">Contact DoiT to arrange a discussion</a> about network optimisation and other topics with our Cloud Architects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85457294f822" width="1" height="1" alt=""><hr><p><a href="https://medium.com/doit-international/advanced-networking-performance-on-a-ec2-linux-achieving-high-throughput-and-low-latency-85457294f822">Advanced Networking Performance on A EC2 Linux: Achieving high throughput and low latency</a> was originally published in <a href="https://medium.com/doit-international">DoiT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrate all your EBS volumes from gp2 to gp3 to improve performance while saving up to 20% on costs]]></title>
            <link>https://medium.com/doit-international/migrate-all-your-ebs-volumes-from-gp2-to-gp3-to-improve-performance-while-saving-up-to-20-on-costs-8c9762e58191?source=rss-1ffb2fdc10e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c9762e58191</guid>
            <category><![CDATA[amazon-ebs]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[storage]]></category>
            <dc:creator><![CDATA[Vilmar]]></dc:creator>
            <pubDate>Thu, 11 Apr 2024 09:02:14 GMT</pubDate>
            <atom:updated>2024-04-11T09:02:14.303Z</atom:updated>
            <content:encoded><![CDATA[<h4>This article provides a one-size-fits-all solution to migrate all your EBS volumes from gp2 to gp3, dramatically improving performance on volumes smaller than 1 TiB, and saving up to 20% on EBS costs for all volumes.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QCKJwVxw5FCjbA8AVhjVSA.png" /><figcaption>AI-generated image of Cloud Storage representation</figcaption></figure><h3>Table of Contents</h3><p>· <a href="#3283">Comparing gp3 to gp2 volumes</a><br>· <a href="#ec96">How to migrate all gp2 volumes to gp3?</a><br> ∘ <a href="#9cba">Prerequisites</a><br>· <a href="#c541">Path to further savings on gp3 migration</a></p><h3>Comparing gp3 to gp2 volumes</h3><p>In December 2020, AWS introduced a new generation of general-purpose SSD-based EBS volumes named gp3. Unlike its predecessor, its baseline performance is not tied to the volume size, and gp3 volumes offer a minimum baseline IOPS of 3000 regardless of volume size, in contrast to the gp2’s variable rate of 3 IOPS/GiB, directly tied to the volume size. Additionally, gp3 volumes are more cost-effective, priced at $0.08/GiB-month compared to the $0.10/GiB-month pricing of the older gp2 volumes.</p><p>Using gp2 EBS volumes, the baseline throughput and IOPS are directly tied to volume size, at a rate of 3 IOPS/GiB, and between 128 MiB/s and 250 MiB/s of throughput, depending on the volume size. For gp2, there is no way of increasing IOPS or throughput without increasing volume size. These volumes also have a bursting credits system, which allows them to burst for short periods.</p><p>With the new gp3 volume types, you can provision up to 16,000 IOPS and 1,000 MiB/s of throughput regardless of volume size, at an additional cost of $0.005/provisioned IOPS-month above the default 3000 IOPS baseline, and $0.04/provisioned MiB/s-month above the default 125 MiB/s baseline.</p><p>AWS has provided a concise comparison table to highlight the differences between the gp2 and gp3 volume types:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PV5xBfXFggbVwNB5aCC7yw.png" /><figcaption>Comparison table between gp3 and gp2 EBS volume types</figcaption></figure><p>With the introduction of this new generation of general-purpose SSD-based EBS volumes, utilising gp2 is no longer economical or advantageous performance-wise, as gp2 volumes are more expensive and typically offer fewer baseline IOPS compared to gp3 volumes of the same size.</p><p>Although gp2 volumes begin to offer more IOPS than the baseline IOPS of gp3 for sizes exceeding 1 TiB, it remains more cost-effective to incur additional charges for matching the additional IOPS and throughput with gp3 than to opt for gp2 to gain the extra IOPS/throughput. In these cases, however, the amount of savings starts to decrease from the baseline of 20%, albeit still being advantageous.</p><p>If your EBS volume is <strong>smaller than 334 GiB, </strong>migrating from gp2 to gp3 will save you 20%, while delivering enormous gains in terms of performance.</p><p>For volumes <strong>larger than 334 GiB but smaller than 1 TiB,</strong> migrating to gp3 and paying for the additional throughput to match gp2’s 250 MiB/s would still save you money, while giving you better performance with those extra baseline IOPS. In this case, savings will range from 15% to 5%, depending on volume size.</p><p>For volumes <strong>larger than 1 TiB,</strong> migrating to gp3 and paying for the additional throughput and IOPS to match gp2’s 250 MiB/s and 3 IOPS per GiB would still save you money, with savings ranging from 15% to 7%.</p><p>In no cases using gp2 is better or cheaper than using gp3. That said, <strong>switching to gp3 is an obvious choice </strong>due to its cost-effectiveness and superior performance.</p><p>Additionally, the migration process has no disadvantages, as it can be <strong>completed without downtime and will not affect performance negatively.</strong> This is because the performance of the EBS volume during the modification is guaranteed to be at least equal to that of the original volume.</p><h3>How to migrate all gp2 volumes to gp3?</h3><p>A straightforward and smooth migration can be accomplished by running this simple Python script provided below. This script will automatically convert all of your gp2 volumes to gp3, in all regions, while matching their IOPS and throughput for volumes larger than 334 GiB.</p><p>By running this script, you will save costs on every volume migrated, up to 20%, while dramatically improving performance for smaller volumes, or at least matching the same performance levels for larger volumes.</p><p>This script will also calculate how much you saved from migrating your gp2 volumes to gp3, and output the effective savings amount.</p><pre>import boto3<br>from botocore.exceptions import ClientError<br><br>def calculate_gp3_cost(size_gib, iops, throughput):<br>    # gp3 pricing<br>    storage_cost_per_gib = 0.08  # $0.08/GB-month<br>    iops_cost = 0.005  # $0.005 per IOPS over 3000 IOPS<br>    throughput_cost = 0.04  # $0.04 per MB/s of throughput above 125 MB/s<br><br>    storage_cost = size_gib * storage_cost_per_gib<br>    extra_iops_cost = (iops - 3000) * iops_cost if iops &gt; 3000 else 0<br>    extra_throughput_cost = (throughput - 125) * throughput_cost if throughput &gt; 125 else 0<br><br>    return storage_cost + extra_iops_cost + extra_throughput_cost<br><br>def calculate_gp2_cost(size_gib):<br>    # gp2 pricing<br>    storage_cost_per_gib = 0.10  # $0.10/GB-month<br>    return size_gib * storage_cost_per_gib<br><br>def migrate_volume(ec2_client, volume_id, size_gib, region_name):<br>    savings = 0<br>    try:<br>        if size_gib &lt; 334:<br>            iops = 3000<br>            throughput = 125<br>        elif size_gib &lt; 1024:<br>            iops = 3000<br>            throughput = 250<br>        else:<br>            iops = size_gib * 3<br>            throughput = 250<br><br>        gp2_cost = calculate_gp2_cost(size_gib)<br>        gp3_cost = calculate_gp3_cost(size_gib, iops, throughput)<br>        savings = gp2_cost - gp3_cost<br><br>        response = ec2_client.modify_volume(<br>            VolumeId=volume_id,<br>            VolumeType=&#39;gp3&#39;,<br>            Iops=iops,<br>            Throughput=throughput<br>        )<br>        print(f&quot;Migrated volume {volume_id} of size {size_gib} GiB to gp3 in {region_name}. Savings: ${savings:.2f} per month.&quot;)<br>    except ClientError as e:<br>        print(f&quot;An error occurred: {e}&quot;)<br>    return savings<br><br>def list_and_migrate_volumes_in_region(region_name):<br>    ec2_client = boto3.client(&#39;ec2&#39;, region_name=region_name)<br>    total_savings = 0<br>    try:<br>        volumes = ec2_client.describe_volumes(<br>            Filters=[<br>                {&#39;Name&#39;: &#39;volume-type&#39;, &#39;Values&#39;: [&#39;gp2&#39;]}<br>            ]<br>        )<br>        if not volumes[&#39;Volumes&#39;]:<br>            return total_savings  # Return early if no volumes to migrate<br><br>        for volume in volumes[&#39;Volumes&#39;]:<br>            volume_id = volume[&#39;VolumeId&#39;]<br>            size_gib = volume[&#39;Size&#39;]<br>            savings = migrate_volume(ec2_client, volume_id, size_gib, region_name)<br>            total_savings += savings<br>    except ClientError as e:<br>        print(f&quot;An error occurred in {region_name}: {e}&quot;)<br>    return total_savings<br><br>def list_regions_and_migrate_volumes():<br>    ec2 = boto3.client(&#39;ec2&#39;)<br>    regions = [region[&#39;RegionName&#39;] for region in ec2.describe_regions()[&#39;Regions&#39;]]<br>    grand_total_savings = 0<br>    volumes_found = False<br><br>    for region in regions:<br>        total_savings = list_and_migrate_volumes_in_region(region)<br>        grand_total_savings += total_savings<br>        if total_savings &gt; 0:<br>            volumes_found = True<br>            print(f&quot;Total savings in {region}: ${total_savings:.2f} per month.&quot;)<br><br>    if not volumes_found:<br>        print(&quot;No gp2 volumes to migrate.&quot;)<br>    else:<br>        print(f&quot;Grand total savings from migrating all gp2 volumes to gp3: ${grand_total_savings:.2f} per month.&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    list_regions_and_migrate_volumes()</pre><h4>Prerequisites:</h4><ul><li>Ensure you have Python3 installed, with the boto3 extension;</li><li>Ensure you have AWS credentials with the necessary permissions to modify EBS volumes in all regions in the <strong><em>~/.aws/credentials</em> </strong>path; <strong>OR</strong></li><li>Alternatively, you can also export the AWS credentials as environment variables for a one-time run with the commands below:</li></ul><pre>export AWS_ACCESS_KEY_ID=&quot;your_access_key_id_here&quot;<br>export AWS_SECRET_ACCESS_KEY=&quot;your_secret_access_key_here&quot;<br>export AWS_DEFAULT_REGION=&quot;us-east-1&quot;</pre><p>To run this script, once confirmed that you meet all the prerequisites listed above, simply save it as a file <em>(for example gp2togp3.py)</em> and run the command below:</p><pre>python3 gp2togp3.py</pre><p>Example usage output:</p><pre>❯ python3 gp2togp3.py<br>Migrated volume vol-0f554746c24525f01 of size 520 GiB to gp3 in eu-west-1. Savings: $5.40 per month.<br>Migrated volume vol-03123800cba75b18f of size 20 GiB to gp3 in eu-west-1. Savings: $0.40 per month.<br>Migrated volume vol-087a04f1d3d88bf07 of size 2520 GiB to gp3 in eu-west-1. Savings: $22.60 per month.<br>Migrated volume vol-06b09798a7b6f21d3 of size 4020 GiB to gp3 in eu-west-1. Savings: $30.10 per month.<br>Migrated volume vol-0b55386bde1279329 of size 4520 GiB to gp3 in eu-west-1. Savings: $32.60 per month.<br>Migrated volume vol-0f2935d2360fdd2ed of size 2020 GiB to gp3 in eu-west-1. Savings: $20.10 per month.<br>Migrated volume vol-0a686b3a9aebbbf8f of size 3020 GiB to gp3 in eu-west-1. Savings: $25.10 per month.<br>Migrated volume vol-0d2d709a825421233 of size 1020 GiB to gp3 in eu-west-1. Savings: $15.40 per month.<br>Migrated volume vol-00766065b8e2ccc14 of size 1520 GiB to gp3 in eu-west-1. Savings: $17.60 per month.<br>Migrated volume vol-07ff6098fc4a188f6 of size 3520 GiB to gp3 in eu-west-1. Savings: $27.60 per month.<br>Total savings in eu-west-1: $196.90 per month.<br>Migrated volume vol-0de6269b523834350 of size 1520 GiB to gp3 in us-east-1. Savings: $17.60 per month.<br>Migrated volume vol-05c8fffff1e48fdcb of size 3020 GiB to gp3 in us-east-1. Savings: $25.10 per month.<br>Migrated volume vol-0f5bd9886a18cfb22 of size 2020 GiB to gp3 in us-east-1. Savings: $20.10 per month.<br>Migrated volume vol-05981da5774928178 of size 4020 GiB to gp3 in us-east-1. Savings: $30.10 per month.<br>Migrated volume vol-0d788bce161c9978a of size 2520 GiB to gp3 in us-east-1. Savings: $22.60 per month.<br>Migrated volume vol-0a45ded9ba633b92a of size 520 GiB to gp3 in us-east-1. Savings: $5.40 per month.<br>Migrated volume vol-06d300164bf986c32 of size 20 GiB to gp3 in us-east-1. Savings: $0.40 per month.<br>Migrated volume vol-04a27bbad19828bbf of size 4520 GiB to gp3 in us-east-1. Savings: $32.60 per month.<br>Migrated volume vol-0e85c18b59e418b8c of size 1020 GiB to gp3 in us-east-1. Savings: $15.40 per month.<br>Migrated volume vol-0b0cafa0f49767f28 of size 3520 GiB to gp3 in us-east-1. Savings: $27.60 per month.<br>Total savings in us-east-1: $196.90 per month.<br>Grand total savings from migrating all gp2 volumes to gp3: $393.80 per month.</pre><h3>Path to further savings on gp3 migration</h3><p>While this article focuses on a one-size-fits-all solution, you might be able to save even more by migrating to gp3, if you do not need those extra IOPS and throughput on volumes larger than 1 TiB.</p><p>In these cases, however, you would need to carefully analyse the usage of your application, to understand how many IOPS and how much throughput it needs, and modify the gp3 volumes to accommodate that.</p><p>When larger volumes do not need as many IOPS as 3 IOPS per GiB, you could end up saving more by simply not increasing the baseline IOPS, while the same goes for throughput.</p><p>Here at DoiT, our team is ready to learn more about you and your cloud engineering needs, to help you rightsize your EBS volumes for maximum performance and savings. <a href="https://www.doit.com/contact/">Get in touch, and let&#39;s chat!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c9762e58191" width="1" height="1" alt=""><hr><p><a href="https://medium.com/doit-international/migrate-all-your-ebs-volumes-from-gp2-to-gp3-to-improve-performance-while-saving-up-to-20-on-costs-8c9762e58191">Migrate all your EBS volumes from gp2 to gp3 to improve performance while saving up to 20% on costs</a> was originally published in <a href="https://medium.com/doit-international">DoiT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Troubleshooting AWS network throttling: A Comprehensive Guide]]></title>
            <link>https://medium.com/doit-international/troubleshooting-aws-network-throttling-a-comprehensive-guide-368811424148?source=rss-1ffb2fdc10e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/368811424148</guid>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[amazon-ec2]]></category>
            <dc:creator><![CDATA[Vilmar]]></dc:creator>
            <pubDate>Thu, 21 Mar 2024 10:02:20 GMT</pubDate>
            <atom:updated>2024-03-21T10:02:20.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pgvyr0_uBQFCA2DbAIxdZw.png" /></figure><h4>Table of Contents</h4><p>· <a href="#533c">The importance of understanding AWS Networking Limitations</a><br>· <a href="#6f67">What are the limitations?</a><br>· <a href="#d059">How is traffic shaped?</a><br>· <a href="#6ced">EC2 Placements and resource sharing</a><br>· <a href="#4d10">Troubleshooting bandwidth throttling</a><br> ∘ <a href="#9e5f">Internet Egress Bandwidth</a><br> ∘ <a href="#a488">Flow Limitations</a><br> ∘ <a href="#47b9">Micro-bursting</a><br> ∘ <a href="#5f5f">Reading CloudWatch network metrics</a><br>· <a href="#5ef7">Troubleshooting Connection Tracking Throttling</a><br>· <a href="#4024">Troubleshooting throttling to the Local Proxy Services</a><br>· <a href="#e08b">Troubleshooting Packet Throttling</a><br>· <a href="#4a94">References</a></p><h4>The importance of understanding AWS Networking Limitations</h4><p>In the vast landscape of AWS services, EC2 instances and the EC2 network stand as the foundational building blocks upon which most other AWS services are built, supporting various applications and services critical to the modern digital infrastructure. However, navigating the performance of these instances involves delving into the intricacies of AWS’s network, notably network throttling. Network throttling, which can manifest in various forms, directly influences the performance and scalability of EC2 instances and, by extension, many other services within the AWS ecosystem.</p><p>AWS implements network throttling through two primary mechanisms: bandwidth limitations and packets per second (PPS) restrictions. Bandwidth throttling affects the volume of data that can be transferred over the network in a given period, while PPS throttling limits the number of network packets that can be sent or received. These constraints are intricately designed to maintain the overall health and efficiency of the AWS infrastructure. Yet, they can pose significant challenges while seeking to optimise application performance and resource utilisation.</p><p>Compounding the challenge is the need for more official documentation on some aspects of AWS network throttling. Information regarding the specifics of how and when AWS applies these throttling mechanisms is hard to find, leaving developers to navigate a labyrinth of forums, user experiences, and trial-and-error investigations to understand and mitigate the impacts on their services. This lack of clear, accessible documentation on AWS network throttling adds a layer of complexity to managing and optimising network performance within the AWS ecosystem.</p><p>In this article, we will piece together the fragmented puzzle of AWS network throttling information to paint a clear and comprehensive picture of how AWS implements throttling mechanisms for the EC2 network.</p><h3>What are the limitations?</h3><p>On modern generations of EC2 instances built on Nitro, AWS exposes a few different metrics as counters of packets that are shaped by network throttling, which are listed in their official documentation [1].</p><ul><li><strong>bw_in_allowance_exceeded:</strong> The number of packets queued or dropped because the inbound aggregate bandwidth exceeded the maximum for this instance type/size;</li><li><strong>bw_out_allowance_exceeded: </strong>The number of packets queued or dropped because the outbound aggregate bandwidth exceeded the maximum for this instance type/size;</li><li><strong>conntrack_allowance_exceeded:</strong> The number of packets dropped because connection tracking exceeded the maximum for the instance and new connections could not be established. This can result in packet loss for traffic to or from the instance.</li><li><strong>conntrack_allowance_available:</strong> The number of tracked connections that can be established by the instance before hitting the Connections Tracked allowance of that instance type.</li><li><strong>linklocal_allowance_exceeded: </strong>The number of packets dropped because the PPS of the traffic to local proxy services exceeded the maximum for the network interface. This impacts traffic to the DNS service, the Instance Metadata Service, and Amazon Time Sync Service.</li><li><strong>pps_allowance_exceeded: </strong>The number of packets queued or dropped because the bidirectional PPS exceeded the maximum for the instance.</li></ul><p>While these metrics are only exposed to instances built on Nitro via the ENA driver, the limitations are not exclusive to Nitro instances. Non-Nitro instances, virtualised in Xen, will also contain network limitations <em>(often lower than Nitro instances inclusive)</em>, however, it makes sense that AWS can only expose these custom metrics on their own ENA proprietary driver.</p><p>These counters can be viewed from the instance’s side with the command below:</p><pre>[root@ip-172-31-82-248 ~]# ethtool -S eth0 | grep allowance<br>     bw_in_allowance_exceeded: 0<br>     bw_out_allowance_exceeded: 0<br>     pps_allowance_exceeded: 0<br>     conntrack_allowance_exceeded: 0<br>     linklocal_allowance_exceeded: 0<br>     conntrack_allowance_available: 136812</pre><h3>How is traffic shaped?</h3><p>The wording in AWS documentation on how the traffic is shaped once a limit is reached is very important here, as it states that packets are <strong>queued or dropped. </strong>However, we do not know how long these packets are queued for.</p><p>While there is no way of telling if throttling was applied in the form of queued or dropped packets, from testing, we can tell that usually, when the network traffic hits the limits only slightly, the shaping will be queueing only, and often, the queuing is not longer than a couple of milliseconds, causing little to no impact.</p><p>Dropping packets only seems to take place once the limits are heavily pushed, and even in those cases, whenever the dropping is little enough, TCP-based applications will often recover from it fairly easily, by simply retransmitting the lost packets.</p><p>Moreover, the ENA metrics on network throttling are packet counters since the last ENA reset, so they are <strong>a sum of packets that were shaped.</strong></p><p>Checking for these counters and finding a non-zero counter might not always be an issue, since the data there might be stale. To better visualise these, you can also export them as a CloudWatch metric via the CloudWatch Agent [2], which makes it possible to visualise these over time and understand whenever the counter is still increasing, and by how many packets per second.</p><h3>EC2 Placements and resource sharing</h3><p>EC2 instances are virtual machines; and a virtual machine is essentially another abstraction layer from the physical hardware, which is shared across multiple tenants.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*s5A7XAhk0Ks0l-gdRmbr6w.png" /></figure><p>As a rough rule,<strong> the larger an EC2 instance size is within its family, the less it will share the hardware with other tenants,</strong> until it is the only virtual machine within that hardware — or an actual metal instance.</p><p>So, you can assume that, for example, a c5.24xlarge instance size, which is the largest size for that family, is very likely to have the entire underlying host for itself, not sharing its network limits with any other tenants, which means it will have the entire hardware&#39;s capability for itself, and much larger network limits than a smaller instance size.</p><p>On the other hand, a c5.large size, which is the smallest size for that family, is very likely to be sharing the underlying host with multiple tenants. Hence it will have 1/x the capability of that underlying hardware, being x the number of maximum tenants for that hardware.</p><p>While we do not have any visibility on how these placements work in the backend, this gives a rough idea that, as a general rule, <strong>the larger size an instance is, the higher the network limits will be.</strong></p><p>Moreover, when you consider traffic that is leaving the instance, there might also be constraints that take into consideration the network stack outside of the hypervisor, due to switches and routers further up the stack.</p><p>While we also have no visibility on AWS&#39; network stack for EC2, a typical datacenter&#39;s network stack would look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FmUvc_I9hu6ctBkuTEHWrQ.png" /></figure><p>AWS does allow us, however, to define <strong>placement strategies [3]</strong>, which will regulate how far instances are from each other. This also affects not only latency but also the amount of bandwidth per flow for flow limits.</p><p>Creating a <strong>Cluster Placement Group </strong>would mean that instances would be as close to each other as possible — such as within the same underlying host; within the same ToR switch; within the same aggregate switch; etc. This strategy would ensure the lowest latency possible between instances in that placement group, and the highest bandwidth limits per flow possible.</p><p>If you do not define any placement strategies, AWS&#39; will allocate your instances randomly according to capacity, which means that sometimes out of pure luck instances can be within the same ToR/aggregate switch; and some other times not.</p><p><strong>Each time you stop and start an EC2 instance, it will be re-placed somewhere different across AWS&#39; infrastructure</strong> [4], meaning it can be moved in-placement <em>(close to your other instance)</em>, or out-of-placement <em>(far from your other instance)</em>, and being in or out of placement, affects latency and maximum throughput per flow.</p><p>Due to this phenomenon, I have seen cases before where two EC2 instances that hosted low-latency and high throughput per flow applications were in-placement out of pure luck, but once they were stop/started landing out-of-placement, and then started having network issues out-of-blue, due to reduced maximum throughput per flow after the move to out-of-placement and increased latency.</p><p>For this reason, it is important to consider your application&#39;s nature and define a placement strategy in advance for your AWS infrastructure.</p><p>Of course cluster placement is not the only valid strategy either, since placing the instances as close as possible will also increase the likelihood of all of them being affected by hardware issues. If all of your instances are within the same underlying host, and there is a hardware failure for that host, then they are all gone simultaneously.</p><p>Alternatively, AWS also offers a <strong>spread placement group </strong>strategy, which does the exact opposite, keeping your instances as far as possible physically.</p><h3>Troubleshooting bandwidth throttling</h3><p>While bandwidth throttling is the most straightforward network limitation that AWS imposes, a few things can make it a bit more challenging.</p><p>First, it&#39;s necessary to establish the real bandwidth capability of each instance type, as AWS has two different bandwidth limits for EC2 instances: the <strong>baseline bandwidth</strong>, and the <strong>burstable ceiling</strong>.</p><p>Whenever the documentation says <em>&quot;Up to&quot; </em>an amount, it refers to the burstable ceiling — you can hit that maximum bandwidth, but only for a specific amount of time, until you run out of burst credits. The larger the instance size, the less it will share the underlying hardware, and the longer you can burst.</p><p>Once the instance runs out of those burst credits, the limit will then drop to the baseline <em>(much smaller than the burstable limit)</em>, and network throttling will start.</p><p>For instance sizes that AWS says &quot;25 Gigabit&quot; or any other amount without the term <em>&quot;Up to&quot;</em>, that is your baseline limit, and there is no burstable ceiling.</p><p>For a few instance types, AWS discloses both the baseline bandwidth, and the burstable bandwidth in its documentation [5], although only a few families are disclosed.</p><p>As for how long you can burst on burstable instances, this is never disclosed by AWS. However, with some testing, it should not be that hard for us to discover it.</p><p>Launching a c5.large and a c5.24xlarge on my own AWS account, we can figure out these limits for a c5.large instance size, for example, using iperf3.</p><pre>[root@ip-172-31-82-248 ~]# iperf3 -c 172.31.23.48 -i 60 -t 480 -P 5<br>Connecting to host 172.31.23.48, port 5201<br>[  5] local 172.31.82.248 port 42202 connected to 172.31.23.48 port 5201<br>[  7] local 172.31.82.248 port 42204 connected to 172.31.23.48 port 5201<br>[  9] local 172.31.82.248 port 42208 connected to 172.31.23.48 port 5201<br>[ 11] local 172.31.82.248 port 42212 connected to 172.31.23.48 port 5201<br>[ 13] local 172.31.82.248 port 42218 connected to 172.31.23.48 port 5201<br>[ ID] Interval           Transfer     Bitrate         Retr  Cwnd<br>[  5]   0.00-60.05  sec  11.4 GBytes  1.64 Gbits/sec  19684    376 KBytes       <br>[  7]   0.00-60.05  sec  11.2 GBytes  1.60 Gbits/sec  17814    341 KBytes       <br>[  9]   0.00-60.05  sec  11.5 GBytes  1.65 Gbits/sec  18713    428 KBytes       <br>[ 11]   0.00-60.05  sec  16.8 GBytes  2.40 Gbits/sec  24552    507 KBytes       <br>[ 13]   0.00-60.05  sec  17.0 GBytes  2.44 Gbits/sec  22710    524 KBytes       <br>[SUM]   0.00-60.05  sec  68.0 GBytes  9.72 Gbits/sec  103473             <br>- - - - - - - - - - - - - - - - - - - - - - - - -<br>[  5]  60.05-120.05 sec  11.4 GBytes  1.64 Gbits/sec  19955    341 KBytes       <br>[  7]  60.05-120.05 sec  11.3 GBytes  1.62 Gbits/sec  18304    428 KBytes       <br>[  9]  60.05-120.05 sec  11.4 GBytes  1.64 Gbits/sec  18976    428 KBytes       <br>[ 11]  60.05-120.05 sec  16.8 GBytes  2.41 Gbits/sec  25220    498 KBytes       <br>[ 13]  60.05-120.05 sec  16.9 GBytes  2.42 Gbits/sec  23265    481 KBytes       <br>[SUM]  60.05-120.05 sec  67.9 GBytes  9.72 Gbits/sec  105720             <br>- - - - - - - - - - - - - - - - - - - - - - - - -<br>[  5] 120.05-180.05 sec  11.5 GBytes  1.65 Gbits/sec  19194    454 KBytes       <br>[  7] 120.05-180.05 sec  11.1 GBytes  1.59 Gbits/sec  18328    454 KBytes       <br>[  9] 120.05-180.05 sec  11.5 GBytes  1.64 Gbits/sec  19259    358 KBytes       <br>[ 11] 120.05-180.05 sec  16.7 GBytes  2.39 Gbits/sec  24946    542 KBytes       <br>[ 13] 120.05-180.05 sec  17.1 GBytes  2.45 Gbits/sec  23032    323 KBytes       <br>[SUM] 120.05-180.05 sec  67.9 GBytes  9.72 Gbits/sec  104759             <br>- - - - - - - - - - - - - - - - - - - - - - - - -<br>[  5] 180.05-240.05 sec  11.5 GBytes  1.65 Gbits/sec  20069    446 KBytes       <br>[  7] 180.05-240.05 sec  11.2 GBytes  1.60 Gbits/sec  17967    463 KBytes       <br>[  9] 180.05-240.05 sec  11.4 GBytes  1.64 Gbits/sec  18942    323 KBytes       <br>[ 11] 180.05-240.05 sec  16.7 GBytes  2.39 Gbits/sec  24645    498 KBytes       <br>[ 13] 180.05-240.05 sec  17.0 GBytes  2.44 Gbits/sec  22380    507 KBytes       <br>[SUM] 180.05-240.05 sec  67.9 GBytes  9.72 Gbits/sec  104003             <br>- - - - - - - - - - - - - - - - - - - - - - - - -<br>[  5] 240.05-300.05 sec  7.89 GBytes  1.13 Gbits/sec  13304    323 KBytes       <br>[  7] 240.05-300.05 sec  7.85 GBytes  1.12 Gbits/sec  12274    498 KBytes       <br>[  9] 240.05-300.05 sec  7.89 GBytes  1.13 Gbits/sec  12763    350 KBytes       <br>[ 11] 240.05-300.05 sec  11.5 GBytes  1.65 Gbits/sec  16480    454 KBytes       <br>[ 13] 240.05-300.05 sec  11.9 GBytes  1.71 Gbits/sec  15472    647 KBytes       <br>[SUM] 240.05-300.05 sec  47.1 GBytes  6.74 Gbits/sec  70293             <br>- - - - - - - - - - - - - - - - - - - - - - - - -<br>[  5] 300.05-360.05 sec   878 MBytes   123 Mbits/sec    0    323 KBytes       <br>[  7] 300.05-360.05 sec   879 MBytes   123 Mbits/sec    0    498 KBytes       <br>[  9] 300.05-360.05 sec   878 MBytes   123 Mbits/sec    0    350 KBytes       <br>[ 11] 300.05-360.05 sec  1.31 GBytes   188 Mbits/sec    0    454 KBytes       <br>[ 13] 300.05-360.05 sec  1.31 GBytes   188 Mbits/sec    0    647 KBytes       <br>[SUM] 300.05-360.05 sec  5.20 GBytes   745 Mbits/sec    0             <br>- - - - - - - - - - - - - - - - - - - - - - - - -<br>[  5] 360.05-420.05 sec   880 MBytes   123 Mbits/sec    0    323 KBytes       <br>[  7] 360.05-420.05 sec   880 MBytes   123 Mbits/sec    0    498 KBytes       <br>[  9] 360.05-420.05 sec   881 MBytes   123 Mbits/sec    0    350 KBytes       <br>[ 11] 360.05-420.05 sec  1.31 GBytes   188 Mbits/sec    0    454 KBytes       <br>[ 13] 360.05-420.05 sec  1.31 GBytes   188 Mbits/sec    0    647 KBytes       <br>[SUM] 360.05-420.05 sec  5.20 GBytes   745 Mbits/sec    0             <br>- - - - - - - - - - - - - - - - - - - - - - - - -<br>[  5] 420.05-480.05 sec   782 MBytes   109 Mbits/sec    0    323 KBytes       <br>[  7] 420.05-480.05 sec   933 MBytes   130 Mbits/sec    0    498 KBytes       <br>[  9] 420.05-480.05 sec   932 MBytes   130 Mbits/sec    0    350 KBytes       <br>[ 11] 420.05-480.05 sec  1.31 GBytes   187 Mbits/sec    0    454 KBytes       <br>[ 13] 420.05-480.05 sec  1.31 GBytes   187 Mbits/sec    0    647 KBytes       <br>[SUM] 420.05-480.05 sec  5.20 GBytes   745 Mbits/sec    0             <br>- - - - - - - - - - - - - - - - - - - - - - - - -<br>[...]</pre><p>What we have above is iperf3 connecting from my c5.large instance to the larger c5.24xlarge <em>(so we are sure the c5.large limits will be hit first, and that&#39;s what we would get as a limiter)</em>, reporting in intervals of 60s <em>(-i 60)</em>, running for 8 minutes <em>(-t 480)</em>, with 5 parallel streams <em>(-P 5).</em></p><p>From this output, we can see that for the first 5 minutes, the bitrate was roughly 10Gbps, which AWS adverts as <em>&quot;Up to&quot; </em>for c5.large instances. However, <strong>after 5 minutes, the Bitrate lowers to 750Mbps only.</strong></p><p>This now gives us two undocumented limits for c5.large instances:</p><ul><li>750Mbps baseline bandwidth;</li><li>5-minute burst limit of up to 10Gbps.</li></ul><p>Now, <strong>we know that c5.large instances have 750Mbps of baseline bandwidth and can burst up to 10Gbps for 5 minutes only.</strong></p><p>We can also see that after the network throttling started to kick in, the ENA counters for outbound bandwidth shaping also started increasing:</p><pre>[root@ip-172-31-82-248 ~]# ethtool -S ens5|grep exceeded<br>     bw_in_allowance_exceeded: 0<br>     bw_out_allowance_exceeded: 42427304<br>     pps_allowance_exceeded: 0<br>     conntrack_allowance_exceeded: 0<br>     linklocal_allowance_exceeded: 0<br>[root@ip-172-31-82-248 ~]# </pre><h4>Internet Egress Bandwidth</h4><p>EC2 instances can achieve their maximum bandwidth potential whenever the traffic source and destination are within AWS and in the same region. But this changes whenever the source or destination of traffic is outside the region, either in a different AWS region, or being routed to the Internet.</p><p>In these cases, if the instance size you are using is massive and has a minimum of 32 vCPUs, the bandwidth limit to other regions or the internet will be 50% of its network bandwidth. [6]</p><p>If the instance size has less than 32 vCPUs, then the limit is fixed at a maximum of 5Gbps. [6]</p><h4>Flow Limitations</h4><p>Another less obvious bandwidth limitation, is that AWS limits the amount of bandwidth per flow. The maximum amount of throughput per flow is 5Gbps, irrespective of instance family or size, and this is a hard limit. [6]</p><p>One of the only two ways of increasing this limit, is if both source and destination instances are within the same EC2 placement. This can either be achieved by placing the instances within the same cluster placement groupor by pure luck if they land within the same aggregate switches, as previously explained in the EC2 Placement section of this article.</p><p>In cases where both the source and destination instances are within the same EC2 placement, the maximum bandwidth per flow is 10Gbps. [6]</p><p>The other way is by using ENA Express on eligible instances within the same subnet, where the limit will be 25 Gbps per flow between those instances. [6]</p><p>Alternatively, whenever possible you should use multi-flow traffic, to ensure maximum bandwidth capability and performance, as this will also cause an impact on PPS limiters that we will see further down.</p><p>One important thing to mention here, is that <strong>throttling due to flow limitations is not exposed anywhere in the ENA throttling metrics.</strong></p><p>We can easily tell that again with iperf3. If I run a single stream from my c5.large <em>(which should be able to achieve 10Gbps)</em> to my c5.24xlarge, which are out-of-placement, we can tell the maximum throughput in a single flow gets limited to 5Gbps:</p><pre>[root@ip-172-31-92-221 ~]# iperf3 -c 172.31.23.48 -t 60 -P 1<br>Connecting to host 172.31.23.48, port 5201<br>[  5] local 172.31.92.221 port 42472 connected to 172.31.23.48 port 5201<br>[ ID] Interval           Transfer     Bitrate         Retr  Cwnd<br>[  5]   0.00-1.00   sec   594 MBytes  4.98 Gbits/sec    0   1.43 MBytes       <br>[  5]   1.00-2.00   sec   592 MBytes  4.97 Gbits/sec    0   1.52 MBytes       <br>[  5]   2.00-3.00   sec   592 MBytes  4.97 Gbits/sec    0   1.52 MBytes       <br>[...]</pre><p>However, no counters increased in the ENA throttling metrics:</p><pre>[root@ip-172-31-92-221 ~]# ethtool -S ens5|grep exceeded<br>     bw_in_allowance_exceeded: 0<br>     bw_out_allowance_exceeded: 0<br>     pps_allowance_exceeded: 0<br>     conntrack_allowance_exceeded: 0<br>     linklocal_allowance_exceeded: 0</pre><p>This is especially important because it means that network throttling due to flow limitations is silent, and very hard to spot when it is happening.</p><h4>Micro-bursting</h4><p>Another consideration when it comes to bandwidth throttling, is micro-bursting. This happens when you hit the bandwidth limits very briefly, which is often hard to spot.</p><p>The typical scenario for this situation would be when the ENA throttling metrics are increasing very slowly, but whenever you check CloudWatch metrics for network traffic, you don&#39;t see it ever reaching your bandwidth ceiling.</p><p>AWS throttling happens at incredibly small intervals, and while we do not have any visibility on how quickly that happens, I have already experienced situations in which only sub-second measurements could spot micro-bursting.</p><p>CloudWatch on the other hand, has data points in 5-minute intervals by default, and with enhanced monitoring, these can be lowered to 1-minute intervals.</p><p>Sometimes, the burst is so short that it gets diluted in the 5-minute intervals that CloudWatch offers, and you can&#39;t see them.</p><p>While the easiest solution here is to trust that AWS ENA counters are correct, even if you can&#39;t spot the traffic peaks, by using the CloudWatch Agent, it is possible to have datapoints as low as 1s, which then should be able to catch most bandwidth peaks.</p><p>Beyond that, the solution would be to compare the amount of traffic in the ENA RX/TX queues, versus the amount of shaping reported.</p><p>However, <strong>in most scenarios of micro-bursting, the amount of shaping isn&#39;t significant enough to worry about in the first place, as the shaping will be majorly queueing,</strong> and if using TCP-based applications, it would also easily recover from small losses.</p><h4>Reading CloudWatch network metrics</h4><p>Another common mistake is misunderstanding the CloudWatch network metrics. While all AWS&#39; network limits are in bits per second, CloudWatch network metrics are in bytes over a period of time. This makes it so confusing to actually understand how close to the bandwidth ceiling you are by simply looking at the network metrics <em>NetworkIn</em> and <em>NetworkOut</em>.</p><p>In my example c5.24xlarge instance, if we open <em>NetworkIn</em> for example, it will show us something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ySbII1eVffaMhupZl6eaOw.png" /></figure><p>Here, one could easily get fooled into believing that this instance peaked above 50Gbps of inbound network traffic at 09:20; however, that&#39;s incorrect.</p><p>To understand the actual network traffic in <em>bps</em>, we must change the statistic to <em>Sum</em>, and divide that by the period in seconds <em>(by default 5 minutes)</em>, to get an average traffic per second during that interval.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8K_kikQbKmnBxLeGkAtZQ.png" /></figure><p>In this case, we will divide the total bytes of that data point <em>(299800135974) </em>by 300 seconds <em>(5 minutes)</em>, and obtain 999333786.58 bytes per second.</p><p>Then, we must convert bytes into bits. To simplify things, we can convert it directly into Mbps by multiplying it by <em>0.000008</em>, as 1 byte per second is equal to 0.000008 Mbps.</p><p>Once converted, we can tell that <strong>this metric actually shows us an inbound traffic average of 7994 Mbps during that 5-minute period,</strong> which is very far from the initial impression of 50 Gbps.</p><p>To get the total network traffic for that period, we would also have to convert <em>NetworkOut</em>, and add both amounts.</p><h3>Troubleshooting Connection Tracking Throttling</h3><p>Moving on from bandwidth limitations, AWS also imposes a limitation on how many connections are tracked, after which it will start refusing new connections.</p><p>This can be a major pain, as once this limit is reached, AWS will start refusing any new connections to your EC2 instance, until the number of connections drops back to a lower amount than the maximum permitted.</p><p>Until very recently, none of this was disclosed by AWS, and there was no mention of these limits in the AWS documentation. Luckily, AWS recently started disclosing the maximum amount of connections tracked per EC2 instance type, but only for modern generation instances based on Nitro.</p><p>While these limits also exist on non-Nitro instances, there is no disclosure of the limits, and the only way to find them out would be by testing at how many connections your instance starts refusing new connections.</p><p>The maximum amount of connections tracked on a Nitro instance can be found with the command below:</p><pre>[root@ip-172-31-92-221 ~]# ethtool -S ens5|grep conntrack_allowance_available<br>     conntrack_allowance_available: 136813<br>[root@ip-172-31-92-221 ~]#</pre><p>The only reason why this even exists in the first place is due to security groups. Security groups are stateful, which means that they track the connections via conntrack to allow the responses to inbound traffic to flow out of the instance regardless of outbound security group rules, and vice versa.</p><p>That said, <strong>there is a way of bypassing this limitation, without increasing the instance size by simply not using security groups.</strong></p><p>Whenever a security group has <strong>inbound and outbound rules that allow all traffic, those flows will be marked as <em>NOTRACK</em>,</strong> and they won&#39;t be tracked by AWS, hence not counting towards the conntrack allowance. [7]</p><p>Alternatively, stateless network ACLs can be used, or even iptables rules directly, which can either be stateless or stateful, since in the latter case you would have control over the conntrack in Linux from the instance side, and would be able to increase the limits as needed.</p><p>The only exception to this workaround is that connections to other specific AWS services, listed below, will always be automatically tracked, regardless of the security group configuration, as this is needed to ensure symmetric routing. In this case, the only workaround would be to increase instance size. [7]</p><ul><li>Egress-only internet gateways</li><li>Gateway Load Balancers</li><li>Global Accelerator accelerators</li><li>NAT gateways</li><li>Network Firewall firewall endpoints</li><li>Network Load Balancers</li><li>AWS PrivateLink (interface VPC endpoints)</li><li>Transit gateway attachments</li><li>AWS Lambda (Hyperplane elastic network interfaces)</li></ul><h3>Troubleshooting throttling to the Local Proxy Services</h3><p>AWS offers a few different services as local proxies within EC2, these being the AWS DNS Resolver <em>(either the second IP of your VPC subnet, or 169.254.169.253 in any EC2 instance)</em>, the AWS-provided NTP server <em>(169.254.169.123)</em>, and the Instance Metadata Service <em>(169.254.169.254)</em>.</p><p>These services share a hard limit of 1024 pps <em>(packets per second)</em> per ENI interface. Any more than that, and the interface will be throttled due to <em>linklocal_allowance_exceeded</em>.</p><p>Usually, throttling in this case comes from an excessive utilisation of the Instance Metadata Service. Having an IMDS query inside a recursive function that is used often, for example, can easily cause one to hit this limit. Keep in mind that the limit is in packets per second, and an HTTP IMDS request will use multiple network packets to be completed, hence this limit is not equivalent to 1024 queries per second.</p><p>Having a mindful usage of IMDS, and caching some of the results where possible, is the way to go here, since this is a hard limit that can not be changed, irrespective of instance size.</p><p>Another common case for throttling here, would be many DNS queries, and the solution in that case, would be to implement a local DNS cache.</p><p>Whenever the ENA counters for <em>linklocal_allowance_exceeded </em>is increasing, you can pinpoint which of these services is causing the throttling by doing a packet capture for the traffic towards those service IPs, and isolating if the traffic is DNS, HTTP or NTP.</p><h3>Troubleshooting Packet Throttling</h3><p>Another form of throttling within AWS is due to the number of packets per second, which is where things get a bit more complicated, as there is minimal documentation on these limitations.</p><p>Even if an EC2 instance is under the maximum bandwidth limit, its network traffic can still be throttled due to hitting the maximum allowed number of packets per second for that instance. The limit here is per instance, and not per ENI like in the <em>linklocal_allowance_exceeded</em>.</p><p>However, AWS does not disclose the allowed maximum number of packets per second for any EC2 instance types without an NDA, and it is also not fixed, meaning it can vary depending on what type of packets the traffic consists of.</p><p>The PPS limits for an EC2 instance will vary depending on: [8]</p><ul><li>If the traffic is TCP or UDP;</li><li>Number of flows;</li><li>Packet size;</li><li>New connections or existing connections <em>(limitation of TCP SYN);</em></li><li>and based on applied security group rules.</li></ul><p>This makes it almost impossible to establish a fixed PPS limit with any certainty, even by exhaustive testing, since the actual limitation will depend on the actual pattern of the network traffic.</p><p>For instance, an application that generates many new connections, will likely hit the limitation of TCP SYN, and hence hit the PPS limit, much sooner than an application that more often relies on existing connections.</p><p>While there are ways of stress testing the instance with packets to have a rough estimation of the PPS limits, and AWS outlines the steps on how to test that <a href="https://repost.aws/knowledge-center/ec2-instance-network-pps-limit">in this article</a> [8], that way is much less reliable than using iperf for discovering the bandwidth limits.</p><p>The preferred alternative is to do stress testing on the actual hosted application and monitor the ENA metrics for PPS throttling since this will consider the application network patterns.</p><p>Luckily, these limitations are often not that small, and the bandwidth limits are often hit first. Still, the preferred traffic patterns here would be an application with TCP traffic that uses mostly existing connections, larger packet sizes, many different flows, and has security groups allowing all inbound and outbound traffic on those ports for no tracking.</p><p>In the case of throttling, adapting the traffic pattern to best suit the pattern mentioned above should help, or alternatively, increasing instance size.</p><h3>References</h3><ul><li>[1] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-network-performance-ena.html#network-performance-metrics">Metrics for the ENA driver</a></li><li>[2] <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-network-performance.html">Collect network performance metrics</a></li><li>[3] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html">Placement groups</a></li><li>[4] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Stop_Start.html#what-happens-start">What happens when you start an instance</a></li><li>[5] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/memory-optimized-instances.html#memory-network-perf">Network Performance</a></li><li>[6] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-network-bandwidth.html">Amazon EC2 instance network bandwidth</a></li><li>[7] <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/security-group-connection-tracking.html">Connection Tracking</a></li><li>[8] <a href="https://repost.aws/knowledge-center/ec2-instance-network-pps-limit">EC2 Instance Network PPS Limit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=368811424148" width="1" height="1" alt=""><hr><p><a href="https://medium.com/doit-international/troubleshooting-aws-network-throttling-a-comprehensive-guide-368811424148">Troubleshooting AWS network throttling: A Comprehensive Guide</a> was originally published in <a href="https://medium.com/doit-international">DoiT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>