#define CONF_DEFAULT_DBDIR (STORAGE_DIR "/confdb")
/*! Maximum depth of nested transactions. */
#define CONF_MAX_TXN_DEPTH 5
+
+/*! Maximum number of UDP workers. */
+#define CONF_MAX_UDP_WORKERS 256
+/*! Maximum number of TCP workers. */
+#define CONF_MAX_TCP_WORKERS 256
+/*! Maximum number of background workers. */
+#define CONF_MAX_BG_WORKERS 512
/*! Maximum number of concurrent DB readers. */
-#define CONF_MAX_DB_READERS 630
+#define CONF_MAX_DB_READERS (CONF_MAX_UDP_WORKERS + CONF_MAX_TCP_WORKERS + \
+ CONF_MAX_BG_WORKERS + 128 /* XDP workers */)
/*! Configuration specific logging. */
#define CONF_LOG(severity, msg, ...) do { \
#define DBG_LOG(err) CONF_LOG(LOG_DEBUG, "%s (%s)", __func__, knot_strerror((err)));
-#define DFLT_TCP_WORKERS_MIN 10
-#define DFLT_BG_WORKERS_MAX 10
+#define DFLT_MIN_TCP_WORKERS 10
+#define DFLT_MAX_BG_WORKERS 10
#define FALLBACK_MAX_TCP_CLIENTS 100
bool conf_db_exists(
{
conf_val_t val = conf_get_txn(conf, txn, C_SRV, C_UDP_WORKERS);
int64_t workers = conf_int(&val);
+ assert(workers <= CONF_MAX_UDP_WORKERS);
if (workers == YP_NIL) {
- return dt_optimal_size();
+ return MIN(dt_optimal_size(), CONF_MAX_UDP_WORKERS);
}
return workers;
{
conf_val_t val = conf_get_txn(conf, txn, C_SRV, C_TCP_WORKERS);
int64_t workers = conf_int(&val);
+ assert(workers <= CONF_MAX_TCP_WORKERS);
if (workers == YP_NIL) {
- return MAX(dt_optimal_size(), DFLT_TCP_WORKERS_MIN);
+ size_t optimal = MAX(dt_optimal_size(), DFLT_MIN_TCP_WORKERS);
+ return MIN(optimal, CONF_MAX_TCP_WORKERS);
}
return workers;
{
conf_val_t val = conf_get_txn(conf, txn, C_SRV, C_BG_WORKERS);
int64_t workers = conf_int(&val);
+ assert(workers <= CONF_MAX_BG_WORKERS);
if (workers == YP_NIL) {
- return MIN(dt_optimal_size(), DFLT_BG_WORKERS_MAX);
+ assert(DFLT_MAX_BG_WORKERS <= CONF_MAX_BG_WORKERS);
+ return MIN(dt_optimal_size(), DFLT_MAX_BG_WORKERS);
}
return workers;
return conf_bg_threads_txn(conf, &conf->read_txn);
}
+/*!
+ * Gets the required LMDB readers limit based on the current configuration.
+ *
+ * \note The resulting value is a common limit to journal, kasp, timers,
+ * and catalog databases. So it's over-estimated for simpicity reasons.
+ *
+ * \note This function cannot be used for the configuration database setting :-/
+ *
+ * \param[in] conf Configuration.
+ *
+ * \return Number of readers.
+ */
+static inline size_t conf_lmdb_readers(
+ conf_t *conf)
+{
+ if (conf == NULL) { // Return default in tests.
+ return 126;
+ }
+ return conf_udp_threads(conf) + conf_tcp_threads(conf) +
+ conf_bg_threads(conf) + conf_xdp_threads(conf);
+}
+
/*!
* Gets the configured maximum number of TCP clients.
*
{ C_RUNDIR, YP_TSTR, YP_VSTR = { RUN_DIR } },
{ C_USER, YP_TSTR, YP_VNONE },
{ C_PIDFILE, YP_TSTR, YP_VSTR = { "knot.pid" } },
- { C_UDP_WORKERS, YP_TINT, YP_VINT = { 1, 255, YP_NIL } },
- { C_TCP_WORKERS, YP_TINT, YP_VINT = { 1, 255, YP_NIL } },
- { C_BG_WORKERS, YP_TINT, YP_VINT = { 1, 255, YP_NIL } },
+ { C_UDP_WORKERS, YP_TINT, YP_VINT = { 1, CONF_MAX_UDP_WORKERS, YP_NIL } },
+ { C_TCP_WORKERS, YP_TINT, YP_VINT = { 1, CONF_MAX_TCP_WORKERS, YP_NIL } },
+ { C_BG_WORKERS, YP_TINT, YP_VINT = { 1, CONF_MAX_BG_WORKERS, YP_NIL } },
{ C_ASYNC_START, YP_TBOOL, YP_VNONE },
{ C_TCP_IDLE_TIMEOUT, YP_TINT, YP_VINT = { 1, INT32_MAX, 10, YP_STIME } },
{ C_TCP_IO_TIMEOUT, YP_TINT, YP_VINT = { 0, INT32_MAX, 500 } },
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include "knot/journal/knot_lmdb.h"
-
#include <stdarg.h>
#include <stdio.h> // snprintf
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
+#include "knot/journal/knot_lmdb.h"
+
+#include "knot/conf/conf.h"
#include "contrib/files.h"
#include "contrib/wire_ctx.h"
#include "libknot/dname.h"
db->dbname = dbname;
pthread_mutex_init(&db->opening_mutex, NULL);
db->maxdbs = 2;
- db->maxreaders = 1278;
+ db->maxreaders = conf_lmdb_readers(conf());
}
static bool lmdb_stat(const char *lmdb_path, struct stat *st)
if ((ret = configure_sockets(conf, server)) != KNOT_EOK) {
return ret;
}
+
+ if (conf_lmdb_readers(conf) > CONF_MAX_DB_READERS) {
+ log_warning("config, exceeded number of database readers");
+ }
}
/* Reconfigure journal DB. */