summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@redhat.com>2023-01-10 17:59:35 -0500
committerFrank Ch. Eigler <fche@redhat.com>2023-01-10 17:59:35 -0500
commit7399e3bd7eb72d045b479173be985803f389f776 (patch)
tree7c34f0e96f8b234de67ec538bebef6c6cffd0644
parenta5b07cdf9c491fb7a4a16598c482c68b718f59b9 (diff)
downloadelfutils-users/fche/try-lessC.tar.gz
debuginfod PR29975 & PR29976: decrease default concurrencyusers/fche/try-lessC
... based on rlimit (rlimig -n NUM) ... based on cpu-affinity (taskset -c A,B,C,D ...)
-rw-r--r--configure.ac6
-rw-r--r--debuginfod/debuginfod.cxx59
2 files changed, 63 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index b2597f8b..8fe8baee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -455,6 +455,12 @@ AS_IF([test "x$ac_cv_func_mremap" = "xno"],
AC_CHECK_HEADERS([error.h])
AC_CHECK_HEADERS([err.h])
+dnl for debuginfod concurrency heuristics
+AC_CHECK_HEADERS([sched.h])
+AC_CHECK_FUNCS([sched_getaffinity])
+AC_CHECK_HEADERS([sys/resource.h])
+AC_CHECK_FUNCS([getrlimit])
+
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -D_GNU_SOURCE"
AC_FUNC_STRERROR_R()
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 02a11477..4271acf4 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -32,6 +32,18 @@
#include "config.h"
#endif
+// #define _GNU_SOURCE
+#ifdef HAVE_SCHED_H
+extern "C" {
+#include <sched.h>
+}
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+extern "C" {
+#include <sys/resource.h>
+}
+#endif
+
extern "C" {
#include "printversion.h"
#include "system.h"
@@ -398,6 +410,8 @@ static const char args_doc[] = "[PATH ...]";
/* Prototype for option handler. */
static error_t parse_opt (int key, char *arg, struct argp_state *state);
+static unsigned default_concurrency();
+
/* Data structure to communicate with argp functions. */
static struct argp argp =
{
@@ -418,7 +432,7 @@ static unsigned http_port = 8002;
static unsigned rescan_s = 300;
static unsigned groom_s = 86400;
static bool maxigroom = false;
-static unsigned concurrency = std::thread::hardware_concurrency() ?: 1;
+static unsigned concurrency = default_concurrency();
static int connection_pool = 0;
static set<string> source_paths;
static bool scan_files = false;
@@ -4082,6 +4096,47 @@ static void sqlite3_sharedprefix_fn (sqlite3_context* c, int argc, sqlite3_value
}
+static unsigned
+default_concurrency() // guaranteed >= 1
+{
+ // Prior to PR29975 & PR29976, we'd just use this:
+ unsigned sth = std::thread::hardware_concurrency();
+ // ... but on many-CPU boxes, admins or distros may throttle
+ // resources in such a way that debuginfod would mysteriously fail.
+ // So we reduce the defaults:
+
+ unsigned aff = 0;
+#ifdef HAVE_SCHED_GETAFFINITY
+ {
+ int ret;
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+ ret = sched_getaffinity(0, sizeof(mask), &mask);
+ if (ret == 0)
+ aff = CPU_COUNT(&mask);
+ }
+#endif
+
+ unsigned fn = 0;
+#ifdef HAVE_GETRLIMIT
+ {
+ struct rlimit rlim;
+ int rc = getrlimit(RLIMIT_NOFILE, &rlim);
+ if (rc == 0)
+ fn = max((rlim_t)1, (rlim.rlim_cur - 100) / 4);
+ // at least 2 fds are used by each listener thread etc.
+ // plus a bunch to account for shared libraries and such
+ }
+#endif
+
+ unsigned d = min(max(sth, 1U),
+ min(max(aff, 1U),
+ max(fn, 1U)));
+ return d;
+}
+
+
+
int
main (int argc, char *argv[])
{
@@ -4207,7 +4262,7 @@ main (int argc, char *argv[])
/* If '-C' wasn't given or was given with no arg, pick a reasonable default
for the number of worker threads. */
if (connection_pool == 0)
- connection_pool = std::thread::hardware_concurrency() * 2 ?: 2;
+ connection_pool = default_concurrency();
/* Note that MHD_USE_EPOLL and MHD_USE_THREAD_PER_CONNECTION don't
work together. */