Latency issue between RDS and Lamda

0

We have APIs deployed on Lambda which read/write data on RDS. All these services are on same region (ap-southeast-2), but we are experiencing delay on RDS from Lambda. It takes around 5 seconds to update record on RDS. What could be the reason for the delay even though these services are configured on same region and is there a way to optimise the latency?

2 回答
0

Five seconds seems like a long time. Have you tried the same operation from an EC2 instance? That might give you an idea as to where the problem might be.

You might also turn on debugging in whichever libraries you're using or perhaps instrument your code using X-Ray. Either way you're trying to track down where the delay is.

The delay could come from DNS resolution; it could come from establishing the TCP session to RDS; it could come from the database itself.

profile pictureAWS
专家
已回答 2 年前
0

Which RDS flavor are you using? Have you configured the RDS Proxy - https://aws.amazon.com/rds/proxy/faqs/ and is lambda using the RDS Proxy? - https://aws.amazon.com/blogs/compute/using-amazon-rds-proxy-with-aws-lambda/

Also is your RDS inside a VPC and is your lambda VPC enabled?

To improve the performance of reads, have you implemented Read Replicas on your RDS database - https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html

Also make sure that the database connection is being opened outside of the Event Handler block in your lambda code, as mentioned in the "Take advantage of execution environment reuse to improve the performance of your function" section of Lambda Best Practices, if you haven't done so already - https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html

Apart from implementing the client on an EC2 machine, as Brett has suggested above, if your database is Postgres, MySQL or MariaDB, you may also want to try out installing the same version of the database in an EC2 machine and try accessing that database from your lambda function, just to eliminate that RDS is not the culprit.

profile pictureAWS
专家
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则