Skip to content

[BUG] KeyDB w/ flash hang during aggressive and blocking evictions #814

Description

@gloomy-7164

Describe the bug

KeyDB hang and was not responsive for a few seconds when it enabled flash and memory utilization grew to reach maxmemory.

It hang for a few seconds, client read/write were almost blocked and saw 1000+ ms latency. KeyDB flushed multi hundreds of MBs of data at once. maxmemory_policy = allkeys_random

I was testing keydb 6.3.3, on AWS r7gd.xlarge instance, 1 primary 0 replica.

To reproduce

  1. Spin up a keydb cluster with flash enabled.
  2. Write data into the cluster until memory utilization reaches maxmemory limit.
  3. KeyDB will enter evictions and spend several seconds busy evicting and almost not responsive. redis-cli commands took seconds to return, client throughput dropped to almost zero.

Expected behavior
Evictions should happen real-time and incrementally and keydb should not spend much time evicting hundreds of MBs of data in a blocking way.

Additional information

I think the problem is from 2 places in the code:

  1. KeyDB decides to free 5% of memory at once if storage is enabled. Code pointer, and it was from this commit. It means if maxmemory=10G, keydb will evict 500MB of data all in once which takes 5+ seconds to finish. @JohnSully Any reasons why we want to evict aggressively if storage is enabled? If evictions only involves removing data from memory and not deleting them from rocksdb, I think it should be ok to evict in the same way as non-storage mode?
  2. Redis has a mechanism to limit the max time spent in a single eviction attempt, controlled by the maxmemory-eviction-tenacity config. However this exit-early mechanism is disabled when storage is enabled, see code. What will be bad if we chose to exit evictions earlier and have storage enabled?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions