Skip to content

Set the rlimit for NOFILE to 1024 to reduce the subprocess cleanup #3101

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

Merged
merged 2 commits into from
Sep 25, 2019

Conversation

cdecker
Copy link
Member

@cdecker cdecker commented Sep 25, 2019

This should limit the overhead introduced by 25ddb80, specifically the loop calling syscalls here:

/* Make (fairly!) sure all other fds are closed. */
int max = sysconf(_SC_OPEN_MAX);
for (int i = 3; i < max; i++)
if (i != execfail[1])
close(i);

In some environments this would be way larger (e.g., running as root in docker), resulting in way more close() calls than intended. This PR limits the number of concurrent open fds, so we have to check and close a smaller range.

Ping @NicolasDorier

Fixes #2977
Fixes #3074

We should never open more than 1024 file descriptors anyway, and under some
situations, namely running as root or in docker, would give us huge
allowances. This then results in a huge, unneeded, cleanup for subprocesses,
which we use a lot.

Fixes ElementsProject#2977
We were compiling them from source, but then not adding them in the final
docker image. This just drops the source based ones in favor of system
provided ones.

Fixes ElementsProject#3074
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 6e134e3

@rustyrussell rustyrussell merged commit 48728d3 into ElementsProject:master Sep 25, 2019
@NicolasDorier
Copy link
Collaborator

cool thanks, will release a new version of current release with this patch today,


/*~ Make sure that we limit ourselves to something reasonable. Modesty
* is a virtue. */
setrlimit(RLIMIT_NOFILE, &nofile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be moderately useful to have this as a configurable option? Or do we need to do this setrlimit ASAP before any command-line processing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we can make it configurable, but for now this limits us to ~1000 peers, which should be an ok guess for now.

For non-root users we're unlikely to even have a higher limit since it requires system configuration changes. If this becomes an issue we can definitely introduce the option.

@ZmnSCPxj ZmnSCPxj mentioned this pull request Sep 28, 2019
@cdecker cdecker mentioned this pull request Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing libraries in the Docker image Anormal CPU consumption
4 participants