Skip to content

Conversation

@dranikpg
Copy link
Contributor

@dranikpg dranikpg commented Oct 28, 2025

Whenever we are beyond the offloading threshold and a stash operation is requested, we allocate a future and return it to the caller. The future is resolved once the value is stashed or the stash is cancelled. The caller (SET command) waits for the future to be completed in the coordinator, slowing the client down to around the speed of the disk.

Before we had no back-pressure whatsoever, so clients could issue SET commands at execution speed. Not all entries are even enqueued for offloading (remember write depth). Generally, it's difficult to pick an adaptive load without back-pressure. Selecting anything faster than the ingestion speed leads to an OOM

  • Provide back-pressure for stashes that are executed when offloading should be performed
  • Optimise maps with EntryMap with heterogeneous lookup

Signed-off-by: Vladislav Oleshko <[email protected]>
Signed-off-by: Vladislav Oleshko <[email protected]>
@dranikpg dranikpg marked this pull request as ready for review October 29, 2025 08:09
PrimeTable::Cursor offloading_cursor_{}; // where RunOffloading left off

// Stash operations waiting for completion to throttle
tiering::EntryMap<::util::fb2::Future<bool>> stash_backpressure_;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either a future or... a blocking counter? I don't see how we can easily use something more lightweight

@dranikpg dranikpg requested a review from romange October 30, 2025 10:18
@romange
Copy link
Collaborator

romange commented Oct 30, 2025

Can you explain what this PR fixes/changes? what is the scenario? Please update the PR description and add "before and after" section.

@romange romange requested a review from Copilot October 30, 2025 15:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds backpressure (throttling) support to tiered storage stash operations when memory pressure is high. When the system is actively offloading data (below the offload threshold), SET commands can now wait for stash operations to complete, preventing overwhelming the I/O system.

  • Introduces a new EntryMap type alias with heterogeneous lookup support for efficient key-value lookups
  • Adds backpressure mechanism that returns futures for throttling SET operations during active offloading
  • Adjusts test configuration parameters for tiering thresholds and write depth

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/server/tiering/entry_map.h New file introducing EntryMap type with custom hasher and equality for heterogeneous lookup
src/server/tiering/small_bins.h Refactors internal maps to use EntryMap type alias
src/server/tiering/small_bins.cc Updates Delete method to use make_pair with heterogeneous lookup
src/server/tiered_storage.h Updates TryStash signature to return optional backpressure future
src/server/tiered_storage.cc Implements backpressure tracking map and resolution logic in stash/cancel/close operations
src/server/string_family.cc Integrates backpressure waiting into SET command flow
tests/dragonfly/tiering_test.py Adjusts test configuration for tiering thresholds and write depth

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dranikpg
Copy link
Contributor Author

@romange updated

romange and others added 2 commits November 2, 2025 08:05
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Roman Gershman <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Roman Gershman <[email protected]>

// If backpressure was provided, wait with reasonable limit (to avoid client deadlocking).
if (backpressure) {
std::move(backpressure)->GetFor(10ms);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe 5ms to be less intrusive?

romange
romange previously approved these changes Nov 2, 2025
@dranikpg dranikpg merged commit 4a9a481 into dragonflydb:main Nov 3, 2025
10 checks passed
abhijat pushed a commit that referenced this pull request Nov 4, 2025
Provide basic backpressure for tiered storage stashes

Signed-off-by: Abhijat Malviya <[email protected]>
@dranikpg dranikpg deleted the stash-backpressure branch November 5, 2025 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants