Skip to content

kv: eliminate heap allocations throughout Raft messaging and processing logic#57007

Merged
craig[bot] merged 3 commits intocockroachdb:masterfrom
nvb:nvanbenschoten/raftAlloc
Nov 24, 2020
Merged

kv: eliminate heap allocations throughout Raft messaging and processing logic#57007
craig[bot] merged 3 commits intocockroachdb:masterfrom
nvb:nvanbenschoten/raftAlloc

Conversation

@nvb
Copy link
Copy Markdown
Contributor

@nvb nvb commented Nov 23, 2020

This PR contains a few improvements within the Raft messaging and processing code to avoid common heap allocations that stuck out during tests in #56860. This will improve the general efficiency of the Raft pipeline and will specifically reduce the cost of handling large coalesced heartbeats. This will reduce the impact that these heartbeats have on the scheduler latency of other active ranges.

nvb added 3 commits November 22, 2020 18:58
We were already computing this duration one level above, so
there's no need to compute it again.
Addresses a TODO. Avoids allocations for small numbers of messages. This
is common for inactive ranges that are still heartbeating. It should
help with cases like cockroachdb#56860.
This was responsible for an allocation per processReady and
processRequestQueue call. This means that it would cause two heap
allocations per Range on each replica during a Raft heartbeat. As
a result, it was the largest source of allocations by far in tests
like cockroachdb#56860 with lots of idle Ranges heartbeating frequently.

This change should reduce the cost of handling these heartbeats,
reducing the impact the heartbeats have on other active Ranges.
@nvb nvb requested a review from aayushshah15 November 23, 2020 02:46
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@aayushshah15 aayushshah15 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aayushshah15 and @nvanbenschoten)


pkg/kv/kvserver/store_raft.go, line 282 at r3 (raw file):

		ctx context.Context, r *Replica,
	) (pErr *roachpb.Error) {
		ctx = r.AnnotateCtx(ctx)

Why aren't we using raftSchedulerCtx here?

Copy link
Copy Markdown
Contributor Author

@nvb nvb left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aayushshah15)


pkg/kv/kvserver/store_raft.go, line 282 at r3 (raw file):

Previously, aayushshah15 (Aayush Shah) wrote…

Why aren't we using raftSchedulerCtx here?

processRaftSnapshotRequest is not called from the Raft scheduler, it's called from Store.receiveSnapshot with the RPC's stream's context.

Copy link
Copy Markdown
Contributor

@aayushshah15 aayushshah15 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/kv/kvserver/store_raft.go, line 282 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

processRaftSnapshotRequest is not called from the Raft scheduler, it's called from Store.receiveSnapshot with the RPC's stream's context.

👍

@nvb
Copy link
Copy Markdown
Contributor Author

nvb commented Nov 24, 2020

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Nov 24, 2020

Build succeeded:

@craig craig bot merged commit 7f231b7 into cockroachdb:master Nov 24, 2020
@nvb nvb deleted the nvanbenschoten/raftAlloc branch November 25, 2020 14:58
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.

3 participants