Skip to content

kv: protect Replica's lastToReplica and lastFromReplica fields with raftMu#74355

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/assortedPerf17
Jan 10, 2022
Merged

kv: protect Replica's lastToReplica and lastFromReplica fields with raftMu#74355
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/assortedPerf17

Conversation

@nvb
Copy link
Copy Markdown
Contributor

@nvb nvb commented Dec 31, 2021

This commit moves the Replica's lastToReplica and lastFromReplica from
under the Replica.mu mutex to the Replica.raftMu mutex. These are
strictly Raft-specific pieces of state, so we don't need fine-grained
locking around them. As a reward, we don't need to grab the Replica.mu
exclusively (or at all) when setting the fields in
Store.withReplicaForRequest.

The locking in setLastReplicaDescriptors showed up in a mutex profile
under a write-heavy workload. It was responsible for 3.44% of mutex
wait time. Grabbing the mutex was probably also slowing down request
processing, as the exclusive lock acquisition had to wait for read locks
to be dropped.

Screen Shot 2021-12-30 at 9 45 08 PM

@nvb nvb requested a review from tbg December 31, 2021 02:57
@nvb nvb requested a review from a team as a code owner December 31, 2021 02:57
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
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.

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/kv/kvserver/replica_raft.go, line 1286 at r1 (raw file):

// sendRaftMessage sends a Raft message.
func (r *Replica) sendRaftMessage(ctx context.Context, msg raftpb.Message) {

sendRaftMessageRaftMuLocked?


pkg/kv/kvserver/replica_raft_quiesce.go, line 401 at r1 (raw file):

}

func (r *Replica) quiesceAndNotifyLocked(

RaftMuLocked?

…aftMu

This commit moves the Replica's lastToReplica and lastFromReplica from
under the `Replica.mu` mutex to the `Replica.raftMu` mutex. These are
strictly Raft-specific pieces of state, so we don't need fine-grained
locking around them. As a reward, we don't need to grab the `Replica.mu`
exclusively (or at all) when setting the fields in
`Store.withReplicaForRequest`.

The locking in `setLastReplicaDescriptors` showed up in a mutex profile
under a write-heavy workload. It was responsible for **3.44%** of mutex
wait time. Grabbing the mutex was probably also slowing down request
processing, as the exclusive lock acquisition had to wait for read locks
to be dropped.
@nvb nvb force-pushed the nvanbenschoten/assortedPerf17 branch from 0e3538a to 410ef29 Compare January 10, 2022 04:08
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.

TFTR!

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


pkg/kv/kvserver/replica_raft.go, line 1286 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

sendRaftMessageRaftMuLocked?

Done.


pkg/kv/kvserver/replica_raft_quiesce.go, line 401 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

RaftMuLocked?

Done.

@nvb
Copy link
Copy Markdown
Contributor Author

nvb commented Jan 10, 2022

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 10, 2022

Build succeeded:

@craig craig bot merged commit 62392dc into cockroachdb:master Jan 10, 2022
@nvb nvb deleted the nvanbenschoten/assortedPerf17 branch January 10, 2022 21: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.

3 participants