Skip to content

Commit

Permalink
feat(server): introduce table_growth_margin flag (#2678)
Browse files Browse the repository at this point in the history
* feat(server): introduce table_growth_margin flag

Signed-off-by: adi_holden <[email protected]>
  • Loading branch information
adiholden authored Mar 3, 2024
1 parent 93debc7 commit 7c443f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/server/db_slice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ ABSL_FLAG(uint32_t, max_segment_to_consider, 4,
"The maximum number of dashtable segments to scan in each eviction "
"when heartbeat based eviction is triggered under memory pressure.");

ABSL_FLAG(double, table_growth_margin, 1.1,
"Prevents table from growing if number of free slots x average object size x this ratio "
"is larger than memory budget.");

namespace dfly {

using namespace std;
Expand Down Expand Up @@ -137,8 +141,9 @@ bool PrimeEvictionPolicy::CanGrow(const PrimeTable& tbl) const {
// even though we may currently use less memory.
// see https://github.com/dragonflydb/dragonfly/issues/256#issuecomment-1227095503
size_t new_available = (tbl.capacity() - tbl.size()) + PrimeTable::kSegCapacity;
bool res = mem_budget_ >
int64_t(PrimeTable::kSegBytes + db_slice_->bytes_per_object() * new_available * 1.1);
bool res =
mem_budget_ > int64_t(PrimeTable::kSegBytes + db_slice_->bytes_per_object() * new_available *
GetFlag(FLAGS_table_growth_margin));
VLOG(2) << "available: " << new_available << ", res: " << res;

return res;
Expand Down
1 change: 1 addition & 0 deletions src/server/main_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ void Service::Init(util::AcceptServer* acceptor, std::vector<facade::Listener*>
config_registry.RegisterMutable("max_segment_to_consider");
config_registry.RegisterMutable("enable_heartbeat_eviction");
config_registry.RegisterMutable("dbfilename");
config_registry.RegisterMutable("table_growth_margin");

uint32_t shard_num = GetFlag(FLAGS_num_shards);
if (shard_num == 0 || shard_num > pp_.size()) {
Expand Down

0 comments on commit 7c443f3

Please sign in to comment.