|
6 | 6 |
|
7 | 7 | #include "absl/strings/str_split.h"
|
8 | 8 | #include "facade/resp_expr.h"
|
| 9 | +#include "util/fibers/detail/fiber_interface.h" |
| 10 | +#include "util/fibers/proactor_base.h" |
9 | 11 | #include "util/fibers/synchronization.h"
|
10 | 12 |
|
11 | 13 | #ifdef __FreeBSD__
|
@@ -130,6 +132,12 @@ ABSL_FLAG(uint32_t, uring_wake_mode, 1,
|
130 | 132 |
|
131 | 133 | ABSL_FLAG(uint32_t, uring_submit_threshold, 1u << 31, "");
|
132 | 134 |
|
| 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 | + |
133 | 141 | ABSL_FLAG(uint32_t, squash_stats_latency_lower_limit, 0,
|
134 | 142 | "If set, will not track latency stats below this threshold (usec). ");
|
135 | 143 |
|
@@ -739,6 +747,17 @@ void UpdateUringFlagsOnThread() {
|
739 | 747 | #endif
|
740 | 748 | }
|
741 | 749 |
|
| 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 | + |
742 | 761 | void SetHuffmanTable(const std::string& huffman_table) {
|
743 | 762 | if (huffman_table.empty())
|
744 | 763 | return;
|
@@ -872,6 +891,12 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*>
|
872 | 891 | RegisterMutableFlags(&config_registry,
|
873 | 892 | facade::GetFlagNames(FLAGS_uring_wake_mode, FLAGS_uring_submit_threshold),
|
874 | 893 | []() { 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(); }); |
875 | 900 |
|
876 | 901 | config_registry.RegisterSetter<MemoryBytesFlag>("maxmemory", [](const MemoryBytesFlag& flag) {
|
877 | 902 | // 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*>
|
954 | 979 | facade::Connection::UpdateFromFlags();
|
955 | 980 | UpdateFromFlagsOnThread();
|
956 | 981 | UpdateUringFlagsOnThread();
|
| 982 | + UpdateSchedulerFlagsOnThread(); |
957 | 983 | });
|
958 | 984 | SetHuffmanTable(GetFlag(FLAGS_huffman_table));
|
959 | 985 |
|
|
0 commit comments