Skip to content

Commit c96b31f

Browse files
committed
Make scheduler configurable and set defaults
1 parent 2e64d65 commit c96b31f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/server/main_service.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "absl/strings/str_split.h"
88
#include "facade/resp_expr.h"
9+
#include "util/fibers/detail/fiber_interface.h"
10+
#include "util/fibers/proactor_base.h"
911
#include "util/fibers/synchronization.h"
1012

1113
#ifdef __FreeBSD__
@@ -130,6 +132,12 @@ ABSL_FLAG(uint32_t, uring_wake_mode, 1,
130132

131133
ABSL_FLAG(uint32_t, uring_submit_threshold, 1u << 31, "");
132134

135+
ABSL_FLAG(uint32_t, scheduler_background_budget, 50'000, "Background fiber budget in nanoseconds");
136+
ABSL_FLAG(uint32_t, scheduler_background_sleep_prob, 50,
137+
"Sleep probability of background fibers on reaching budget");
138+
ABSL_FLAG(uint32_t, scheduler_background_warrant, 5,
139+
"Percentage of guaranteed cpu time for background fibers");
140+
133141
ABSL_FLAG(uint32_t, squash_stats_latency_lower_limit, 0,
134142
"If set, will not track latency stats below this threshold (usec). ");
135143

@@ -739,6 +747,17 @@ void UpdateUringFlagsOnThread() {
739747
#endif
740748
}
741749

750+
void UpdateSchedulerFlagsOnThread() {
751+
using fb2::detail::Scheduler;
752+
auto* sched = fb2::detail::FbInitializer().sched;
753+
sched->UpdateConfig(&Scheduler::Config::budget_background_fib,
754+
GetFlag(FLAGS_scheduler_background_budget));
755+
sched->UpdateConfig(&Scheduler::Config::background_sleep_prob,
756+
GetFlag(FLAGS_scheduler_background_sleep_prob));
757+
sched->UpdateConfig(&Scheduler::Config::background_warrant_pct,
758+
GetFlag(FLAGS_scheduler_background_warrant));
759+
}
760+
742761
void SetHuffmanTable(const std::string& huffman_table) {
743762
if (huffman_table.empty())
744763
return;
@@ -872,6 +891,12 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*>
872891
RegisterMutableFlags(&config_registry,
873892
facade::GetFlagNames(FLAGS_uring_wake_mode, FLAGS_uring_submit_threshold),
874893
[]() { UpdateUringFlagsOnThread(); });
894+
// Register scheduler flags
895+
RegisterMutable(
896+
&config_registry,
897+
facade::GetFlagNames(FLAGS_scheduler_background_budget, FLAGS_scheduler_background_sleep_prob,
898+
FLAGS_scheduler_background_warrant),
899+
[]() { UpdateSchedulerFlagsOnThread(); });
875900

876901
config_registry.RegisterSetter<MemoryBytesFlag>("maxmemory", [](const MemoryBytesFlag& flag) {
877902
// TODO: reduce code reliance on constant direct access of max_memory_limit
@@ -954,6 +979,7 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*>
954979
facade::Connection::UpdateFromFlags();
955980
UpdateFromFlagsOnThread();
956981
UpdateUringFlagsOnThread();
982+
UpdateSchedulerFlagsOnThread();
957983
});
958984
SetHuffmanTable(GetFlag(FLAGS_huffman_table));
959985

0 commit comments

Comments
 (0)