使用mogodb,CPU几乎达到100%

时间:2017-09-04 09:08:15

标签: angularjs node.js mongodb mongoose mongodb-query

我正在使用与节点js的mongodb的mongoose库。

我的页面包含大约20个图表。所有图表都与mongo db中的相同集合相关。

我必须为同一系列的图表调用近15-16项服务。

当我这样做时,cpu在MongoDB数据库服务器上几乎达到100%。

任何人都可以建议如何优化它。

以下是mongodb查询的日志。

2017-09-01T23:57:25.164+0000 I COMMAND  [conn4] command HyperlocalPortalDB.users command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503810000000), $lt: new Date(1504069140000) } } }, 
{ $group: { _id: { mac: “$mac” } } },
 { $lookup: { from: “users”, localField: “_id.mac”, foreignField: “mac”, as: “userDetail” } }, 
 { $match: { userDetail.activations.activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’) } }, 
 { $unwind: “$userDetail” }, { $project: { mac: “$_id.mac”, groupField: “$userDetail.city” } }, 
 { $group: { _id: “$groupField”, count: { $sum: 1 } } }, 
 { $sort: { count: -1 } } ] } 
 planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10810 nreturned:0 reslen:18599 
 locks:{ Global: { acquireCount: { r: 26198 } }, Database: { acquireCount: { r: 13099 } }, 
 Collection: { acquireCount: { r: 13098 } } } protocol:op_query 7755ms

2017-09-01T23:57:25.264+0000 I COMMAND  [conn3] command HyperlocalPortalDB.users command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503810000000), $lt: new Date(1504069140000) } } }, 
{ $group: { _id: { mac: “$mac” } } }, 
{ $lookup: { from: “users”, localField: “_id.mac”, foreignField: “mac”, as: “userDetail” } }, 
{ $match: { userDetail.activations.activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’) } }, 
{ $unwind: “$userDetail” }, { $project: { mac: “$_id.mac”, groupField: “$userDetail.country” } }, 
{ $group: { _id: “$groupField”, count: { $sum: 1 } } }, { $sort: { count: -1 } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10831 nreturned:0 reslen:82 
locks:{ Global: { acquireCount: { r: 26240 } }, Database: { acquireCount: { r: 13120 } }, 
Collection: { acquireCount: { r: 13119 } } } protocol:op_query 7776ms

2017-09-01T23:57:25.486+0000 I COMMAND  [conn5] command HyperlocalPortalDB.users command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503810000000), $lt: new Date(1504069140000) } } }, 
{ $group: { _id: { mac: “$mac” } } }, 
{ $lookup: { from: “users”, localField: “_id.mac”, foreignField: “mac”, as: “userDetail” } }, 
{ $match: { userDetail.activations.activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’) } }, 
{ $unwind: “$userDetail” }, { $project: { mac: “$_id.mac”, groupField: “$userDetail.state” } }, 
{ $group: { _id: “$groupField”, count: { $sum: 1 } } }, { $sort: { count: -1 } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10806 nreturned:0 reslen:2053 
locks:{ Global: { acquireCount: { r: 26190 } }, Database: { acquireCount: { r: 13095 } }, 
Collection: { acquireCount: { r: 13094 } } } protocol:op_query 7336ms

2017-09-01T23:57:25.564+0000 I COMMAND  [conn6] command HyperlocalPortalDB.users command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503810000000), $lt: new Date(1504069140000) } } }, 
{ $group: { _id: { mac: “$mac” } } }, 
{ $lookup: { from: “users”, localField: “_id.mac”, foreignField: “mac”, as: “userDetail” } }, 
{ $match: { userDetail.activations.activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’) } }, 
{ $unwind: “$userDetail” }, { $project: { mac: “$_id.mac”, groupField: “$userDetail.state” } }, 
{ $group: { _id: “$groupField”, count: { $sum: 1 } } }, { $sort: { count: -1 } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10811 nreturned:0 reslen:2053 
locks:{ Global: { acquireCount: { r: 26200 } }, Database: { acquireCount: { r: 13100 } }, 
Collection: { acquireCount: { r: 13099 } } } protocol:op_query 8259ms

2017-09-01T23:57:26.018+0000 I COMMAND  [conn2] command HyperlocalPortalDB.users command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503810000000), $lt: new Date(1504069140000) } } }, 
{ $group: { _id: { mac: “$mac” } } }, { $lookup: { from: “users”, localField: “_id.mac”, foreignField: “mac”, as: “userDetail” } }, 
{ $match: { userDetail.activations.activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’) } }, 
{ $unwind: “$userDetail” }, { $project: { mac: “$_id.mac”, groupField: “$userDetail.city” } }, 
{ $group: { _id: “$groupField”, count: { $sum: 1 } } }, { $sort: { count: -1 } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10804 nreturned:0 reslen:18599 
locks:{ Global: { acquireCount: { r: 26186 } }, Database: { acquireCount: { r: 13093 } }, 
Collection: { acquireCount: { r: 13092 } } } protocol:op_query 7978ms

2017-09-01T23:57:29.030+0000 I COMMAND  [conn5] command HyperlocalPortalDB.coordinates command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503810000000), $lt: new Date(1503896340000) } } }, 
{ $group: { _id: “$mac”, minTime: { $min: “$t” }, maxTime: { $max: “$t” } } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 numYields:10751 nreturned:0 reslen:26423 
locks:{ Global: { acquireCount: { r: 21538 } }, Database: { acquireCount: { r: 10769 } }, 
Collection: { acquireCount: { r: 10768 } } } protocol:op_query 3537ms

2017-09-01T23:57:29.812+0000 I COMMAND  [conn3] command HyperlocalPortalDB.coordinates command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503982800000), $lt: new Date(1504069140000) } } }, 
{ $group: { _id: “$mac”, minTime: { $min: “$t” }, maxTime: { $max: “$t” } } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 numYields:10755 nreturned:0 reslen:25216 
locks:{ Global: { acquireCount: { r: 21540 } }, Database: { acquireCount: { r: 10770 } }, 
Collection: { acquireCount: { r: 10769 } } } protocol:op_query 4540ms

2017-09-01T23:57:30.641+0000 I COMMAND  [conn6] command HyperlocalPortalDB.coordinates command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503896400000), $lt: new Date(1503982740000) } } }, 
{ $group: { _id: “$mac”, minTime: { $min: “$t” }, maxTime: { $max: “$t” } } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 numYields:10762 nreturned:0 reslen:25145 
locks:{ Global: { acquireCount: { r: 21558 } }, Database: { acquireCount: { r: 10779 } }, 
Collection: { acquireCount: { r: 10778 } } } protocol:op_query 5077ms

2017-09-01T23:57:31.664+0000 I COMMAND  [conn2] command HyperlocalPortalDB.users command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503810000000), $lt: new Date(1504069140000) } } }, 
{ $group: { _id: { mac: “$mac” } } }, { $lookup: { from: “users”, localField: “_id.mac”, foreignField: “mac”, as: “userDetail” } }, 
{ $match: { userDetail.activations.activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’) } }, { $unwind: “$userDetail” }, 
{ $project: { mac: “$_id.mac”, groupField: “$userDetail.country” } }, { $group: { _id: “$groupField”, count: { $sum: 1 } } }, 
{ $sort: { count: -1 } } ] } planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10774 nreturned:0 reslen:82 
locks:{ Global: { acquireCount: { r: 26126 } }, Database: { acquireCount: { r: 13063 } }, 
Collection: { acquireCount: { r: 13062 } } } protocol:op_query 5638ms

