Hi,
During my aggregation tests I found that mongo sometimes uses 100% in one core and sometimes not and as a consequence, the time of response varies a lot.
This CPU usage can also vary from an aggregation query to another (for example : if a want to aggregate more documents).
Although in most cases MongoDB is not CPU-bound, some processing in MongoDB is relatively CPU-intensive, for example:
There are some performance profiling tools that may be of help to you:
mongostat
provides the status of a currently running mongod
or mongos
process.mongotop
provides information about the time it took for MongoDB to read and write data.db.currentOp()
command shows what operation is currently running.Also, there are some pages that may be of help:
$group
stage: SERVER-4507However, I can give you some pointer regarding your aggregation query:
db.consumption.aggregate([
{$match: {ID_1:{$lte:500},Time:{$lte :1461908939}}},
{$group:{
_id:{"ID_1":"$ID_1","ID_2":"$ID_2"},
AvgValue:{$avg:"$Value"}
}}])
Although the $match
stage can use an index, once the pipeline enters the $group
(or $project
) stage, no index can be used. The reason for this is an index is closely tied to how the documents are stored in disk. Indexes can help to speed up find()
queries (since find()
does not reshape documents), but $group
and $project
stage reshape the documents in-memory so any indexes no longer applies. In other words, $group
stage will output documents that do not have a physical representation in disk, and thus indexes (which are tied to the physical location of a document) cannot be used anymore.
If your $match
stage is not selective enough (e.g. it returns a lot of documents), then the $group
stage will have to calculate average values of a large numbers of documents. If the documents involved need to be fetched and uncompressed from disk, it will also add up to the CPU usage you are seeing.
I would suggest using mongotop
, mongostat
, and other performance measurement tools to determine what happened during the aggregation query in your deployment.
Best regards,
Kevin
Hi Kevin,