简体   繁体   中英

First query or connection to AWS RDS is very very slow

I have a product built with laravel, with multi-tenancy. Deployed on EC2 instance and using AWS RDS as the database server.

I am currently having around 100 databases on the production. Laravel's hyn tenancy module is handling the connections.

Now, the problem is for each tenant after some idle time, the first request takes too long. around 15-20 seconds. and after that, it works smoothly.

In the test environment, we are not using RDS but a local MySQL instance. and the problem does not occur in the test environment. the only difference between test and production is the AWS RDS.

I have looked into max connections, query cache, and so on... but no luck so far.

Any suggestions?

The solution will depend on what kind of RDS you have. I assume it's serverless (more common). In that case, there's a setting for min and max for ACU. It will (I believe) go down to zero by default if the DB is not accessed in a while. Check that and see if it is properly set.

If you have a Provisioned DB, then it's more complex. It will start caching things once queries are executed but until a particular query is run, you will be waiting for the DB to "wake up" and run a full query. Check this page for relevant info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM