h2non / nar

node.js application archive - create self-contained binary like executable applications that are ready to ship and run
MIT License
428 stars 23 forks source link

Second node process - memory usage #134

Closed ruffrey closed 8 years ago

ruffrey commented 8 years ago

Sorry if this is documented somewhere but I couldn't find it.

When running a self-executable build of an app on Linux, there are two node processes. One is just labeled "node" and the other is my app. That extra node process uses ~90 MB of RAM.

Are you able to explain this, and suggest any workarounds? Thanks very much for this project.

h2non commented 8 years ago

That's related to the nar process who reads the archive, uncompress the files and finally execute it based on package.json > scripts. The app specific process is spawned as child process from parent nar specific node process.

The amount of memory needed depends on the size of your archive and amount of files, but the memory should be flushed over the time between GC collection cycles. I suppose you're talking about the RSS memory.

As solution/optimization, nar could spawn a child process only to read and extract files, and then kill it, avoiding persistent memory issues if something is leaking somewhere, but I'm not able now to do that improvements.

As workaround, I would recommend you to split the process: once your nar archive has been deployed, extract the files via my-app.nar extract and then run it as standalone node app (but node binary must be in $PATH, otherwise you have to provision it). Also, you can create the non self-contained nar package.

ruffrey commented 8 years ago

That helps a lot. Thanks!