- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
The following article is the best source for your question
In summary
AWS NAT Gateway uses a hash-based system to distribute outgoing traffic among the available Elastic IPs. This hash is based on five factors: source IP, source port, destination IP, destination port, and the protocol being used.
The purpose of this design is to ensure consistency or "stickiness" in a connection. Once a connection is made between a source and a destination, it's important that all packets of that connection follow the same path - in other words, they use the same Elastic IP. This is crucial for applications that require session stickiness.
However, this hash-based system does not necessarily guarantee an equal distribution of traffic among all the Elastic IPs. The way traffic is spread largely depends on the variation in the five factors used in the hash. If there's little variation in these factors, it could result in an uneven distribution of traffic among the Elastic IPs.
In your tests, if you're sending traffic with the exact same values for all five factors, theoretically, it should always be hashed to the same Elastic IP. But keep in mind that many client-side libraries and systems will automatically assign a new source port for each new connection, which might explain the variation you're seeing even when other fields are constant.
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 7 Monaten
- AWS OFFICIALAktualisiert vor 7 Monaten
- AWS OFFICIALAktualisiert vor einem Jahr
Another thing that helps hash balances is a prime number for the number of buckets (in this case, IPs). So try 5 or 7 IPs and see if that helps. For why prime numbers work best, see https://www.learnhowtoprogram.com/computer-science/bit-manipulation-and-hashing/optimizing-hashing-algorithms
I found out that apart from these 5 tuples, in case of TCP traffic, TCP Sequence number is also a factor. So for TCP traffic, It would be random. The algorithm for TCP traffic is similar as of Network load balancer. https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html#network-load-balancer-overview