与AWS RDS的第一个查询或连接非常慢
我有一个带有Laravel的产品,具有多租期。 部署在EC2实例上,并使用AWS RD作为数据库服务器。
我目前正在制作大约100个数据库。 Laravel的Hyn租赁模块正在处理连接。
现在,问题是在闲置时间后的每个租户,第一个请求需要太长。大约15-20秒。之后,它运行顺利。
在测试环境中,我们不是使用RD,而是使用本地MySQL实例。并且问题不会在测试环境中发生。测试和生产之间的唯一区别是AWS RD。
我已经研究了最大连接,查询缓存等等……但是到目前为止没有运气。
有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案将取决于您拥有的RDS。
我认为它是无服务器(更常见的)。在这种情况下,有一个最小的设置,最大设置为ACU。如果在一段时间内未访问数据库,它将(我相信)默认情况下降至零。检查一下,看看是否正确设置了它。
如果您有配置DB,则更为复杂。一旦执行查询,它将开始缓存内容,但是直到运行特定的查询之前,您将等待DB“唤醒”并运行完整的查询。
检查此页面有关相关信息。
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.