Skip to content
Prev 60074 / 63421 Next

Is it a good choice to increase the NCONNECTION value?

Currently, setrlimit() is called by R_EnsureFDLimit() and the latter is called by initLoadedDLL() in Rdynload.c depending on the R_MAX_NUM_DLLS environment variable.

R_MAX_NUM_DLLS can be at most 1000 and the ulimit is raised to ceil(R_MAX_NUM_DLLS/0.6), which is at most 1667.

That seems pretty low to me.


I would not mind calling R_EnsureFDLimit(10000) unconditionnally. Ten thousand file descriptors should be "cheap" enough in system resources on any modern system (probably less than hundred megabytes even if kernel structures are large), and should be enough for moderate-to-intensive uses.
I was thinking about something like /proc/$PID/fd on Linux to enumerate file descriptors of the current process, independently of who created them.

However, I did not find a fast and portable way of doing that. If thousands of file descriptors are open, we cannot afford to do thousands of system calls every time a new connection is created.


Anyway, I wrote and tested a patch with the following features:

1) Dynamic allocation of the Connections array with a MAX_NCONNECTIONS limit

2) MAX_NCONNECTIONS defaults to 8192

3) MAX_NCONNECTIONS can be set at startup by an environment variable R_MAX_NCONNECTIONS

4) MAX_NCONNECTIONS can be read and changed at run time by the options("max.n.connections")

5) R_EnsureFDLimit(10000) is called unconditionnally at startup


--

Sincerely

Andr? GILLIBERT

________________________________
De : Simon Urbanek <simon.urbanek at R-project.org>
Envoy? : jeudi 26 ao?t 2021 01:27:51
? : GILLIBERT, Andre
Cc : qweytr1 at mail.ustc.edu.cn; R-devel; Martin Maechler
Objet : Re: [Rd] Is it a good choice to increase the NCONNECTION value?

ATTENTION: Cet e-mail provient d?une adresse mail ext?rieure au CHU de Rouen. Ne cliquez pas sur les liens ou n'ouvrez pas les pi?ces jointes ? moins de conna?tre l'exp?diteur et de savoir que le contenu est s?r. En cas de doute, transf?rer le mail ? ? DSI, S?curit? ? pour analyse. Merci de votre vigilance


Andre,

as stated earlier, R already uses setrlimit() to raise the limit (see my earlier reply).

As for "special" connections, that is not feasible (without some serious re-write), since the connection doesn't know what it is used for and connections are not the only way descriptors may be used.

Anyway, I think the take away was that likely the best way forward is to make it configurable at startup time with possible option to check that value against the feasibility of open connections.

Cheers,
Simon