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

kvserver: use MaxInflightBytes raft config option #94692

Merged
merged 1 commit into from
Jan 16, 2023

Conversation

pav-kv
Copy link
Collaborator

@pav-kv pav-kv commented Jan 4, 2023

This change starts using the raft's MaxInflightBytes option which limits the inflight total byte size of the log entries sent via MsgApp. The default limit is set to a conservatively large value, to not change the current behaviour for now.

Part of #90314
Epic: none
Release note (ops change): Added COCKROACH_RAFT_MAX_INFLIGHT_BYTES env variable which helps strictly limiting inflight traffic from a Raft leader to followers, particularly in situations when many large messages are sent and significantly exceed COCKROACH_RAFT_MAX_SIZE_PER_MSG * COCKROACH_RAFT_MAX_INFLIGHT_MSGS which is a softer limit.

@pav-kv pav-kv changed the title kvserver: user MaxInflightBytes raft config option kvserver: use MaxInflightBytes raft config option Jan 4, 2023
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@pav-kv pav-kv force-pushed the raft_max_inflight_bytes branch from 88de000 to 01c59c5 Compare January 4, 2023 13:38
@pav-kv pav-kv force-pushed the raft_max_inflight_bytes branch from 01c59c5 to 9b83e05 Compare January 11, 2023 11:37
@pav-kv pav-kv requested review from erikgrinaker and tbg January 11, 2023 11:43
@pav-kv pav-kv marked this pull request as ready for review January 11, 2023 11:43
@pav-kv pav-kv requested review from a team as code owners January 11, 2023 11:43
Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

LGTM

// TODO(#90314): lower this limit to something close to max rates observed in
// healthy clusters. Currently this value is a conservatively large multiple
// of defaultRaftMaxSizePerMsg * defaultRaftMaxInflightMsgs, so that it
// doesn't cut off traffic until we know it's ok.
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if the default here should not be hard-coded, but constructed dynamically based on MaxInflightMsgs and MaxMsgSize. Something like:

maxInflightBytes := 256 << 20
if other := maxBytesPerMsg * maxInflightMsgs {
  maxInflightBytes = other
}

We have some customers that configure MaxInflightMsgs to very high values. Presumably they'd still end up below 256<<20 (in actual BDP) for the maxInflightBytes but it does make some sense for the maxInflightBytes to always be larger than the bandwidth-delay product implied by the other two settings, unless it's explicitly specified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a fixup commit (not merging yet, testing the idea). Does this look any reasonable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idea is: if either RaftConfig or env variable has this option non-zero, then the user knows what they are doing, so we don't check. Otherwise we compute the default which is a multiple of the other 2 parameters (which can either be default too, or overridden by the user).

Alternatively, we could by default set MaxInflightBytes to 0, which would disable this feature. But then we would need to explicitly modify our prod environment to enable it. Which of the ways is better?

Copy link
Collaborator Author

@pav-kv pav-kv Jan 13, 2023

Choose a reason for hiding this comment

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

Ended up using your suggestion.

I think RaftMaxInflightBytes is an important limit on its own, it shouldn't heavily depend on RaftMaxBytesPerMsg because the latter is too much of a soft limit. So I reverted my idea of dynamically setting it to maxBytesPerMsg * maxInflightMsgs * 64 because that presumes that the largest message shouldn't normally exceed 64x target message size. I think that the users concerned with the bandwidth-delay product should primarily be tweaking RaftMaxInflightBytes.

Setting the default RaftMaxInflightBytes to a constant allows tweaking the other 2 parameters independently to optimize for different things. Since maxBytesPerMsg is effectively a "target" message size, it controls the batching strategy, and not so much the max-inflight traffic. Another interpretation of maxBytesPerMsg is: it's the subjective threshold between "small" and "large" messages. Which is also why I don't think it should determine the max-inflight-bytes.

Upping RaftMaxInflightBytes to the product makes sense though, to not accidentally break users who already assume things based on the other 2 settings. Alternatively, we could panic if the config is not reasonable? But I don't know if that would break any existing users.

pkg/base/testdata/raft_config Show resolved Hide resolved
Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Basically LGTM but need to fix overflow.

pkg/base/config.go Outdated Show resolved Hide resolved
pkg/base/config.go Outdated Show resolved Hide resolved
@pav-kv pav-kv force-pushed the raft_max_inflight_bytes branch 2 times, most recently from 6a68fee to 15b98be Compare January 13, 2023 14:29
@pav-kv pav-kv requested a review from tbg January 13, 2023 14:37
This change starts using the raft's MaxInflightBytes option which limits the
inflight total byte size of the log entries sent via MsgApp. The default limit
is set to a conservatively large value, to not change the current behaviour for
now.

Epic: none
Release note (ops change): Added COCKROACH_RAFT_MAX_INFLIGHT_BYTES env variable
which helps strictly limiting inflight traffic from a Raft leader to followers,
particularly in situations when many large messages are sent and significantly
exceed COCKROACH_RAFT_MAX_SIZE_PER_MSG * COCKROACH_RAFT_MAX_INFLIGHT_MSGS which
is a softer limit.
@pav-kv pav-kv force-pushed the raft_max_inflight_bytes branch from 15b98be to 1c41f8d Compare January 13, 2023 14:39
@pav-kv
Copy link
Collaborator Author

pav-kv commented Jan 16, 2023

bors r=erikgrinaker,tbg

@craig
Copy link
Contributor

craig bot commented Jan 16, 2023

Build succeeded:

@craig craig bot merged commit 4ed157d into cockroachdb:master Jan 16, 2023
@pav-kv pav-kv deleted the raft_max_inflight_bytes branch January 16, 2023 13:14
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.

4 participants