Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

High server CPU usage #106

Open
darkadept opened this issue Feb 7, 2017 · 10 comments
Open

High server CPU usage #106

darkadept opened this issue Feb 7, 2017 · 10 comments

Comments

@darkadept
Copy link
Contributor

darkadept commented Feb 7, 2017

I've been having strange issues with crater server-side. I've been getting 100% usage on a single node process. I was pretty sure that it had something to do with the accounts-base meteor package.

I cloned a fresh crater, edited meteor/.meteor/packages and added accounts-base, ran npm install and npm start. I watched my cpu usage and it was normal until I loaded the page. Then one of my cpu cores went to 100%. It was the node process. It continues running at 100% even if I close the client web browser.

If I run npm run debug I can record a JavaScript CPU profile and I can see that a Promise gets called over and over and over. Remember, this is without changing any code, just added the accounts-base package.

Now the stupid part is I just tried again and now it's not doing it anymore. At least with my fresh crater clone. It's still doing it consistently in my crater-based app. I did have the problem in a fresh crater clone too though, just not consistent.

In my crater-based app it's running at 100% cpu even in production mode too.

Edit: more details:
Node v6.3.1
Npm v3.10.3
O/S: Ubuntu 16.10

@jedwards1211
Copy link
Member

Huh, okay, can you export the profiling results and email them to me?

@jedwards1211
Copy link
Member

I've seen some background node processes get stuck at 100% cpu on my comp but I haven't figured out why, or if it's related.

@darkadept
Copy link
Contributor Author

Ok. I can finally reproduce it! It's definitely something with the Meteor login code. I'll try to outline the steps to reproduce it again:

  1. git clone a fresh crater
  2. add accounts-base to meteor packages
  3. run crater server
  4. access crater from browser (leave tab open), observe normal server cpu usage
  5. stop crater server
  6. In browser's tab add the following to local storage:
Meteor.userId                      <some random id>
Meteor.loginToken               <some random code>
Meteor.loginTokenExpires     <some date>
  1. close tab
  2. start crater server again
  3. access crater from browser, observe high server cpu usage

There is another way to trigger the problem:

  1. git clone a fresh crater
  2. add accounts-base to meteor packages (I think you also need accounts-password for this too)
  3. add a link on one of the pages to run Meteor.loginWithPassword('random user', 'random password')
  4. run crater server
  5. access crater from browser (local storage should be blank), observe normal server cpu usage
  6. click on link that runs Meteor.loginWithPassword(), observe high server cpu usage
  7. note that local storage is still blank because of non existent random user in login call

I have two profiles recorded, on that is good (with normal cpu usage) and one that is bad (with high cpu usage). I'll email them over to you.

@darkadept
Copy link
Contributor Author

Oh, I'll just upload the profiles here.

Crater #106 Profiles.zip

@jedwards1211
Copy link
Member

Hmmm, I wonder if I'm doing something dumb in the way I sync mongo data into redux that's churning unnecessarily. Expanding the worst offenders doesn't yield much specific information...here's what I see. Did you see high CPU usage from the browser too?

image

@darkadept
Copy link
Contributor Author

No. My if I profile my browser it seems fine. Mostly (idle). In fact, if I close my browser the cpu on the server stays pinned.

@jedwards1211
Copy link
Member

Weird. Any idea if you see the same thing with an equivalent pure-meteor app?

@darkadept
Copy link
Contributor Author

I'll check it out and report back.

@darkadept
Copy link
Contributor Author

Ok. I thought I had tried this already but I obviously didn't. I tried using Node 4 instead of 6. And it's fine now.

Node: v4.7.3
Npm: v2.15.11

This is working fine. I guess Meteor is still on node v4 so there is no real way to test a plain Meteor app with node v6. I'm guessing that if I could it would cause the same problem. Maybe, anyways.

You may want to change the line in the README that says tested on Node 6.

@jedwards1211
Copy link
Member

Hmm. Well the CI setup does perform integration tests on Node 6, not that they would catch an issue like this. When I find time I'll try to figure out exactly what's going on

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants