0

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 mongo:3.0
It was running smoothly on the day of installation but after some times It server was getting slow, I examined within the server with top 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 top cmd.
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.

Thanks

Community
  • 1
  • 1
Ankit Balyan
  • 1,319
  • 19
  • 31

1 Answers1

0

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, {
    $pull:
      'services.resume.loginTokens':
        when: {$lt: cutoff}
  },
  {multi : true}

  return {
    id: userId,
    token: stampedToken.token
  }

I got this solution from this so question

Community
  • 1
  • 1
Ankit Balyan
  • 1,319
  • 19
  • 31
  • Can I just ask for some clarification: 1: Is this a collection you have designed, call users? Or is it the collection of mongo's own users, for mongo authentication? 2: So the cause of the problem was the existence of a lot of sub-documents in an array, in documents in the users collection. Do you know why this made the server use so much CPU? – Vince Bowdren Sep 08 '16 at 11:37
  • This design and functionality is from rocket.chat, I was implementing its API and methods into my android project. so If you have logged in, then either you should use existing login token, or logout from the app. – Ankit Balyan Sep 08 '16 at 15:56
  • My app was in development tries, So I was trying logging in manually, without the use of login tokens or logging out. – Ankit Balyan Sep 08 '16 at 15:57
  • From MDG: "Key thing with Meteor is the way DDP sends changes to documents at the level of top-level document fields. What this means is that if you have large and complex subfields on document that change often, DDP can send unnecessary changes over the wire." – Ankit Balyan Sep 09 '16 at 20:11