Skip to content

High Latency When Querying Aurora MySQL from Cross-AZ EC2 Instance

0

I have two EC2 instances running in different Availability Zones within the same AWS Region, along with an Aurora MySQL 8 RDS cluster that has a single instance in one of the AZs.

When executing a query from the EC2 instance in the same AZ as the Aurora instance, the query completes in 18-20ms. However, when running the same query from the EC2 instance in the other AZ, the execution time increases to 39-40ms, nearly 2x the latency.

I understand that AWS documentation mentions some additional latency for cross-AZ communication, but a 2x increase seems higher than expected.

Note: These EC2 instances are plain Ubuntu machines with only MySQL client installed and a SQL query file. There are no applications or workloads running on them.

What could be causing this significant latency difference, and what optimizations or best practices can help mitigate it?

asked 2 years ago645 views

1 Answer
0

The latency difference you're experiencing between cross-AZ and same-AZ queries to your Aurora MySQL cluster is not uncommon, although a 2x increase is indeed on the higher side. Several factors could contribute to this latency:

  1. Network Path: Cross-AZ communication requires data to travel a longer physical distance, which naturally increases latency. While AWS has optimized its network infrastructure, some latency increase is unavoidable.

  2. Synchronous Replication: If you're using a Multi-AZ deployment, the increased latency could be partly due to synchronous data replication between Availability Zones. This ensures data consistency but can impact write and commit latency.

  3. Network Configuration: The network setup of your EC2 instances and VPC could influence latency. Ensure that you're using the latest generation of EC2 networking features, such as Elastic Network Adapter (ENA).

To mitigate this latency issue and optimize performance, consider the following approaches:

  1. Use Aurora Read Replicas: If your workload allows, you can create Aurora Read Replicas in different AZs. This allows you to route read queries to the nearest replica, reducing cross-AZ latency.

  2. Optimize EC2 Network Performance: Ensure your EC2 instances are configured for optimal network performance. This includes using instances with enhanced networking support and configuring the ENA driver correctly.

  3. Analyze Query Performance: Use tools like EXPLAIN to analyze your queries and ensure they're optimized. Sometimes, query optimization can significantly reduce execution time, mitigating the impact of network latency.

  4. Consider Aurora Global Database: For applications that require even lower latency across regions, Aurora Global Database can provide sub-second replication across AWS Regions.

  5. Use Connection Pooling: Implementing connection pooling can help reduce the overhead of establishing new connections for each query, which may be more noticeable in cross-AZ scenarios.

  6. Evaluate Workload Distribution: If possible, consider distributing your workload so that instances primarily query Aurora instances in the same AZ.

  7. Monitor and Tune: Continuously monitor your database performance using Amazon CloudWatch and Performance Insights. This can help you identify and address specific causes of latency.

Remember that some level of increased latency for cross-AZ communication is expected and is a trade-off for the increased availability and fault tolerance that multi-AZ deployments provide. If the latency difference continues to be a significant issue after implementing these optimizations, you may want to consult with AWS support for a more in-depth analysis of your specific setup.

Sources
Improve network latency for Linux based EC2 instances - Amazon Elastic Compute Cloud
Multi-AZ DB instance deployments for Amazon RDS - Amazon Relational Database Service

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.