From 8b3894c59db94d03b9d103e0eecf149968dc3798 Mon Sep 17 00:00:00 2001 From: MonsieurNicolas Date: Thu, 22 Aug 2019 15:37:30 -0700 Subject: [PATCH 1/2] fix: use MAX_PENDING_CONNECTIONS in config as upper bound simplify logic that derives overlay limits --- src/main/Config.cpp | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/main/Config.cpp b/src/main/Config.cpp index f3bd605ab0..bbf6f832ed 100644 --- a/src/main/Config.cpp +++ b/src/main/Config.cpp @@ -1028,13 +1028,12 @@ Config::adjust() int maxFsConnections = std::min( std::numeric_limits::max(), fs::getMaxConnections()); - auto totalRequiredConnections = TARGET_PEER_CONNECTIONS + - MAX_ADDITIONAL_PEER_CONNECTIONS + - MAX_PENDING_CONNECTIONS; - auto totalAuthenticatedConnections = TARGET_PEER_CONNECTIONS + MAX_ADDITIONAL_PEER_CONNECTIONS; - if (totalAuthenticatedConnections > 0 && totalRequiredConnections > 0) + + int maxPendingConnections = MAX_PENDING_CONNECTIONS; + + if (totalAuthenticatedConnections > 0) { auto outboundPendingRate = double(TARGET_PEER_CONNECTIONS) / totalAuthenticatedConnections; @@ -1047,8 +1046,26 @@ Config::adjust() std::max(1, cappedToUnsignedShort)); }; - if (totalRequiredConnections > maxFsConnections) + // see if we need to reduce maxPendingConnections + if (totalAuthenticatedConnections + maxPendingConnections > + maxFsConnections) + { + maxPendingConnections = + totalAuthenticatedConnections >= maxFsConnections + ? 1 + : static_cast( + maxFsConnections - totalAuthenticatedConnections); + } + + // if we're still over, we scale everything + if (totalAuthenticatedConnections + maxPendingConnections > + maxFsConnections) { + maxPendingConnections = std::max(MAX_PENDING_CONNECTIONS, 1); + + int totalRequiredConnections = + totalAuthenticatedConnections + maxPendingConnections; + auto outboundRate = (double)TARGET_PEER_CONNECTIONS / totalRequiredConnections; auto inboundRate = (double)MAX_ADDITIONAL_PEER_CONNECTIONS / @@ -1061,32 +1078,25 @@ Config::adjust() auto authenticatedConnections = TARGET_PEER_CONNECTIONS + MAX_ADDITIONAL_PEER_CONNECTIONS; - MAX_PENDING_CONNECTIONS = + maxPendingConnections = authenticatedConnections >= maxFsConnections ? 1 : static_cast(maxFsConnections - authenticatedConnections); } - // allow setting own values for testing purposes + MAX_PENDING_CONNECTIONS = static_cast(std::min( + std::numeric_limits::max(), maxPendingConnections)); + + // derive outbound/inbound pending connections + // from MAX_PENDING_CONNECTIONS, using the ratio of inbound/outbound + // connections if (MAX_OUTBOUND_PENDING_CONNECTIONS == 0 && MAX_INBOUND_PENDING_CONNECTIONS == 0) { - if (TARGET_PEER_CONNECTIONS <= - std::numeric_limits::max() / 2) - { - MAX_OUTBOUND_PENDING_CONNECTIONS = TARGET_PEER_CONNECTIONS * 2; - } - else - { - MAX_OUTBOUND_PENDING_CONNECTIONS = - std::numeric_limits::max(); - } - - MAX_OUTBOUND_PENDING_CONNECTIONS = - std::min(MAX_OUTBOUND_PENDING_CONNECTIONS, - doubleToNonzeroUnsignedShort(MAX_PENDING_CONNECTIONS * - outboundPendingRate)); + MAX_OUTBOUND_PENDING_CONNECTIONS = std::max( + 1, doubleToNonzeroUnsignedShort(MAX_PENDING_CONNECTIONS * + outboundPendingRate)); MAX_INBOUND_PENDING_CONNECTIONS = std::max( 1, MAX_PENDING_CONNECTIONS - MAX_OUTBOUND_PENDING_CONNECTIONS); } From a32f9206a09b3caba028743cfa513e1e80efebe6 Mon Sep 17 00:00:00 2001 From: MonsieurNicolas Date: Thu, 22 Aug 2019 16:37:30 -0700 Subject: [PATCH 2/2] reduce the limit of open descriptors in travis --- travis-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis-build.sh b/travis-build.sh index ba242ab79f..9bd6f6b7dc 100755 --- a/travis-build.sh +++ b/travis-build.sh @@ -123,7 +123,7 @@ export ALL_VERSIONS=1 export TEMP_POSTGRES=0 export NUM_PARTITIONS=$((NPROCS*2)) export RUN_PARTITIONS -ulimit -n 1024 +ulimit -n 256 time make check echo All done