Mongo 运行 在 Amazon EC2 上运行缓慢

Mongo running slow on Amazon EC2

我一直在使用 compose.io 来托管我的 Mongo 实例。我的数据越来越大,而且留在那里的成本越来越高,所以我想转移到 EC2,在那里我有大约 750 美元的积分。

问题:

我有一个端点来验证我 运行 来自本地主机的用户:

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

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

(数据库是精确副本)

Ping EC2 实例大约需要 90-100 毫秒。

集合已重新索引()并且 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

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