Meteor bundle on production 100% CPU

@orloff

I successfully verified that using node 4.6.1 works properly, the problem is with pm2. I use pm2 to run clusters and there is a problem there:

Running node main.js works but pm2 start main.js does not, pm2 fails even when I type and pass the
--interpreter=~/.nvm/versions/node/v4.6.1/bin/node parameter to be sure the proper version of node is used.

Let me know if you have the same problem or find a solution

i use process.json for pm2, working without mistakes, but shows 100% CPU on VM, and it is only small meteor app

In my case, the problem was that PM2 in cluster mode only uses the node version where PM2 resides… I installed PM2 using node v6, so, in cluster mode will always use that version.

Running the app in single fork mode works as long as you apply nvm use 4 (in case you are using nvm) before running the app

Also, be sure to run npm install in /programs/server with the proper version of node too, I had the node modules installed with v6 and that was causing trouble using v4

If you don’t have multiple versions of node installed then the problem is more interesting than that.

2 Likes
$ sudo pm2 kill
[PM2] Stopping PM2...
[PM2][WARN] No process found
[PM2] All processes have been stopped and deleted
[PM2] PM2 stopped
$ ps aux | grep node
root     12028  0.3  4.0 1201556 70132 ?       Ssl  14:52   0:04 node /opt/bundle/main.js
orloff    14709  0.0  0.0  12944   924 pts/0    S+   15:11   0:00 grep --color=auto node

:grinning:

1 Like

I have the same issue on the windows 8.1 x64 environment with node v6.9.1.

To replicate the issue:

  1. meteor create meteorTest
  2. remove insecure and autopublish packages so we can rule out other factors.
  3. create a dummy meteor method at server\method.js , like the below:

Meteor.methods({

test:function(inputString){
    return inputString;
}

});

  1. build it by running meteor build --directory ../meteorTest-build
  2. install all dependencies (need c++ compiler from VS2015):

cd program\server
npm install
set MONGO_URL=mongodb://localhost:27017
set ROOT_URL=http://localhost
set PORT=8080

  1. run node main.js or meteor node main.js to do the comparison
  2. browser http://localhost:8080
  3. On the browser console, run Meteor.call('test','hi123',function(err,result){ console.log(result) });

When using the meteor node, cpu usage level returns to zero after the call, while using the node v6.9.1 causes the cpu usage level goes to 25% and stuck, which means whole cpu core is consumed…

But the problem is that I cannot use meteor node with forever on node v6.9.1 . At last, I switch to node v4.6.2 via https://github.com/coreybutler/nvm-windows , so that I can keep both versions of node while using forever to run meteor.

I had the same issue with the latest pm2 version (2.1.6) and node 6.9.1. I removed autopublish and insecure that I forgot, downgraded node to 4.6.1.

Autopublish and insecure don’t seem to change anything to the CPU usage, but that’s always a good thing to do.

The node version on my ubuntu server is the deal breaker. I tried switching back and forth from 6.9.1 or 6.9.3 (LTS) and 4.6.1 and I go from 100% usage with node 6 to 1 or 2% with node 4.

Is this because Meteor’s node version is tied to node 4 ? I thought it would use the bundled version anyway ?

I’m currently experiencing the same problem
Almost no load in dev mode, but once bundled and running as a docker container. It consumes 100% cpu.
Node version of the container is 4.6.1 and I’m not using pm2.

Are you using the 32bit or 64bit version of node 4? It might be one of factors too.

64-bit

…I must type 20 characters in order to post…

I’m gonna try to run a v8 cpu profile and see if that brings something up, but for that it would be useful if support for node 6 lands, with a lot of build-in v8 tooling.

You are using Meteor 1.4.2?

Yep, 1.4.2.3 to be precise

Okay, I remembered that good old Kadira has a CPU profiling feature based on v8-profiler on my paid plan.

Cool thing is I can share them, so here is the CPU profile I took:
https://ui.kadira.io/cpf/XhwuaQyJGvD6widS4?metric=costlyFunction

Except for the client requesting the CPU profile, there were 0 other connected clients. So the application should be idle, but was running at 100% CPU.

I’m yet to learn how to interpret the profile correctly, so if anyone is experienced in this, he might come to a conclusion faster…

Can you send me the raw *.cpuprofile file? I know how to read them pretty well

1 Like

Was it bundled with 4.6.2 or a higher version? It needs to be bundled, and run with the same version ideally. Meteor apps bundled with 6.x or 7.x always run at 100% CPU. This is a major issue MDG should look at, they advice what node to run the apps at, but do not state (to the best of my knowledge) they need to be bundled with it too.

Just install N and run n 4.6.2 to quickly switch :slight_smile:

This happens to me too.

On my live bundled app.
I’m using Meteor 1.4.3.2
Node 4.6.2
Ubuntu 16.04 x64

It turns out PM2 (Advance Node Process Manager) was the culprit.
Works fine when I run my app with plain node and foreverjs
$ node main.js
or
$ forever start main.js

Switched to foreverjs for now.

Please let me know how they go over time. I tried using forever instead of PM2 too, it worked for a little but as soon as connections started hitting the server, it jumped straight back up to 100%. Since reverted back to PM2 and found the actual issue root cause, for my deploy at least (mentioned above).

We faced the same issue, CPU shoots up as soon as you make any method calls, then slowly goes down. Even if we comment out most of what is in the method. We reverted to Node 4.6.2 on both development and host and all is working well now. PM2 is also working as planned, so it was not the culprit and I don’t see why it would be.

Haven’t tried with recent node and 1.4.3 meteor, but seen same 100% of cpu with node 6 and node 7 ~ month ago.

Make sure you dont have facts installed, I installed for debugging and forgot about, once I removed CPU when from 100% to 3-5%

https://atmospherejs.com/meteor/facts