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

nmmain self-daemonizing is memory inefficient #117

Open
aaaaalbert opened this issue Jun 17, 2015 · 0 comments
Open

nmmain self-daemonizing is memory inefficient #117

aaaaalbert opened this issue Jun 17, 2015 · 0 comments

Comments

@aaaaalbert
Copy link
Contributor

Unless instructed otherwise via the --foreground command-line flag, the nodemanager automatically daemonizes after starting up. This puts it in the background and decouples it from the controlling terminal (if any). (Otherwise, running start_seattle.sh or python nmmain.py and later closing the terminal would kill the nodemanager.)

In order to daemonize, the nodemanager fork()s twice and redirects its stdstreams from / to /dev/null effectively. Only the latter of the forked children is kept alive, the parent and first child processes both exit.

On systems with small amounts of available memory such as WiFi routers running OpenWrt, fork()ing is problematic: The parent nodemanager process consumes significant amounts of RAM already, and RAM consuption increases linearly with every fork as a copy of the parent process' memory image is created. Due to the typically low CPU speed of these devices, this transient spike in RAM consumption can lock up the system for minutes, or even cause memory exhaustion which crashes the nodemanager.


An immediate solution would be to not self-daemonize, but rather use common POSIX tools to achieve the same thing:

nohup python nmmain.py </dev/null >/dev/null 2>&1 &

(nohup disables signal forwarding from the terminal to the process, the <, > redirect stdin and stdout so that the process doesn't read from or write to the terminal anymore, 2>&1 redirects stderr into the already-redirected stdout, and & puts the whole thing in the background).

This snippet would render self-daemonizing in nmmain.py unneccessary, and would replace backgrounding without detaching in the Seattle start shell script.

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

No branches or pull requests

1 participant