mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 20:07:47 +02:00
Raise posix descriptor limit if necessary
This commit is contained in:
parent
0cd5a24233
commit
0cc96f2be1
2 changed files with 26 additions and 0 deletions
|
@ -25,6 +25,9 @@
|
||||||
#include "AssignmentClientChildData.h"
|
#include "AssignmentClientChildData.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
#include <QtCore/QJsonDocument>
|
#include <QtCore/QJsonDocument>
|
||||||
|
#ifdef POSIX_SOURCE
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
const QString ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME = "assignment-client-monitor";
|
const QString ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME = "assignment-client-monitor";
|
||||||
const int WAIT_FOR_CHILD_MSECS = 1000;
|
const int WAIT_FOR_CHILD_MSECS = 1000;
|
||||||
|
@ -71,6 +74,7 @@ AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmen
|
||||||
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
|
||||||
packetReceiver.registerListener(PacketType::AssignmentClientStatus, this, "handleChildStatusPacket");
|
packetReceiver.registerListener(PacketType::AssignmentClientStatus, this, "handleChildStatusPacket");
|
||||||
|
|
||||||
|
adjustOsResources(_numAssignmentClientForks);
|
||||||
// use QProcess to fork off a process for each of the child assignment clients
|
// use QProcess to fork off a process for each of the child assignment clients
|
||||||
for (unsigned int i = 0; i < _numAssignmentClientForks; i++) {
|
for (unsigned int i = 0; i < _numAssignmentClientForks; i++) {
|
||||||
spawnChildClient();
|
spawnChildClient();
|
||||||
|
@ -372,3 +376,23 @@ bool AssignmentClientMonitor::handleHTTPRequest(HTTPConnection* connection, cons
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssignmentClientMonitor::adjustOsResources(unsigned int numForks) const
|
||||||
|
{
|
||||||
|
#ifdef _POSIX_SOURCE
|
||||||
|
// QProcess on Unix uses six descriptors, some temporarily, for each child proc.
|
||||||
|
unsigned requiredDescriptors = 30 + 6 * numForks;
|
||||||
|
struct rlimit descLimits;
|
||||||
|
if (getrlimit(RLIMIT_NOFILE, &descLimits) == 0) {
|
||||||
|
if (descLimits.rlim_cur < requiredDescriptors) {
|
||||||
|
descLimits.rlim_cur = requiredDescriptors;
|
||||||
|
if (setrlimit(RLIMIT_NOFILE, &descLimits) == 0) {
|
||||||
|
qDebug() << "Resetting descriptor limit to" << requiredDescriptors;
|
||||||
|
} else {
|
||||||
|
const char *const errorString = strerror(errno);
|
||||||
|
qDebug() << "Failed to reset descriptor limit to" << requiredDescriptors << ":" << errorString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "AssignmentClientChildData.h"
|
#include "AssignmentClientChildData.h"
|
||||||
#include <HTTPManager.h>
|
#include <HTTPManager.h>
|
||||||
#include <HTTPConnection.h>
|
#include <HTTPConnection.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
extern const char* NUM_FORKS_PARAMETER;
|
extern const char* NUM_FORKS_PARAMETER;
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ public slots:
|
||||||
private:
|
private:
|
||||||
void spawnChildClient();
|
void spawnChildClient();
|
||||||
void simultaneousWaitOnChildren(int waitMsecs);
|
void simultaneousWaitOnChildren(int waitMsecs);
|
||||||
|
void adjustOsResources(unsigned int numForks) const;
|
||||||
|
|
||||||
QTimer _checkSparesTimer; // every few seconds see if it need fewer or more spare children
|
QTimer _checkSparesTimer; // every few seconds see if it need fewer or more spare children
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue