We are using different databases to store data of company. For example, user’s general information (login, password, profile info, etc) stored in the main database, but user’s messages, notifications or any other data stored at the separate database for each company.
Connection to the database with publication of messages looks like this:
Meteor.publish('messages', function(companyId, query, limit){
let mongoDbUrl = 'mongodb://IP_ADDRESS:27017/' + companyId;
let CONN = {};
let getDbConn = (dbUrl)=>{
let database = null;
if (CONN[dbUrl]) {
database = CONN[dbUrl];
} else {
database = new MongoInternals.RemoteCollectionDriver(dbUrl);
CONN[dbUrl] = database;
}
return database;
};
let dbUrl = mongoDbUrl + companyId;
let database = getDbConn(dbUrl);
let messages = database.open('messages');
return messages.find(query, {limit: limit});
});
Furthermore, we are using rocketchat:streamer package to inform user that another user is typing message just now.
After 100-150 user connections on production server CPU is running above 90%. How to reduce CPU utilization?