Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxMemoryRestart in CLI.js #697

Closed
keenwon opened this issue Sep 9, 2014 · 16 comments
Closed

maxMemoryRestart in CLI.js #697

keenwon opened this issue Sep 9, 2014 · 16 comments

Comments

@keenwon
Copy link

keenwon commented Sep 9, 2014

I find the maxMemoryRestart in CLI.js, but it is not work, why?

pm2.connect(function (err) {
    pm2.start('src/test.js', {
        name: 'test',
        maxMemoryRestart: '35',
        force: true
    }, function (err, proc) {
        if (err) {
            console.error(err);
            process.exit(0);
        }
        pm2.disconnect(function () {
            process.exit(0);
        });
    });
});

pm2 v0.10.7

@Unitech
Copy link
Owner

Unitech commented Sep 9, 2014

when you do a

$ pm2 describe test

does it shows

node v8 arguments │ --max-old-space-size=35

?

@keenwon
Copy link
Author

keenwon commented Sep 9, 2014

[root@AntColony antcolony]# pm2 describe worker[3002]
Describing process with pid 7 - name worker[3002]
┌───────────────────┬────────────────────────────────────────┐
│ status │ online │
│ name │ worker[3002] │
│ id │ 7 │
│ path │ /antcolony/src/queen.js │
│ args │ 3002 │
│ exec cwd │ /antcolony │
│ error log path │ /root/.pm2/logs/worker-3002--err-7.log │
│ out log path │ /root/.pm2/logs/worker-3002--out-7.log │
│ pid path │ /root/.pm2/pids/worker-3002--7.pid │
│ mode │ fork_mode │
│ node v8 arguments │ --max-old-space-size=35 │
│ watch & reload │ ✘ │
│ interpreter │ node │
│ restarts │ 1 │
│ unstable restarts │ 0 │
│ uptime │ 33s │
│ created at │ 2014-09-09T14:46:18.038Z │
└───────────────────┴───────────


⌬ PM2 monitoring :

● worker[3000] [| ] 4 %
[5] [fork_mode] [|||||||||| ] 35.605 MB

● worker[3001] [ ] 2 %
[6] [fork_mode] [||||||| ] 24.078 MB

● worker[3002] [| ] 4 %
[7] [fork_mode] [|||||||||||||||| ] 53.109 MB

● worker[3003] [ ] 2 %
[8] [fork_mode] [||||||||||||||| ] 51.629 MB

● worker[3004] [| ] 4 %
[9] [fork_mode] [|||||| ] 22.246 MB


After a while, the process will restart(unstable). but if I run lots of ‘worker’, the redis may crash(out of memory).

@Unitech
Copy link
Owner

Unitech commented Sep 9, 2014

Thanks for this feedback. Internally, when setting the maxMemoryRestart option, PM2 set the node v8 argument --max-old-space-size that set the memory limit consumed before exiting.

Looks like an unwanted behaviour form v8 :/

@glukki
Copy link

glukki commented Nov 12, 2014

Looks like --max-old-space-size doesn't count c-land mem, so any Buffer is out of scope.
Can we watch at a total node-process memory?

@Unitech
Copy link
Owner

Unitech commented Nov 13, 2014

We gonna integrate a worker system to monitor and auto restart apps based on a memory limit instead of --max-old-space-size, issue reported to feature list

@Unitech Unitech closed this as completed Nov 13, 2014
@Unitech Unitech mentioned this issue Nov 13, 2014
15 tasks
@aronwoost
Copy link
Contributor

+1

@Tjatse
Copy link
Collaborator

Tjatse commented Nov 18, 2014

--max-old-space-size only has effects on heap memory, not working on others, e.g.: Buffer, Stream, maybe we need a watcher to monitor the process memory.

@Unitech
Copy link
Owner

Unitech commented Nov 18, 2014

@jshkurti is working on this feature

@aronwoost
Copy link
Contributor

I just want to add, that I'm looking forward to this feature. ❤️ 😊

@jshkurti
Copy link
Contributor

This is done :)

@aronwoost
Copy link
Contributor

Where to find?

@jshkurti
Copy link
Contributor

$ npm install git://github.com/Unitech/pm2#development -g

Then:

$ pm2 start app.js --max-memory-restart=15M

The worker runs every 30seconds by default. You can change that by modifying env variable PM2_WORKER_INTERVAL.

e.g.

$ PM2_WORKER_INTERVAL=2000 pm2 start app.js

Will force the worker to run every 2 second.

@aronwoost
Copy link
Contributor

Thanks! When will it come to master/npm?

@jshkurti
Copy link
Contributor

@keenwon
Copy link
Author

keenwon commented Nov 27, 2014

Thanks!

@aronwoost
Copy link
Contributor

Awesome! 👍

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

No branches or pull requests

6 participants