在MongoDB中使用secondaryprefer后查询变慢

时间:2016-09-26 05:56:10

标签: mongodb performance

我们有一个mongoDB副本集(1个主要+ 2个辅助+ 1个仲裁者)。之前我们在spring中使用primarypreferred配置来连接mongo(因为应用程序用例)。现在我们决定继续使用二级(通过使用二级优先)。问题是在移动到二级查询后执行时间急剧增加。最初我们认为这种行为是由于数据和索引不在RAM中。因此,我们尝试使用jmeter预热数千个查询。在jmeter上我们得到了一些性能改进,但我认为这是因为查询缓存。 我在同一个查询的主要和次要上都使用了explain()并获得了相同的获胜计划。查询的执行时间也几乎相同。出现问题我们增加了二级负载。
查询此类查询

2016-09-26T11:28:22.826+0530 I COMMAND  [conn4206507] command response.$cmd command: aggregate { aggregate: "buyerResponse", pipeline: [ { $match: { superProfileId: 15205907, productType: { $in: [ "CP" ] }, responseDate: { $gte: new Date(1472277502000), $lt: new Date(1474869502000) }, status: { $in: [ "Y", "K" ] } } }, { $project: { month: { $month: [ "$responseDate" ] }, superProfileId: 1, subProfileId: 1, productType: 1, productId: 1, responseType: 1, siteVisit: 1, preference: 1, callStatus: 1, isNew: 1, propertySnapshot: 1 } }, { $group: { _id: "$callStatus", superProfileId: { $first: "$superProfileId" }, subProfileId: { $first: "$subProfileId" }, productType: { $first: "$productType" }, productId: { $first: "$productId" }, responseType: { $first: "$responseType" }, month: { $first: "$month" }, siteVisit: { $first: "$siteVisit" }, preference: { $first: "$preference" }, callStatus: { $first: "$callStatus" }, isNew: { $first: "$isNew" }, projectId: { $first: "$propertySnapshot.projectId" }, count: { $sum: 1 } } } ] } keyUpdates:0 writeConflicts:0 numYields:101 reslen:50 locks:{ Global: { acquireCount: { r: 208 } }, MMAPV1Journal: { acquireCount: { r: 104 } }, Database: { acquireCount: { r: 104 } }, Collection: { acquireCount: { R: 104 } } } 513ms

这两个查询几乎同时运行,并且参数和数据大小相同。

2016-09-26T11:28:01.216+0530 I COMMAND  [conn4206507] command response.$cmd command: aggregate { aggregate: "buyerResponse", pipeline: [ { $match: { superProfileId: 18154267, productType: { $in: [ "CP" ] }, responseDate: { $gte: new Date(1472277478000), $lt: new Date(1474869478000) }, status: { $in: [ "Y", "K" ] } } }, { $project: { month: { $month: [ "$responseDate" ] }, superProfileId: 1, subProfileId: 1, productType: 1, productId: 1, responseType: 1, siteVisit: 1, preference: 1, callStatus: 1, isNew: 1, propertySnapshot: 1 } }, { $group: { _id: "$callStatus", superProfileId: { $first: "$superProfileId" }, subProfileId: { $first: "$subProfileId" }, productType: { $first: "$productType" }, productId: { $first: "$productId" }, responseType: { $first: "$responseType" }, month: { $first: "$month" }, siteVisit: { $first: "$siteVisit" }, preference: { $first: "$preference" }, callStatus: { $first: "$callStatus" }, isNew: { $first: "$isNew" }, projectId: { $first: "$propertySnapshot.projectId" }, count: { $sum: 1 } } } ] } keyUpdates:0 writeConflicts:0 numYields:669 reslen:50 locks:{ Global: { acquireCount: { r: 1344 }, acquireWaitCount: { r: 2 }, timeAcquiringMicros: { r: 417 } }, MMAPV1Journal: { acquireCount: { r: 672 }, acquireWaitCount: { r: 1 }, timeAcquiringMicros: { r: 48952 } }, Database: { acquireCount: { r: 672 } }, Collection: { acquireCount: { R: 672 } } } 2948ms

0 个答案:

没有答案