If your application runs on an ECS instance and needs to connect to an ApsaraDB RDS database, we recommend connecting over the internal network. This approach improves access speed and enhances security.
For step-by-step instructions, see Connect to an ApsaraDB RDS instance.
Troubleshoot internal network connection latency
If you experience high latency when an ECS instance connects to ApsaraDB RDS over the internal network, but SQL queries run at normal speed, investigate the following potential causes.
Use a connection pool or persistent connections
With a non-persistent connection, each database request requires a TCP three-way handshake and authentication. This creates significant overhead, especially in high-concurrency scenarios. To reduce latency from frequent new connections, configure your application to use a database connection pool or persistent connections. This allows your application to reuse existing connections.
Check the availability zone deployment
If your ECS instance and ApsaraDB RDS instance are in different availability zones, network communication between them adds 0.5 ms to 1 ms of latency. For the lowest possible network latency, deploy your ECS instance and ApsaraDB RDS instance in the same availability zone.