Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upWISH: 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
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
NCONNECTIONSlimit 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
NCONNECTIONSin src/main/connections.c;which is used to preallocate a set of
Rconnection:s of this size;static Rconnection Connections[NCONNECTIONS];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
NCONNECTIONSlimit, to say, 1024.NCONNECTIONS=16384on 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.Connectionsas 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).