diff --git a/keydb.conf b/keydb.conf index 04f66f766..55594ef56 100644 --- a/keydb.conf +++ b/keydb.conf @@ -2070,3 +2070,12 @@ server-threads 2 # # By default KeyDB sets this to 2. replica-weighting-factor 2 + +# Should KeyDB make active attempts at balancing clients across threads? This can impact +# performance accepting new clients. By default this is enabled. If disabled there is still +# a best effort from the kernel to distribute across threads with SO_REUSEPORT but it will not +# be as fair. +# +# By default this is enabled +# +active-client-balancing yes \ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index efd7928bd..eaa1e2dd9 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2779,6 +2779,7 @@ standardConfig configs[] = { createBoolConfig("replica-announced", NULL, MODIFIABLE_CONFIG, g_pserver->replica_announced, 1, NULL, NULL), createBoolConfig("enable-async-commands", NULL, MODIFIABLE_CONFIG, g_pserver->enable_async_commands, 1, NULL, NULL), createBoolConfig("multithread-load-enabled", NULL, MODIFIABLE_CONFIG, g_pserver->multithread_load_enabled, 0, NULL, NULL), + createBoolConfig("active-client-balancing", NULL, MODIFIABLE_CONFIG, g_pserver->active_client_balancing, 1, NULL, NULL), /* String Configs */ createStringConfig("aclfile", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, g_pserver->acl_filename, "", NULL, NULL), diff --git a/src/networking.cpp b/src/networking.cpp index a7920b692..4346c7479 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -1319,7 +1319,7 @@ void acceptOnThread(connection *conn, int flags, char *cip) int ielCur = ielFromEventLoop(serverTL->el); bool fBootLoad = (g_pserver->loading == LOADING_BOOT); - int ielTarget = 0; + int ielTarget = ielCur; if (fBootLoad) { ielTarget = IDX_EVENT_LOOP_MAIN; // During load only the main thread is active @@ -1330,7 +1330,7 @@ void acceptOnThread(connection *conn, int flags, char *cip) while (cserver.cthreads > 1 && ielTarget == IDX_EVENT_LOOP_MAIN) ielTarget = rand() % cserver.cthreads; } - else + else if (g_pserver->active_client_balancing) { // Cluster connections are more transient, so its not worth the cost to balance // we can trust that SO_REUSEPORT is doing its job of distributing connections diff --git a/src/server.h b/src/server.h index 974661ad8..305177651 100644 --- a/src/server.h +++ b/src/server.h @@ -2635,6 +2635,7 @@ struct redisServer { int enable_async_commands; int multithread_load_enabled = 0; + int active_client_balancing = 1; long long repl_batch_offStart = -1; long long repl_batch_idxStart = -1;