Check file handle limit on startup (RIPD-442, RIPD-1024):

Calculate the number of file descriptors that are needed during
execution based on the configuration file, with a hard floor
of 1024, adjusting the limit if possible. Refuse to run if enough
fds are not available.

Additionally, allow administrators to limit the number of incoming
connections a configured port will accept. By default no limit is
imposed.
This commit is contained in:
Nik Bougalis
2016-04-08 09:39:09 -07:00
parent 79ca82c078
commit 47eb4da080
25 changed files with 265 additions and 88 deletions

View File

@@ -534,6 +534,7 @@ public:
void signalStop() override;
bool checkSigs() const override;
void checkSigs(bool) override;
int fdlimit () const override;
//--------------------------------------------------------------------------
@@ -1156,14 +1157,12 @@ ApplicationImp::doStart()
void
ApplicationImp::run()
{
if (!config_->RUN_STANDALONE)
{
if (!config_->RUN_STANDALONE)
{
// VFALCO NOTE This seems unnecessary. If we properly refactor the load
// manager then the deadlock detector can just always be "armed"
//
getLoadManager ().activateDeadlockDetector ();
}
// VFALCO NOTE This seems unnecessary. If we properly refactor the load
// manager then the deadlock detector can just always be "armed"
//
getLoadManager ().activateDeadlockDetector ();
}
m_stop.wait ();
@@ -1201,6 +1200,27 @@ void ApplicationImp::checkSigs(bool check)
checkSigs_ = check;
}
int ApplicationImp::fdlimit() const
{
// Standard handles, config file, misc I/O etc:
int needed = 128;
// 1.5 times the configured peer limit for peer connections:
needed += static_cast<int>(0.5 + (1.5 * m_overlay->limit()));
// the number of fds needed by the backend (internally
// doubled if online delete is enabled).
needed += std::max(5, m_shaMapStore->fdlimit());
// One fd per incoming connection a port can accept, or
// if no limit is set, assume it'll handle 256 clients.
for(auto const& p : serverHandler_->setup().ports)
needed += std::max (256, p.limit);
// The minimum number of file descriptors we need is 1024:
return std::max(1024, needed);
}
//------------------------------------------------------------------------------
void