Reputation: 73
We are using parse-server + mongoDB on the own server for the mobile game backend. There are about 200K users with ~2k connected at the same time. The "_Session" collection is about 1 million records and continues to grow.
Servers CPUs are constantly loaded on 100% each. In the MongoDB logs I can see 95% records like:
2017-05-11T16:25:24.738+0300 I COMMAND [conn1] command appdb1._Session command: find { find: "_Session", filter: { _session_token: "r:9eaba843dc3f8b482dbc76009f94c18a" }, sort: {}, projection: {}, limit: 1 } planSummary: COLLSCAN keysExamined:0 docsExamined:1015131 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:7930 nreturned:1 resle n:428 locks:{ Global: { acquireCount: { r: 15862 } }, Database: { acquireCount: { r: 7931 } }, Collection: { acquireCount: { r: 7931 } } } protocol:op_query 556ms
I've created index for the _Session collection, db.getCollection("_Session").getIndexes() [
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "appdb1._Session"
},
{
"v" : 1,
"key" : {
"sessionToken" : 1
},
"name" : "sessionToken_1",
"ns" : "appdb1._Session",
"background" : true
}
]
but, as I understand, it is not used, and DB performs full collection scan every time when it searches for a record.
So server кesponds with great delays, please, help with this problem.
Thanks!
Upvotes: 1
Views: 184
Reputation: 4417
Try creating index on key _session_token in background:
db.yourCollection.ensureIndex({ "_session_token":1}, {background:true})
This will avoid collection scan for the query with key _session_token
.
Upvotes: 1