From 258292366298bbc55e9c3c432efc523dfb394014 Mon Sep 17 00:00:00 2001 From: Richard Schubert Date: Tue, 13 Feb 2024 12:25:34 -0600 Subject: [PATCH] Improve polling for available file descriptors - Remove 8MB of memory for each socket created - Reduce available file descriptor polling to minimum necessary - roughly a 1000 times faster - old duration: 34'571'539 ns - new duration: 34'464 ns --- utilities/xmlrpcpp/src/XmlRpcServer.cpp | 57 +++++++++++-------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/utilities/xmlrpcpp/src/XmlRpcServer.cpp b/utilities/xmlrpcpp/src/XmlRpcServer.cpp index 99aa24d2f0..28bcf70cd1 100644 --- a/utilities/xmlrpcpp/src/XmlRpcServer.cpp +++ b/utilities/xmlrpcpp/src/XmlRpcServer.cpp @@ -30,26 +30,6 @@ XmlRpcServer::XmlRpcServer() _accept_error(false), _accept_retry_time_sec(0.0) { -#if !defined(_WINDOWS) - struct rlimit limit = { .rlim_cur = 0, .rlim_max = 0 }; - unsigned int max_files = 1024; - - if(getrlimit(RLIMIT_NOFILE, &limit) == 0) { - max_files = limit.rlim_max; - if( limit.rlim_max == RLIM_INFINITY ) { - max_files = 0; - } - } else { - XmlRpcUtil::error("Could not get open file limit: %s", strerror(errno)); - } - pollfds.resize(max_files); - for(unsigned int i=0; i= 0) { - for(rlim_t i=0; i FREE_FD_BUFFER ? FREE_FD_BUFFER : limit.rlim_cur); + + // Poll the available file descriptors. + // The POSIX specification guarantees that rlim_cur will always be less or + // equal to the process's initial rlim_max, so we don't need an additional + // bounds check here. + for(unsigned long long offset=0; offset= 0) { + for(rlim_t i=0; i