Skip to content

Lambda <-> RDS Proxy <-> RDS (PostgreSQL) 10 fold slower than Lambda <-> RDS

0

For some time I've been running my lambda connected directly to RDS PostgreSQL and I had no concern about performance at all. Most queries completed within 100ms or less. But because we do expect more traffic, I did set up an identical environment (same lambda, same database setup, etc) except this time using the RDS-Proxy, tls and IAM authentication. Instead of improved (or similar) performance, queries take at least 10 times longer than before. How can I find causes for this? Or should I continue without RDS-Proxy completely? Already read about pinning transactions, but that is not the case. Currently doing simple queries and never see anything in the cloudwatch metric for that. Cloudwatch indicates only 2 database connections and 1 client connection during my basic tests.

Any help would be appreciated

1 Answer
0

This performance difference between direct RDS connections and using RDS Proxy is a known issue that others have experienced. There are several factors that could be causing the slowdown:

  1. Proxy Overhead: RDS Proxy introduces additional overhead due to connection pooling and management. This overhead can result in higher query times compared to direct connections, with some users reporting 8-12x slower query times even with a single connection.

  2. Connection Management: While RDS Proxy is designed to help with connection pooling, the initial connection establishment can be slower, especially when using IAM authentication and TLS, which you've enabled.

  3. Configuration Issues: Your proxy settings might need optimization. Check your connection pool settings, minimum and maximum connections, and idle connection timeout.

To troubleshoot and improve performance:

  1. Monitor Metrics: Use CloudWatch to analyze RDS Proxy metrics like DatabaseConnections, ClientConnections, and connection limits.

  2. Connection Reuse: Ensure your Lambda code is reusing connections rather than creating new ones for each query.

  3. Evaluate Necessity: Consider whether you actually need RDS Proxy. AWS recommends it primarily for production environments with high concurrency that generate many connections in a short period. For Lambdas with lower execution frequency, direct connections might be more efficient.

  4. Test Without IAM/TLS: Try testing without IAM authentication and TLS to see if these security features are contributing to the slowdown.

If your current workload doesn't generate connection spikes that risk exhausting database connections, you might be better off continuing with direct connections until your traffic increases to the point where connection pooling becomes necessary.
Sources
RDS Proxy query time is slower than expected | AWS re:Post
Which is preferred, Lambda->RDS Proxy->RDS or Lambda->RDS? | AWS re:Post
RDS Proxy causing a consistent increase in DB Connections from Lambda | AWS re:Post

answered 5 months 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.