I wrote an app using Sails.js with mongoDb(sails-mongo).
Firstly, I decided to write all to a single document... And database slowed on 5GB of data.. "Slowed" means that basic find query executed in 30-50s..
Than I rewrite all in an multiple collections and add indexing.. example of my models:
Markets.js
module.exports = {
attributes: {
name: {
type: 'string',
index: true
},
pairs: {
collection: 'Exchanges',
via: 'source',
}
}
};
and Exchanges.js
module.exports = {
attributes: {
s1: {
type: "string"
},
source:{
model: "Maklers",
index: true
},
s2: {
type: "string"
},
p: {
type: 'float'
},
v1: {
type: 'float'
},
v2: {
type: 'float'
},
vb: {
type: 'float'
}
}
};
and example of slow query
Markets.findOne({
name: info,
sort: 'createdAt DESC',
limit: 1,
createdAt: {
'<=': aft
}
}).populateAll().exec(function(err, items) {
callback(err, items);
});
result of db.stats
> db.stats()
{
"db" : "stats222",
"collections" : 8,
"objects" : 36620661,
"avgObjSize" : 238.26556139988844,
"dataSize" : 8725442352,
"storageSize" : 10033258480,
"numExtents" : 63,
"indexes" : 13,
"indexSize" : 2940024192,
"fileSize" : 14958985216,
"nsSizeMB" : 16,
"extentFreeList" : {
"num" : 0,
"totalSize" : 0
},
"dataFileVersion" : {
"major" : 4,
"minor" : 22
},
"ok" : 1
}
What you can advice me? It`s about 2000 of records every minute..
How to increase perfomance? Change db config? Change indexes? Change DB? Change models/collections config?
I using 2-core server with 2GB of Virtual Memory.. Sorry for bad english..