mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 06:29:30 +02:00
Merge pull request #13622 from SimonWalton-HiFi/ac-monitor-resources
Raise POSIX descriptor-limit in AC Monitor if necessary
This commit is contained in:
commit
d7a49ee594
2 changed files with 29 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(std::max(_numAssignmentClientForks, _maxAssignmentClientForks));
|
||||||
// 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,27 @@ 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 (I think) descriptors, some temporarily, for each child proc.
|
||||||
|
// Formula based on tests with a Ubuntu 16.04 VM.
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const char *const errorString = strerror(errno);
|
||||||
|
qDebug() << "Failed to read descriptor limit:" << errorString;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -55,6 +55,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