SfAnki SfAnki - 1 year ago 141
Node.js Question

Mongodb with node is using high cpu usage on Docker

Hi I've installed Rocket.chat on ubuntu Aws micro instance, It running with Nginx, MongoDB, and node, where MongoDB is running with docker image


It was running smoothly on the day of installation but after some times It server was getting slow, I examined within the server with
command. It was MongoDB using cpu% around 70. and the next day It flickers with more than 90%.

I've reinstalled everything on the server but it is same again, no luck.

Here is the screenshot for

Please let me know if any other stats are needed for this.
enter image description here

How can I examined the main problem here, how can I optimize it to make it work properly.


Answer Source

I got to know why this issue arises. I started implementing my custom chat platform with Meteor. So the cause of the problem was services.resume.loginTokens in the user object.
We were trying implementing rocket chat methods/api on the custom native android application. Whenever application is calling the login method from the android app, It was adding a new login token without deleting the previous ones (for multi-system logins)

so if you'll delete the previous one with some date check, It won't create overheads to the user object.

Accounts.registerLoginHandler (loginRequest) ->

  # ... Do whatever you need to do to authenticate the user

  stampedToken = Accounts._generateStampedLoginToken();
  Meteor.users.update userId,
    $push: {'services.resume.loginTokens': stampedToken}

  # Delete old resume tokens so they don't clog up the db
  cutoff = +(new Date) - (24*60*60)*1000
  Meteor.users.update userId, {
        when: {$lt: cutoff}
  {multi : true}

  return {
    id: userId,
    token: stampedToken.token

I got this solution from this so question