Heroku 共享数据库与 Amazon RDS 性能
我正在将所有数据从 Heroku 的共享数据库移动到 Amazon RDS。在将所有内容切换到 RDS 之前,我在本地运行了一些测试,以确保我的应用程序可以正常运行。这些测试明显减慢了 RDS 上的查询时间。对于完全相同的请求,我得到:
在 Heroku 上,使用 heroku 共享数据库:
Completed 200 OK in 98ms (Views: 0.7ms | ActiveRecord: 56.0ms)
本地,使用 RDS 数据库实例
Completed 200 OK in 253ms (Views: 0.7ms | ActiveRecord: 127.9ms)
ActiveRecord 时间是我在这里担心的。我错过了什么吗? Heroku 清楚地说明了他们的共享数据库:
共享数据库适用于登台、测试和小规模 生产应用。
但它似乎比我每月支付 80 美元的 RDS 实例更快。 heroku的共享数据库在本地运行吗?因为对我来说很明显,在我的 Heroku 应用程序内本地运行的任何数据库都将比其外部的任何数据库更快。亚马逊表示,任何耗时超过 10 毫秒的查询都被视为“慢查询”。但现在看来,每个查询从应用程序到亚马逊服务器的往返时间+实际查询时间至少需要 25 毫秒。或者我错过了什么?
I'm in the process of moving all my data from Heroku's shared db to Amazon RDS. Before switching everything over to RDS, I ran some tests locally to make sure my app works fine with it. These tests clearly slow that query time is slower on RDS. For the exact same request, I get:
On Heroku, with heroku shared db:
Completed 200 OK in 98ms (Views: 0.7ms | ActiveRecord: 56.0ms)
Locally, with RDS db instance
Completed 200 OK in 253ms (Views: 0.7ms | ActiveRecord: 127.9ms)
The ActiveRecord times are what I'm worried about here. Am I missing something? Heroku clearly states this about their shared db:
Shared databases are suitable for staging, testing, and low-scale
production applications.
And yet it seems to be faster than this RDS instance I'm paying 80$/month for. Is heroku's shared db running locally? Because it's pretty obvious to me that about any database running locally inside my heroku app is going to be faster than any db that lives outside of it. Amazon says that any query taking more than 10ms is considered as a "slow query". But right now it seems that every query is gonna take at least 25ms for the roundtrip alone from the app to amazon's server + the actual query time. Or am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,Heroku EC2 实例在东部可用区中运行,因此在同一区域中创建 RDS 实例非常类似于为其提供本地数据库(我相信这也是heroku 共享数据库的工作方式)。
直接在 Heroku 上为我的应用程序设置暂存环境并将其连接到我的 RDS 实例后,查询时间比我在本地测试时快得多(每个 SQL 查询都必须从我的本地计算机到 RDS 服务器进行往返) 。
唯一未解决的小问题是如何确定我的 heroku 应用程序在哪个特定可用性子区域中运行,以便我可以将其与我的 RDS 实例进行匹配(尽管它可能并不像全局可用性区域那么重要)。
From what I understand, Heroku EC2 instances run in the East availability zone, so creating an RDS instance in that same zone is pretty much like giving it a local database (I believe that's how heroku's shared databases work as well).
After setting up a staging environment for my app directly on Heroku and connecting it to my RDS instance, query times were much faster than when I tested it locally (where each SQL query had to make a roundtrip from my local machine to the RDS servers).
The only minor thing that's left unanswered is how to determine in which particular availability sub-zone my heroku app is running, so I can match it with my RDS instance (although it probably doesn't matter as much as the global availability zone).