in spawn process memory usage is growing

125 views
Skip to first unread message

Stefano Cudini

unread,
May 22, 2014, 8:08:30 PM5/22/14
to nod...@googlegroups.com

I use the follow code to run a PHP script in CLI environment within a nodejs daemon.

The script takes the data in stdin performs the calculations and return other data to stdout.

The problem is that to run the script with child_process.spawn and pipes to an increasing memory usage. So I must to restart the node app every little time.

I would like to keep constant the use of RAM.

In the example I use cat command to simulate my php script, but the problem persists, increasing use of memory proportional to the number of cycles in setInterval. And I use setInterval to simulate period execution of the script.

var spawn = require('child_process').spawn;

var php = spawn('cat');

php.stdout.pipe(process.stdout);

var i = 0;
setInterval(function() {
    php.stdin.write(++i);
},10);

// ravi

unread,
May 23, 2014, 12:06:50 PM5/23/14
to nod...@googlegroups.com
On May 22, 2014, at 8:08 PM, Stefano Cudini <stefano...@gmail.com> wrote:
php.stdout.pipe(process.stdout);


This doesn’t make sense to me, that you are piping the stdout of the “php” process to your own stdout. Did you mean to pipe your stdout to php’s stdin? I have always found Node’s Streams stuff complicated or non-intuitive, but from a simple Unix perspective the above doesn’t compute.

Regards,

—ravi

// ravi

unread,
May 23, 2014, 12:06:53 PM5/23/14
to nod...@googlegroups.com
On May 23, 2014, at 9:36 AM, // ravi <ravi-...@g8o.net> wrote:
On May 22, 2014, at 8:08 PM, Stefano Cudini <stefano...@gmail.com> wrote:
php.stdout.pipe(process.stdout);

This doesn’t make sense to me, that you are piping the stdout of the “php” process to your own stdout.
Did you mean to pipe your stdout to php’s stdin? I have always found Node’s Streams stuff complicated or non-intuitive…

The non-intuitiveness got me :-). Ignore the above. I just [re]read the docs for Streams.

—ravi


Stefano Cudini

unread,
May 26, 2014, 9:13:24 PM5/26/14
to nod...@googlegroups.com
yes you're right, really the pipe is only for debugging ^_^

 
Regards,

—ravi

Stefano Cudini

unread,
May 26, 2014, 9:17:24 PM5/26/14
to nod...@googlegroups.com
Can you see here for more details aboute the problem:

Stefano Cudini

unread,
May 29, 2014, 8:22:05 PM5/29/14
to nod...@googlegroups.com


after various tests suggested here:
https://github.com/joyent/node/issues/7666

the problem persists .... with time... increases the memory used by node! 
Even if I kill the spawn process(into loop), or if it's auto terminated with exit
On each new execution the memory required to process node also increases imposed if the variables "--expose-gc --always-compact"

is there a way to limit the memory used by node??

my server has only 1GB of ram, help!

Reply all
Reply to author
Forward
0 new messages