简体   繁体   English

如何加快我的 AWS RDS Postgres 性能?

[英]How can I speed up my AWS RDS Postgres performance?

I just set up a db.t2.micro instance on Amazon's AWS.我刚刚在亚马逊的 AWS 上设置了一个 db.t2.micro 实例。 I am using sinatra to load a localhost webpage.我正在使用 sinatra 加载本地主机网页。 I am using Active Record to do maybe about 30~ queries and it's taking 92 seconds to load.我正在使用 Active Record 进行大约 30~ 次查询,加载需要 92 秒。 It's extremely slow.它非常缓慢。 I tried doing custom parameters as listed here: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_BestPractices.html#CHAP_BestPractices.PostgreSQL我尝试执行此处列出的自定义参数: http : //docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_BestPractices.html#CHAP_BestPractices.PostgreSQL

This didn't help speed anything up.这无助于加快速度。 I'm not sure how I can speed up this instance.我不确定如何加速这个实例。 This is my first time hosting a database.这是我第一次托管数据库。 Any help would be appreciated.任何帮助,将不胜感激。

When I run my sinatra app it host locally(localhost).当我运行我的 sinatra 应用程序时,它在本地(本地主机)托管。 Here is where the 30~ queries are taking 92 seconds to load.这是 30~ 个查询需要 92 秒才能加载的地方。 When I run select * statements in Postgres they take only a couple seconds.当我在 Postgres 中运行 select * 语句时,它们只需要几秒钟。

The problem is the latency between you and Amazon's data center.问题在于您和亚马逊数据中心之间的延迟。

For example when you are in New York and your RDS instance is in Amazon's data center on the west coast, then the latency between you and the data center is about 80-100ms.比如你在纽约,你的RDS实例在亚马逊西海岸的数据中心,那么你和数据中心之间的延迟大约是80-100ms。 That means when your local application sends a query to the database then it takes about 100ms before the database receives the query.这意味着当您的本地应用程序向数据库发送查询时,大约需要 100 毫秒才能让数据库收到查询。 To return the answer it takes again an additional 100ms.要返回答案,它又需要额外的 100 毫秒。

That said: Assume a roundtrip takes 300ms and you have ~30 queries then your application loses about 10 seconds doing nothing – just waiting for data being sent through the wire.也就是说:假设往返需要 300 毫秒,并且您有大约 30 个查询,那么您的应用程序会损失大约 10 秒什么都不做——只是等待数据通过线路发送。 And there are other factors that might slow down this even more: Big packets or lost packets (the server has to ask again), bad internet connections, wireless connections, the distance between you and the database being longer than my example.还有其他因素可能会进一步减慢速度:大数据包或丢失数据包(服务器必须再次询问)、互联网连接不良、无线连接、您与数据库之间的距离比我的示例更长。

Therefore the database should be as near as possible to the application server in the same data center to minimize latency.因此,数据库应尽可能靠近同一数据中心的应用服务器,以最大限度地减少延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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