-
Notifications
You must be signed in to change notification settings - Fork 4
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
WISH: Increase limit of maximum number of open connections (currently 125+3) #28
Comments
UPDATE: I've tested with
|
A first quick mod that would allow us to modify svn diff src/main/connections.c
Index: src/main/connections.c
===================================================================
--- src/main/connections.c (revision 71879)
+++ src/main/connections.c (working copy)
@@ -120,7 +120,9 @@
# include <Startup.h>
#endif
-#define NCONNECTIONS 128 /* snow needs one per slave node */
+#ifndef NCONNECTIONS
+# define NCONNECTIONS 128 /* snow needs one per slave node */
+#endif
#define NSINKS 21
static Rconnection Connections[NCONNECTIONS]; |
I ran into the exact same issue in a different context - we are writing software that very rapidly polls small subsets of a large amount of files and it is beneficial for us to keep the file connections open so we do not incur the file opening/closing penalty. |
…raster operations When using many cores to parallelise training replicates + ncores-1 used by default in raster package, R session can overpass the maximum number of allowed connections (HenrikBengtsson/Wishlist-for-R#28) Probably fix a bug where filename is not passed to summarize_pred.Raster in summary.process_NN function
R-devel thread 'Is it a good choice to increase the NCONNECTION value?' started on 2021-08-23 https://stat.ethz.ch/pipermail/r-devel/2021-August/081033.html has a good discussion on this where R Core's shares a willingness to bump this up. |
Simple Bash instructions to tweak $ NCONNECTIONS=1024
$ sed -i -E "s/^(#define NCONNECTIONS) [[:digit:]]+/\1 $NCONNECTIONS/" src/main/connections.c To update $ sed -i -E "s/[[:digit:]]+ (connections)/$NCONNECTIONS \1/" src/library/base/man/connections.Rd These |
Added to R-devel (to become R 4.4.0) on 2023-05-30:
Source: wch/r-source@7efae40, and later also wch/r-source@d896f86 and wch/r-source@70827de. A simple test run: $ R
> parallelly::availableConnections()
[1] 128 $ R --max-connections=512
> parallelly::availableConnections()
[1] 512 and $ Rscript -e "parallelly::availableConnections()"
[1] 128
$ Rscript --max-connections=512 -e "parallelly::availableConnections()"
[1] 512 |
Great! How could we change the default in Rprofile and use the lager number in the Rstudio environment? |
Background
As documents in
help("connections", package="base")
the maximum number of connections one can have open in R (in addition to the three always reserved) is 125;Here is an example showing what happens when we try to open too many connections:
Issue
There are several use cases where one might hit the upper limit of number of open connections possible in R. A common use case where one is may face this issue is when using SNOW compute clusters. SNOW clusters as implemented by the parallel package (a core R package) uses one connection per SNOW worker. These days more users have access to large clusters or machines with a large number of cores, making it more likely to try to use clusters with > 125 nodes.
The problem with the low
NCONNECTIONS
limit in relationship to SNOW clusters has been discussed by others in the past, e.g.Troubleshooting
The total limit of 128 connections is hardcoded into the R source code as constant / macro
NCONNECTIONS
in src/main/connections.c;which is used to preallocate a set of
Rconnection
:s of this size;The NCONNECTIONS limit was increased from 50 to 128 in R 2.4.0 (released October 2006), which appears to have been done for the same reason as explained here.
Wish
NCONNECTIONS
limit, to say, 1024.NCONNECTIONS=16384
on Linux (see comment below). Similar checks may have to be done on macOS and Windows as well.int ConnIndex(Rconnection con)
for non-existing connections.Using a linked list would avoid this particular problem (see below).all 128 connections are in use
.Connections
as a linked list, which (including its memory usage) could grow and shrink as needed. This could even remove having a limit at all. This would require redesign of the code and increase the risk of introducing bugs. (This idea was proposed by @mtmorgan).The text was updated successfully, but these errors were encountered: