MongoDB Server - CPU Performance High

129 views
Skip to first unread message

santhosh okkadu

unread,
Mar 9, 2017, 11:39:03 PM3/9/17
to mongodb-user

My MongoDB Server CPU Performance is some times hitting 99% because of which the application is getting slower.


I'm using ROBOMONGO tool through which I've run a query to get the current Operations on the DB (db.currentOP()) and I'm running this query every second and I'm getting an array result with number of operations and at a point I'm getting 1000+ requests.


Can any one guide me the way to find the queries running on the database.


I'm using a Chat application so I couldn't find the exact place where it is happening on Live Environment.


BTW, Our server Configuration is :
R3.xlarge
4vCPU
30.5GB RAM


Sample Log :
{
"desc" : "conn17",
"threadId" : "7220",
"connectionId" : 17,
"client" : "SAMPLE_IP_ADDRESS:57979",
"active" : true,
"opid" : 487161,
"secs_running" : 0,
"microsecs_running" : NumberLong(51785),
"op" : "command",
"ns" : "uandmeprod_main.$cmd",
"query" : {
"count" : "USERINFO",
"query" :

{ "CLIENT_IDENTIFIER" : "app-1877da2f1972e564741" }

},
"numYields" : 0,
"locks" :

{ "Global" : "r", "Database" : "r", "Collection" : "R" }

,
"waitingForLock" : true,
"lockStats" : {
"Global" : {
"acquireCount" :

{ "r" : NumberLong(2) }

},
"MMAPV1Journal" : {
"acquireCount" :

{ "r" : NumberLong(1) }

},
"Database" : {
"acquireCount" :

{ "r" : NumberLong(1) }

},
"Collection" : {
"acquireCount" :

{ "R" : NumberLong(1) }

,
"acquireWaitCount" :

{ "R" : NumberLong(1) }

}
}
}, 
{
"desc" : "conn427",
"threadId" : "18704",
"connectionId" : 427,
"client" : "SAMPLE_IP_ADDRESS:61212",
"active" : true,
"opid" : 486758,
"secs_running" : 0,
"microsecs_running" : NumberLong(279493),
"op" : "query",
"ns" : "uandmeprod_main.USERINFO",
"query" : {
"find" : "USERINFO",
"filter" :

{ "MOBILENO" : "1127060672" }

},
"numYields" : 0,
"locks" :

{ "Global" : "r", "MMAPV1Journal" : "r", "Database" : "r", "Collection" : "R" }

,
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" :

{ "r" : NumberLong(2) }

},
"MMAPV1Journal" : {
"acquireCount" :

{ "r" : NumberLong(1) }

},
"Database" : {
"acquireCount" :

{ "r" : NumberLong(1) }

},
"Collection" : {
"acquireCount" :

{ "R" : NumberLong(1) }

}
}
}, 
{
"desc" : "conn1336",
"threadId" : "6964",
"connectionId" : 1336,
"client" : "SAMPLE_IP_ADDRESS:63173",
"active" : true,
"opid" : 486632,
"secs_running" : 0,
"microsecs_running" : NumberLong(284492),
"op" : "query",
"ns" : "uandmeprod_main.USERINFO",
"query" : {
"find" : "USERINFO",
"filter" :

{ "MOBILENO" : "9866858528" }

},
"numYields" : 0,
"locks" :

{ "Global" : "r", "MMAPV1Journal" : "r", "Database" : "r", "Collection" : "R" }

,
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" :

{ "r" : NumberLong(2) }

},
"MMAPV1Journal" : {
"acquireCount" :

{ "r" : NumberLong(1) }

},
"Database" : {
"acquireCount" :

{ "r" : NumberLong(1) }

},
"Collection" : {
"acquireCount" :

{ "R" : NumberLong(1) }

}
}
}

Valtteri Pirttilä

unread,
Mar 16, 2017, 8:46:30 AM3/16/17
to mongodb-user
I don't have an answer to your exact question, but maybe I can still offer some help.

My experience has been that high CPU usage usually indicates that your indexes are not supporting either your query criteria or your sorting.

Instead of checking currently running operations, maybe you could use the MongoDB profiler to help you?


The profiler combined with running queries with .explain() or .explain("executionStats") is rather useful in fine tuning your indexes.

Best of luck to you,

Valtteri

Wan Bachtiar

unread,
Mar 22, 2017, 7:56:37 PM3/22/17
to mongodb-user

My MongoDB Server CPU Performance is some times hitting 99% because of which the application is getting slower.

Hi Santhosh,

There are many things that can cause a server to use high CPU. Assuming that this is a dedicated server only running a standalone mongod server, you could start a diagnosis of the issue using the following:

If you have further questions, it would help others if you could provide:

  • Specific MongoDB version
  • The storage engine that you’re using
  • The output of mongostat before and during the CPU high load
  • The output log (slow queries) during the CPU high load
  • The suspected slow queries and a sample document schema

See also db.currentOp to understand better the output of the document. You may also benefited from reviewing Monitoring for MongoDB and FAQ: MongoDB Concurrency

Also, I’d recommend to enrol to MongoDB University free online course M201: Performance and/or M312: Diagnostics and Debugging to learn more. The next session of the course will start on 28th March which gives you plenty of time to register.

Regards,

Wan

Reply all
Reply to author
Forward
0 new messages