Skip to content
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

Fix computation of overlay parameters #2248

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions src/main/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,13 +1028,12 @@ Config::adjust()
int maxFsConnections = std::min<int>(
std::numeric_limits<unsigned short>::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;
Expand All @@ -1047,8 +1046,26 @@ Config::adjust()
std::max<int>(1, cappedToUnsignedShort));
};

if (totalRequiredConnections > maxFsConnections)
// see if we need to reduce maxPendingConnections
if (totalAuthenticatedConnections + maxPendingConnections >
maxFsConnections)
{
maxPendingConnections =
totalAuthenticatedConnections >= maxFsConnections
? 1
: static_cast<unsigned short>(
maxFsConnections - totalAuthenticatedConnections);
}

// if we're still over, we scale everything
if (totalAuthenticatedConnections + maxPendingConnections >
maxFsConnections)
{
maxPendingConnections = std::max<int>(MAX_PENDING_CONNECTIONS, 1);

int totalRequiredConnections =
totalAuthenticatedConnections + maxPendingConnections;

auto outboundRate =
(double)TARGET_PEER_CONNECTIONS / totalRequiredConnections;
auto inboundRate = (double)MAX_ADDITIONAL_PEER_CONNECTIONS /
Expand All @@ -1061,32 +1078,25 @@ Config::adjust()

auto authenticatedConnections =
TARGET_PEER_CONNECTIONS + MAX_ADDITIONAL_PEER_CONNECTIONS;
MAX_PENDING_CONNECTIONS =
maxPendingConnections =
authenticatedConnections >= maxFsConnections
? 1
: static_cast<unsigned short>(maxFsConnections -
authenticatedConnections);
}

// allow setting own values for testing purposes
MAX_PENDING_CONNECTIONS = static_cast<unsigned short>(std::min<int>(
std::numeric_limits<unsigned short>::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<unsigned short>::max() / 2)
{
MAX_OUTBOUND_PENDING_CONNECTIONS = TARGET_PEER_CONNECTIONS * 2;
}
else
{
MAX_OUTBOUND_PENDING_CONNECTIONS =
std::numeric_limits<unsigned short>::max();
}

MAX_OUTBOUND_PENDING_CONNECTIONS =
std::min(MAX_OUTBOUND_PENDING_CONNECTIONS,
doubleToNonzeroUnsignedShort(MAX_PENDING_CONNECTIONS *
outboundPendingRate));
MAX_OUTBOUND_PENDING_CONNECTIONS = std::max<unsigned short>(
1, doubleToNonzeroUnsignedShort(MAX_PENDING_CONNECTIONS *
outboundPendingRate));
MAX_INBOUND_PENDING_CONNECTIONS = std::max<unsigned short>(
1, MAX_PENDING_CONNECTIONS - MAX_OUTBOUND_PENDING_CONNECTIONS);
}
Expand Down
2 changes: 1 addition & 1 deletion travis-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down