summaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@vespa.ai>2024-05-07 13:08:45 +0000
committerTor Brede Vekterli <vekterli@vespa.ai>2024-05-07 13:08:45 +0000
commit14b7d07ef53a7221a4d0156474653b08f3fc3c9a (patch)
treef9b57b05bf62e87a46ef23169477be78340e4b46 /configd
parentc58223801f86cbffcbfa9caedc3da5be02daa43e (diff)
Use `poll` instead of `select` in config sentinel work loop
`select` on glibc is not well-defined when the highest file descriptor _number_ (not count) is > 1023. Use `poll` instead, which does not have this limitation (and also is pleasantly O(|fds|) instead of O(highest fd number)).
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/manager.cpp14
-rw-r--r--configd/src/apps/sentinel/manager.h3
-rw-r--r--configd/src/apps/sentinel/sentinel.cpp15
3 files changed, 14 insertions, 18 deletions
diff --git a/configd/src/apps/sentinel/manager.cpp b/configd/src/apps/sentinel/manager.cpp
index 36bdef0dd8a..f6a74774610 100644
--- a/configd/src/apps/sentinel/manager.cpp
+++ b/configd/src/apps/sentinel/manager.cpp
@@ -170,16 +170,16 @@ Manager::handleChildDeaths()
}
void
-Manager::updateActiveFdset(fd_set *fds, int *maxNum)
+Manager::updateActiveFdset(std::vector<pollfd> &fds)
{
- // ### _Possibly put an assert here if fd is > 1023???
- for (OutputConnection *c : _outputConnections) {
+ for (const OutputConnection *c : _outputConnections) {
int fd = c->fd();
if (fd >= 0) {
- FD_SET(fd, fds);
- if (fd >= *maxNum) {
- *maxNum = fd + 1;
- }
+ fds.emplace_back();
+ auto &ev = fds.back();
+ ev.fd = fd;
+ ev.events = POLLIN;
+ ev.revents = 0;
}
}
}
diff --git a/configd/src/apps/sentinel/manager.h b/configd/src/apps/sentinel/manager.h
index 765803b5da6..6967e078dd9 100644
--- a/configd/src/apps/sentinel/manager.h
+++ b/configd/src/apps/sentinel/manager.h
@@ -9,6 +9,7 @@
#include "state-api.h"
#include <vespa/config-sentinel.h>
#include <vespa/vespalib/net/http/state_server.h>
+#include <poll.h>
#include <sys/types.h>
#include <sys/select.h>
@@ -54,7 +55,7 @@ public:
virtual ~Manager();
bool terminate();
bool doWork();
- void updateActiveFdset(fd_set *fds, int *maxNum);
+ void updateActiveFdset(std::vector<pollfd> &fds);
};
}
diff --git a/configd/src/apps/sentinel/sentinel.cpp b/configd/src/apps/sentinel/sentinel.cpp
index 4f1d6019065..a327769e706 100644
--- a/configd/src/apps/sentinel/sentinel.cpp
+++ b/configd/src/apps/sentinel/sentinel.cpp
@@ -10,7 +10,6 @@
#include <clocale>
#include <string>
#include <unistd.h>
-#include <sys/time.h>
#include <vespa/log/log.h>
LOG_SETUP("sentinel.config-sentinel");
@@ -84,6 +83,7 @@ main(int argc, char **argv)
}
sentinel::Manager manager(environment);
+ std::vector<pollfd> fds;
vespalib::steady_time lastTime = vespalib::steady_clock::now();
while (!stop()) {
try {
@@ -103,16 +103,11 @@ main(int argc, char **argv)
if (vespalib::SignalHandler::CHLD.check()) {
continue;
}
- int maxNum = 0;
- fd_set fds;
- FD_ZERO(&fds);
- manager.updateActiveFdset(&fds, &maxNum);
+ fds.clear();
+ manager.updateActiveFdset(fds);
+ constexpr int poll_timeout_ms = 100;
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 100000; //0.1s
-
- select(maxNum, &fds, nullptr, nullptr, &tv);
+ poll(fds.data(), fds.size(), poll_timeout_ms);
vespalib::steady_time now = vespalib::steady_clock::now();
if ((now - lastTime) < 10ms) {