How does Amazon Aurora for MySQL or PostgreSQL distribute workload between reader nodes?
You can use the reader endpoint to connect to the reader nodes in an Amazon Aurora cluster. To understand how Amazon Aurora distributes the workload between reader endpoints, see using the reader endpoint.
To verify the rotation distribution of connections, run a shell command. To see how Aurora attempts to load balance your connections to the reader endpoint, run a command like this:
while sleep 5; do dig xxx-cluster.cluster-ro-xxxxxx.us-east1.rds.amazonaws.com|grep CNAME; done
Each time you resolve the reader endpoint, you get an instance IP address that you can connect to. This IP address is chosen based on the rotation distribution.
The DB connection to each read replica might not be distributed evenly in these scenarios:
- If a client caches DNS information, you might see a discrepancy in the distribution of the connections. This happens when the client connects to the same Aurora replica using cached connection settings. DNS caching can occur anywhere, including your network later, the operating system, or the application container.
- If the DB instance is in the process of failing over, then the reader endpoint might direct connections to the primary DB instance for the DB cluster for a short time. This happens when an Aurora replica is promoted to the primary DB instance.
- If the read replica is unavailable or fails a health check, then the connections might not be distributed evenly.
- If the application is written in Java and the TTL caching wasn't disabled or adjusted, then the connections might not be distributed evenly. For example, Java virtual machines (JVMs) might cache DNS indefinitely, if the DNS caching isn't configured otherwise. For more information, see setting the JVM TTL for DNS name lookups.
- If the connections occur at the same time, then the connections are sent to the same reader endpoint.
You can use custom endpoints if you want more flexibility when managing the distribution of your workload. For example, you might use custom endpoints if you use different DB instance sizes within the cluster. For more information, see using custom endpoints.
Amazon Aurora connection management