mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 02:15:45 +02:00
feat(server): add oom guard (#1650)
1. add flag maxmemory_ratio 2. When current used memory * maxmemory_ratio > maxmemory_limit denyoom commands will return oom error. Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
parent
7c99d2d111
commit
116934b008
5 changed files with 51 additions and 4 deletions
|
@ -71,6 +71,15 @@ void ServerState::Destroy() {
|
|||
state_ = nullptr;
|
||||
}
|
||||
|
||||
uint64_t ServerState::GetUsedMemory(uint64_t now_ns) {
|
||||
static constexpr uint64_t kCacheEveryNs = 1000;
|
||||
if (now_ns > used_mem_last_update_ + kCacheEveryNs) {
|
||||
used_mem_last_update_ = now_ns;
|
||||
used_mem_cached_ = used_mem_current.load(std::memory_order_relaxed);
|
||||
}
|
||||
return used_mem_cached_;
|
||||
}
|
||||
|
||||
bool ServerState::AllowInlineScheduling() const {
|
||||
// We can't allow inline scheduling during a full sync, because then journaling transactions
|
||||
// will be scheduled before RdbLoader::LoadItemsBuffer is finished. We can't use the regular
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue