{ "rescan-time", 't', "SECONDS", 0, "Number of seconds to wait between rescans, 0=disable.", 0 },
{ "groom-time", 'g', "SECONDS", 0, "Number of seconds to wait between database grooming, 0=disable.", 0 },
{ "maxigroom", 'G', NULL, 0, "Run a complete database groom/shrink pass at startup.", 0 },
- { "concurrency", 'c', "NUM", 0, "Limit scanning thread concurrency to NUM.", 0 },
+ { "concurrency", 'c', "NUM", 0, "Limit scanning thread concurrency to NUM, default=#CPUs.", 0 },
+ { "connection-pool", 'C', "NUM", OPTION_ARG_OPTIONAL,
+ "Use webapi connection pool with NUM threads, default=unlim.", 0 },
{ "include", 'I', "REGEX", 0, "Include files matching REGEX, default=all.", 0 },
{ "exclude", 'X', "REGEX", 0, "Exclude files matching REGEX, default=none.", 0 },
{ "port", 'p', "NUM", 0, "HTTP port to listen on, default 8002.", 0 },
static unsigned groom_s = 86400;
static bool maxigroom = false;
static unsigned concurrency = std::thread::hardware_concurrency() ?: 1;
+static int connection_pool = 0;
static set<string> source_paths;
static bool scan_files = false;
static map<string,string> scan_archives;
concurrency = (unsigned) atoi(arg);
if (concurrency < 1) concurrency = 1;
break;
+ case 'C':
+ if (arg)
+ {
+ connection_pool = atoi(arg);
+ if (connection_pool < 2)
+ argp_failure(state, 1, EINVAL, "-C NUM minimum 2");
+ }
+ else // arg not given
+ connection_pool = std::thread::hardware_concurrency() * 2 ?: 2;
+ break;
case 'I':
// NB: no problem with unconditional free here - an earlier failed regcomp would exit program
if (passive_p)
if (verbose > 3)
obatched(clog) << "fdcache interned a=" << a << " b=" << b
<< " fd=" << fd << " mb=" << mb << " front=" << front_p << endl;
+
set_metrics();
}
}
-
+static void // error logging callback from libmicrohttpd internals
+error_cb (void *arg, const char *fmt, va_list ap)
+{
+ (void) arg;
+ inc_metric("error_count","libmicrohttpd",fmt);
+ char errmsg[512];
+ (void) vsnprintf (errmsg, sizeof(errmsg), fmt, ap); // ok if slightly truncated
+ obatched(cerr) << "libmicrohttpd error: " << errmsg; // MHD_DLOG calls already include \n
+}
// A user-defined sqlite function, to score the sharedness of the
// Start httpd server threads. Separate pool for IPv4 and IPv6, in
// case the host only has one protocol stack.
- MHD_Daemon *d4 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
+ MHD_Daemon *d4 = MHD_start_daemon ((connection_pool ? 0 : MHD_USE_THREAD_PER_CONNECTION)
#if MHD_VERSION >= 0x00095300
| MHD_USE_INTERNAL_POLLING_THREAD
#else
http_port,
NULL, NULL, /* default accept policy */
handler_cb, NULL, /* handler callback */
+ MHD_OPTION_EXTERNAL_LOGGER, error_cb, NULL,
+ (connection_pool ? MHD_OPTION_THREAD_POOL_SIZE : MHD_OPTION_END),
+ (connection_pool ? (int)connection_pool : MHD_OPTION_END),
MHD_OPTION_END);
- MHD_Daemon *d6 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION
+ MHD_Daemon *d6 = MHD_start_daemon ((connection_pool ? 0 : MHD_USE_THREAD_PER_CONNECTION)
#if MHD_VERSION >= 0x00095300
| MHD_USE_INTERNAL_POLLING_THREAD
#else
http_port,
NULL, NULL, /* default accept policy */
handler_cb, NULL, /* handler callback */
+ MHD_OPTION_EXTERNAL_LOGGER, error_cb, NULL,
+ (connection_pool ? MHD_OPTION_THREAD_POOL_SIZE : MHD_OPTION_END),
+ (connection_pool ? (int)connection_pool : MHD_OPTION_END),
MHD_OPTION_END);
if (d4 == NULL && d6 == NULL) // neither ipv4 nor ipv6? boo
if (! passive_p)
obatched(clog) << "search concurrency " << concurrency << endl;
+ obatched(clog) << "webapi connection pool " << connection_pool
+ << (connection_pool ? "" : " (unlimited)") << endl;
if (! passive_p)
obatched(clog) << "rescan time " << rescan_s << endl;
obatched(clog) << "fdcache fds " << fdcache_fds << endl;
--- /dev/null
+#!/usr/bin/env bash
+#
+# Copyright (C) 2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+
+mkdir Z
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=12000
+get_ports
+
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+cp -rvp ${abs_srcdir}/debuginfod-tars Z
+tempfiles Z
+
+
+for Cnum in "" "-C" "-C10" "-C100"
+do
+ env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE $Cnum -d :memory: -Z .tar.xz -Z .tar.bz2=bzcat -p $PORT1 -t0 -g0 -v --fdcache-fds=0 --fdcache-prefetch-fds=0 Z >> vlog$PORT1 2>&1 &
+ PID1=$!
+ tempfiles vlog$PORT1
+ errfiles vlog$PORT1
+
+ wait_ready $PORT1 'ready' 1
+ # Wait for server to finish indexing
+ wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+ wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+ wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+ # Do a bunch of lookups in parallel
+ for jobs in `seq 100`; do
+ curl -s http://localhost:$PORT1/buildid/cee13b2ea505a7f37bd20d271c6bc7e5f8d2dfcb/debuginfo > /dev/null &
+ done
+
+ # all 100 curls should succeed
+ wait_ready $PORT1 'http_responses_transfer_bytes_count{code="200",type="debuginfo"}' 100
+
+ (sleep 5;
+ curl -s http://localhost:$PORT1/metrics | egrep 'error|responses';
+ kill $PID1) &
+ wait # for all curls, the ()& from just above, and for debuginfod
+ PID1=0
+done
+
+xfail "grep Server.reached.connection vlog$PORT1" # PR18661
+
+exit 0