Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRG: Drop append entries when upper layer is overloaded #4735

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

neilalexander
Copy link
Member

This adds a mechanism for the Raft layer to detect when the upper layer isn't keeping up with applies. When the overloaded condition is detected, we'll start dropping newly incoming append entries instead so that the apply queue doesn't build up endlessly.

Still need to figure out what threshold makes sense here, or how it makes sense to configure it.

Signed-off-by: Neil Twigg [email protected]

server/raft.go Outdated

// Updates the overloaded state. Lock must be held.
func (n *raft) updateOverloadState() {
n.overload.Store(n.apply.len() >= overloadThreshold || n.commit-n.applied >= uint64(overloadThreshold))
Copy link
Member

Choose a reason for hiding this comment

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

More about memory then number of elements I think, WDYT?


// Pushes to the apply queue and updates the overloaded state. Lock must be held.
func (n *raft) pushToApply(ce *CommittedEntry) {
n.apply.push(ce)
Copy link
Member

Choose a reason for hiding this comment

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

I think this function returns pending, so could short circuit some work here.

// If we are overwhelmed, i.e. the upper layer is not applying entries
// fast enough and our apply queue is building up, start to drop new
// append entries instead.
if n.Overloaded() {
Copy link
Member

Choose a reason for hiding this comment

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

Just check n.apply.len()? Always present, so do not need to lock the raft group, and ipq underneath has its own which we use here anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Overloaded() doesn't take a lock but now just checks the apply queue size.

Copy link
Member

Choose a reason for hiding this comment

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

It takes the ipq lock, so we are now taking it twice in that function I think.

Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

Does the ipq size tracking effect performance?

// If we are overwhelmed, i.e. the upper layer is not applying entries
// fast enough and our apply queue is building up, start to drop new
// append entries instead.
if n.Overloaded() {
Copy link
Member

Choose a reason for hiding this comment

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

It takes the ipq lock, so we are now taking it twice in that function I think.

@neilalexander
Copy link
Member Author

Haven't benched it yet but I will do so.

@neilalexander neilalexander changed the title Raft: Drop append entries when upper layer is overloaded NRG: Drop append entries when upper layer is overloaded Feb 15, 2024
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