Mongo在Amazon EC2上运行缓慢

时间:2015-11-22 13:56:56

标签: mongodb amazon-web-services amazon-ec2 aws-ec2

我一直在使用compose.io来托管我的Mongo实例。我的数据变得越来越大,成本越来越高,所以我想搬到EC2,我有750美元的学分。

问题:

我有一个端点来验证从我的localhost运行的用户:

当我的API指向compose.io数据库时,其响应时间约为200毫秒

当我的API指向我的新EC2 Mongo实例时,其响应时间约为700毫秒。

(数据库是精确的副本)

Ping EC2实例大约是90-100ms。

集合已经被reIndexed()并且Mongo实例上没有负载。

有关EC2实例的详细信息:

M3.large

100条提供iOP

零流量/负载。

我无法弄清楚为什么Mongo反应如此之慢。当我验证对数据库发生的几件事情(这是mongod.log的输出)

2015-11-22T13:44:15.631+0000 [conn6] insert production.transactions query: { method: "POST", resource: "/api/v1.1/login", body: { password: "***********", email: "********" }, timezone: "America/New_York", agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36", _id: ObjectId('5651c6afdc24948b9f2e15e5'), created: new Date(1448199855577), __v: 0 } ninserted:1 keyUpdates:0 numYields:0 locks(micros) w:99 0ms
2015-11-22T13:44:15.631+0000 [conn6] command production.$cmd command: insert { insert: "transactions", documents: [ { method: "POST", resource: "/api/v1.1/login", body: { password: "***********", email: "*******" }, timezone: "America/New_York", agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36", _id: ObjectId('5651c6afdc24948b9f2e15e5'), created: new Date(1448199855577), __v: 0 } ], ordered: false, writeConcern: { w: 1 } } keyUpdates:0 numYields:0 locks(micros) w:83 reslen:40 0ms
2015-11-22T13:44:15.734+0000 [conn8] query production.users query: { email: "*******" } planSummary: IXSCAN { email: 1 } ntoskip:0 keyUpdates:0 numYields:0 locks(micros) r:125 nreturned:1 reslen:1553 0ms
2015-11-22T13:44:15.918+0000 [conn7] remove production.tokens query: { user_id: "5330d44ba6885a020005bc88" } ndeleted:0 keyUpdates:0 numYields:0 locks(micros) w:236 0ms
2015-11-22T13:44:15.918+0000 [conn7] command production.$cmd command: delete { delete: "tokens", deletes: [ { q: { user_id: "5330d44ba6885a020005bc88" }, limit: 0 } ], ordered: true, writeConcern: { w: 1 } } keyUpdates:0 numYields:0  reslen:40 0ms
2015-11-22T13:44:16.019+0000 [conn9] insert production.tokens query: { _id: "Tor9ke2lrt5Ooeifuh6hnCYFmmpDlWu8tRu2T2uZbgylFpx8EBlg1Aw7cQKQNc0I09zRhLrxdceV7lTf6UWl769ZMLX1cxlb0qksY8ssj1zme9uT1PkpNlIlNdBJE40S", user_id: "5330d44ba6885a020005bc88", expires: new Date(1448804120000), created: new Date(1448199855964), __v: 0 } ninserted:1 keyUpdates:0 numYields:0 locks(micros) w:73 0ms
2015-11-22T13:44:16.020+0000 [conn9] command production.$cmd command: insert { insert: "tokens", documents: [ { _id: "Tor9ke2lrt5Ooeifuh6hnCYFmmpDlWu8tRu2T2uZbgylFpx8EBlg1Aw7cQKQNc0I09zRhLrxdceV7lTf6UWl769ZMLX1cxlb0qksY8ssj1zme9uT1PkpNlIlNdBJE40S", user_id: "5330d44ba6885a020005bc88", expires: new Date(1448804120000), created: new Date(1448199855964), __v: 0 } ], ordered: false, writeConcern: { w: 1 } } keyUpdates:0 numYields:0 locks(micros) w:105 reslen:40 0ms
2015-11-22T13:44:16.128+0000 [conn10] command production.$cmd command: findAndModify { findandmodify: "users", query: { _id: ObjectId('5330d44ba6885a020005bc88') }, new: false, remove: false, upsert: false, update: { $set: { last_login: new Date(1448199856068) } }, writeConcern: { w: 1 } } update: { $set: { last_login: new Date(1448199856068) } } nscanned:1 nscannedObjects:1 nMatched:1 nModified:1 fastmod:1 keyUpdates:0 numYields:0 locks(micros) w:130 reslen:1624 0ms

1 个答案:

答案 0 :(得分:2)

问题的原因似乎是在美国西部设立mongo实例,同时在美国东部托管应用程序。网络延迟是响应时间增加的原因。