2017-09-01T23:57:33.839+0000 I COMMAND  [conn5] warning: log line attempted (89kB) over max size (10kB), printing beginning and end ... command HyperlocalPortalDB.coordinates command: aggregate { aggregate: “coordinates”, 
pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503810000000), $lt: new Date(1503896340000) }, mac: { $in: [ “41:9e:87:01:00:00", “41:9E:87:01:00:00”, “ab:cd:ed”, “41:9e:87:01:09:64”, “41:9E:87:01:09:64" ] } } }, 
{ $group: { _id: { $dateToString: { format: “%Y-%m-%d %H”, date: { $subtract: [ “$t”, 14400000 ] } } },
 macList: { $addToSet: “$mac” } } },  { $sort: { _id: 1 } } ] } 
 planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10756 nreturned:0 reslen:80098 
 locks:{ Global: { acquireCount: { r: 21548 } }, Database: { acquireCount: { r: 10774 } }, 
 Collection: { acquireCount: { r: 10773 } } } protocol:op_query 4433ms

2017-09-01T23:57:34.270+0000 I COMMAND  [conn6] warning: log line attempted (89kB) over max size (10kB), printing beginning and end ... command HyperlocalPortalDB.coordinates command: aggregate { aggregate: “coordinates”, pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503982800000), $lt: new Date(1504069140000) }, mac: { $in: [ “41:9e:87:01:00:00”, “41:9E:87:01:00:00", “ab:cd:ed”, “AB:CD:ED”,  “41:9e:87:01:09:64", “41:9E:87:01:09:64” ] } } }, 
{ $group: { _id: { $dateToString: { format: “%Y-%m-%d %H”, date: { $subtract: [ “$t”, 14400000 ] } } }, 
macList: { $addToSet: “$mac” } } }, { $sort: { _id: 1 } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10749 nreturned:0 reslen:57332 
locks:{ Global: { acquireCount: { r: 21528 } }, Database: { acquireCount: { r: 10764 } }, 
Collection: { acquireCount: { r: 10763 } } } protocol:op_query 3619ms

2017-09-01T23:57:34.376+0000 I COMMAND  [conn4] warning: log line attempted (89kB) over max size (10kB), printing beginning and end ... command HyperlocalPortalDB.coordinates command: aggregate { aggregate: “coordinates”, pipeline: [ { $match: { activationId: ObjectId(‘59a6e4dad95d240cf4ba37de’), t: { $gte: new Date(1503896400000), $lt: new Date(1503982740000) }, mac: { $in: [ “41:9e:87:01:00:00", “41:9E:87:01:00:00”, “ab:cd:ed”, “AB:CD:ED”, “41:9e:87:01:09:64”, “41:9E:87:01:09:64" ] } } }, 
{ $group: { _id: { $dateToString: { format: “%Y-%m-%d %H”, date: { $subtract: [ “$t”, 14400000 ] } } }, macList: { $addToSet: “$mac” } } }, 
{ $sort: { _id: 1 } } ] } 
planSummary: COLLSCAN keysExamined:0 docsExamined:1373500 hasSortStage:1 numYields:10758 nreturned:0 reslen:76210 
locks:{ Global: { acquireCount: { r: 21550 } }, Database: { acquireCount: { r: 10775 } }, 
Collection: { acquireCount: { r: 10774 } } } protocol:op_query 4973ms

1 个答案:

答案 0 :(得分:0)

1 - 禁用控制台显示

2 - 申请mongodb productions notes

例如:

  

使用WiredTiger存储引擎时,强烈建议使用XFS,以避免将EXT4与WiredTiger一起使用时可能出现的性能问题。

  

禁用透明大页面。 MongoDB在普通(4096字节)虚拟内存页面上表现更好。