Skip to content

kvclient: add x-region, x-zone metrics to DistSender#103963

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
wenyihu6:crosslocality-new
Jun 13, 2023
Merged

kvclient: add x-region, x-zone metrics to DistSender#103963
craig[bot] merged 1 commit intocockroachdb:masterfrom
wenyihu6:crosslocality-new

Conversation

@wenyihu6
Copy link
Copy Markdown
Contributor

@wenyihu6 wenyihu6 commented May 26, 2023

Previously, there were no metrics to observe cross-region, cross-zone traffic in
batch requests / responses at DistSender.

To improve this issue, this commit introduces six new distsender metrics -

"distsender.batch_requests.replica_addressed.bytes"
"distsender.batch_responses.replica_addressed.bytes"
"distsender.batch_requests.cross_region.bytes"
"distsender.batch_responses.cross_region.bytes"
"distsender.batch_requests.cross_zone.bytes"
"distsender.batch_responses.cross_zone.bytes"

The first two metrics track the total byte count of batch requests processed and
batch responses received at DistSender. Additionally, there are four metrics to
track the aggregate counts processed and received across different regions and
zones. Note that these metrics only track the sender node and not the receiver
node as DistSender resides on the gateway node receiving SQL queries.

Part of: #103983

Release note (ops change): Six new metrics -
"distsender.batch_requests.replica_addressed.bytes",
"distsender.batch_responses.replica_addressed.bytes",
"distsender.batch_requests.cross_region.bytes",
"distsender.batch_responses.cross_region.bytes",
"distsender.batch_requests.cross_zone.bytes",
"distsender.batch_responses.cross_zone.bytes"- are now added to DistSender
metrics.

For accurate metrics, follow these assumptions:

  • Configure region and zone tier keys consistently across nodes.
  • Within a node locality, ensure unique region and zone tier keys.
  • Maintain consistent configuration of region and zone tiers across nodes.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@wenyihu6 wenyihu6 changed the title Crosslocality new kvclient/server: add cross-region byte metrics to DistSender and Node May 26, 2023
@wenyihu6
Copy link
Copy Markdown
Contributor Author

wenyihu6 commented May 26, 2023

pkg/kv/kvclient/kvcoord/dist_sender.go line 2493 at r2 (raw file):

// after receiving batch responses.
func (ds *DistSender) maybeIncrementCrossRegionBatchMetrics(ba *kvpb.BatchRequest) (bool, error) {
	gatewayNodeDesc, err := ds.nodeDescs.GetNodeDescriptor(ba.GatewayNodeID)

I used the DistSender.NodeDescStore to retrieve the gateway node's descriptor via connector here. Alternatively, we can rely on the DistSender locality, which is populated through the DistSenderConfig. I thought the current approach might reduce errors thrown here since setting locality explicitly isn't required when creating the struct for DistSenderConfig. But I wasn't sure.

@wenyihu6
Copy link
Copy Markdown
Contributor Author

pkg/kv/kvclient/kvcoord/dist_sender.go line 2490 at r2 (raw file):

// nil).
//
// isCrossRegion is returned here to avoid redundant checks for cross-region

I made the assumption that that if batch requests sent are cross-region, batch response received later should also be cross-region to avoid redundant check. But I'm not sure if this assumption always holds.

@wenyihu6
Copy link
Copy Markdown
Contributor Author

wenyihu6 commented May 26, 2023

pkg/server/node_test.go line 828 at r2 (raw file):

	// Record the node metrics before sending the requests for comparison.
	serversMetricsBeforeRequest := make(map[int]metricsPair)

I found it necessary to use this map to store the node metrics before sending the request for comparison in order for node_test to pass. It appears that the nodes are performing several cross-region batch requests after the setup. For dist_sender_test, it doesn't seem to be required as I'm sending requests immediately after creating a new DistSender. I'm wondering if I should include this map in dist_sender_test as well to avoid potential flakiness.

@wenyihu6 wenyihu6 force-pushed the crosslocality-new branch 5 times, most recently from 4eb8949 to 14bc503 Compare May 27, 2023 22:16
@wenyihu6
Copy link
Copy Markdown
Contributor Author

pkg/kv/kvclient/kvcoord/dist_sender.go line 2207 at r4 (raw file):

		}

		isCrossRegion, error := ds.maybeIncrementCrossRegionBatchMetrics(ba)

I’m not certain about the appropriate location to update the metrics. Currently, I am incrementing the metrics within sendToReplicas, which is where batches have already been divided and is now forwarding to a specific replica for the range. We have another function that increments batch counts whenever DistSender receives a batch request before subdividing. Ideally, we would want these metrics to measure similar aspects. However, we do not know the destination node in advance (as far as I understand), and we cannot determine which batch is cross-region until this point where we determine which replicas each sub-batch should be sent to. But I'm not sure if I misunderstood or if there is a better approach here.

@wenyihu6 wenyihu6 force-pushed the crosslocality-new branch 2 times, most recently from 1b54c76 to 2bd4d1d Compare May 30, 2023 16:37
@wenyihu6 wenyihu6 requested a review from kvoli May 30, 2023 21:34
Copy link
Copy Markdown
Contributor

@kvoli kvoli left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 4 files at r1, 1 of 4 files at r3, 3 of 3 files at r5, 3 of 3 files at r6, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @wenyihu6)


-- commits line 15 at r5:
You should mention the limitation/requirement that the node has a locality with a region key.


pkg/kv/kvclient/kvcoord/dist_sender.go line 390 at r2 (raw file):

Previously, wenyihu6 (Wenyi Hu) wrote…

I added these two testing knobs to capture the number of bytes of batch request accurately in DistSender. Alternatively, we can simply ensure that the metrics are non-zero. Do you have a preference between these approaches?

This looks good, could be re-used for cross-zone (same region) metrics if added.


pkg/kv/kvclient/kvcoord/dist_sender.go line 2490 at r2 (raw file):

Previously, wenyihu6 (Wenyi Hu) wrote…

I made the assumption that that if batch requests sent are cross-region, batch response received later should also be cross-region to avoid redundant check. But I'm not sure if this assumption always holds.

Seems like a fine assumption.


pkg/kv/kvclient/kvcoord/dist_sender.go line 2493 at r2 (raw file):

Previously, wenyihu6 (Wenyi Hu) wrote…

I used the DistSender.NodeDescStore to retrieve the gateway node's descriptor via gossip here. Alternatively, we can rely on the DistSender locality, which is populated through the DistSenderConfig. I thought the current approach might reduce errors thrown here since setting locality explicitly isn't required when creating the struct for DistSenderConfig. But I wasn't sure.

There can be SQL only nodes, such as in serverless where each tenant has its own dedicated SQL node.

Did you update since your previous comment?


pkg/kv/kvclient/kvcoord/dist_sender.go line 2207 at r4 (raw file):

Previously, wenyihu6 (Wenyi Hu) wrote…

I’m not certain about the appropriate location to update the metrics. Currently, I am incrementing the metrics within sendToReplicas, which is where batches have already been divided and is now forwarding to a specific replica for the range. We have another function that increments batch counts whenever DistSender receives a batch request before subdividing. Ideally, we would want these metrics to measure similar aspects. However, we do not know the destination node in advance (as far as I understand), and we cannot determine which batch is cross-region until this point where we determine which replicas each sub-batch should be sent to. But I'm not sure if I misunderstood or if there is a better approach here.

This approach seems reasonable. If there isn't already a total "divided" batch bytes metric, then we could add it in order to get a % in timeseries queries.


pkg/kv/kvclient/kvcoord/dist_sender.go line 2207 at r5 (raw file):

		}

		isCrossRegion, error := ds.maybeIncrementCrossRegionBatchMetrics(ba)

nit: rename to err

@wenyihu6 wenyihu6 force-pushed the crosslocality-new branch 3 times, most recently from fb4fcab to 8a24fc3 Compare May 31, 2023 12:39
@wenyihu6
Copy link
Copy Markdown
Contributor Author

-- commits line 15 at r5:

Previously, kvoli (Austen) wrote…

You should mention the limitation/requirement that the node has a locality with a region key.

Done.

@wenyihu6
Copy link
Copy Markdown
Contributor Author

pkg/kv/kvclient/kvcoord/dist_sender.go line 2207 at r5 (raw file):

Previously, kvoli (Austen) wrote…

nit: rename to err

Done.

@wenyihu6 wenyihu6 force-pushed the crosslocality-new branch 5 times, most recently from 0ef55f5 to ae930a3 Compare June 7, 2023 22:21
@wenyihu6 wenyihu6 marked this pull request as ready for review June 7, 2023 22:22
@wenyihu6 wenyihu6 requested a review from a team as a code owner June 7, 2023 22:22
@wenyihu6
Copy link
Copy Markdown
Contributor Author

wenyihu6 commented Jun 7, 2023

The first two commits come from #104417. I'm making a separate PR for the original second commit (node metrics).

@wenyihu6 wenyihu6 requested a review from kvoli June 7, 2023 22:23
@wenyihu6 wenyihu6 changed the title kvclient/server: add cross-region byte metrics to DistSender and Node kvclient: add x-region, x-zone metrics to DistSender Jun 7, 2023
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 13, 2023

Build failed:

@wenyihu6
Copy link
Copy Markdown
Contributor Author

wenyihu6 commented Jun 13, 2023

bors retry

The failure was due to an irrelevant flaky test that has been fixed on master.

@healthy-pod
Copy link
Copy Markdown
Contributor

bors r-

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 13, 2023

Canceled.

@healthy-pod
Copy link
Copy Markdown
Contributor

bors r+

@healthy-pod
Copy link
Copy Markdown
Contributor

bors single off

@wenyihu6
Copy link
Copy Markdown
Contributor Author

Thank you : )!

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 13, 2023

Build succeeded:

wenyihu6 added a commit to wenyihu6/cockroach that referenced this pull request Jun 14, 2023
cockroachdb#103963 accidentally removed a testing knob which caused cockroachdb#104865.
This commit adds the testing knob back.

Fixes: cockroachdb#104865
Release note: none
craig bot pushed a commit that referenced this pull request Jun 14, 2023
104658: kvserver: attempt to explain ProposalData lifecycle r=tbg a=tbg

Epic: CRDB-25287
Release note: None


104867: kvnemesis: add TestingKnobs.OnRangeSpanningNonTxnalBatch back r=tbg a=wenyihu6

#103963 accidentally removed a testing knob which caused #104865. 
This commit adds the testing knob back.

Fixes: #104865
Release note: none

Co-authored-by: Tobias Grieger <tobias.b.grieger@gmail.com>
Co-authored-by: Wenyi <wenyi.hu@cockroachlabs.com>
kvoli added a commit to kvoli/cockroach that referenced this pull request Sep 29, 2023
The X-locality log events were added in cockroachdb#103963 for the dist sender, to
alert when localities were misconfigured. In some clusters, especially
test clusters, these events are unnecessarily verbose in traces.

Change the log from `VEvent(5)` to `VInfo(5)` in the dist sender path.

Resolves: cockroachdb#110648
Epic: none
Release note: None
craig bot pushed a commit that referenced this pull request Sep 29, 2023
111140: roachtest: harmonize GCE and AWS machine types r=erikgrinaker,herkolategan,renatolabs a=srosenberg

Previously, same (performance) roachtest executed in GCE and AWS
may have used a different memory (per CPU) multiplier and/or
cpu family, e.g., cascade lake vs ice lake. In the best case,
this resulted in different performance baselines on an otherwise
equivalent machine type. In the worst case, this resulted in OOMs
due to VMs in AWS having 2x less memory per CPU.

This change harmozines GCE and AWS machine types by making them
as isomorphic as possible, wrt memory, cpu family and price.
The following heuristics are used depending on specified `MemPerCPU`:
`Standard` yields 4GB/cpu, `High` yields 8GB/cpu,
`Auto` yields 4GB/cpu up to and including 16 vCPUs, then 2GB/cpu.
`Low` is supported _only_ in GCE.
Consequently, `n2-standard` maps to `m6i`, `n2-highmem` maps to `r6i`,
`n2-custom` maps to `c6i`, modulo local SSDs in which case `m6id` is
used, etc. Note, we also force `--gce-min-cpu-platform` to `Ice Lake`;
isomorphic AWS machine types are exclusively on `Ice Lake`.

Roachprod is extended to show cpu family and architecture on `List`.
Cost estimation now correctly deals with _custom_ machine types.
Finally, we change the default zone allocation in GCE from exclusively
`us-east1-b` to ~25% `us-central1-b` and ~75% `us-east1-b`. This is
inteded to balance the quotas for local SSDs until we eventually
switch to PD-SSDs.

Epic: none
Fixes: #106570

Release note: None

111442: server,kvcoord: change x-locality log from vevent to vinfo r=arulajmani a=kvoli

The X-locality log events were added in #104585 to the Node batch
receive path, to alert when localities were misconfigured. In some
clusters, especially test clusters, these events are unnecessarily
verbose in traces.

Change the log from `VEvent(5)` to `VInfo(5)` in the node batch path.

The X-locality log events were added in #103963 for the dist sender, to
alert when localities were misconfigured. In some clusters, especially
test clusters, these events are unnecessarily verbose in traces.

Change the log from `VEvent(5)` to `VInfo(5)` in the dist sender path.

Resolves: #110648
Epic: none
Release note: None

111475: server,settingswatcher: fix the local persisted cache r=stevendanna,aliher1911 a=knz

There's two commits here, fixing 2 separate issues.
Epic: CRDB-6671

### server,settingswatcher: properly evict entries from the local persisted cache

Fixes #70567.
Supersedes #101472.

(For context, on each node there is a local persisted cache of cluster
setting customizations. This exists to ensure that configured values
can be used even before a node has fully started up and can start
reading customizations from `system.settings`.)

Prior to this patch, entries were never evicted from the local
persisted cache: when a cluster setting was reset, any previously
saved entry in the cache would remain there.

This is a very old bug, which was long hidden and was recently
revealed when commit 2f5d717 was
merged. In a nutshell, before this recent commit the code responsible
to load the entries from the cache didn't fully work and so the stale
entries were never restored from the cache. That commit fixed the
loader code, and so the stale entries became active, which made the
old bug visible.

To fix the old bug, this present commit modifies the settings watcher
to preserve KV deletion events, and propagates them to the persisted
cache.

(There is no release note because there is no user-facing release where
the bug was visible.)

### settingswatcher: write-through to the persisted cache

Fixes #111422.
Fixes #111328.

Prior to this patch, the rangefeed watcher over `system.settings` was
updating the in-RAM value store before it propagated the updates to
the persisted local cache.

In fact, the update to the persisted local cache was lagging quite a
bit behind, because the rangefeed watcher would buffer updates and
only flush them after a while.

As a result, the following sequence was possible:

1. client updates a cluster setting.
2. server is immediately shut down. The persisted cache
   has not been updated yet.
3. server is restarted. For a short while (until the settings watcher
   has caught up), the old version of the setting remains active.

This recall of ghost values of a setting was simply a bug. This patch
fixes that, by ensuring that the persisted cache is written through
before the in-RAM value store.

By doing this, we give up on batching updates to the persisted local
store. This is deemed acceptable because cluster settings are not
updated frequently.



Co-authored-by: Stan Rosenberg <stan.rosenberg@gmail.com>
Co-authored-by: Austen McClernon <austen@cockroachlabs.com>
Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
THardy98 pushed a commit to THardy98/cockroach that referenced this pull request Oct 6, 2023
The X-locality log events were added in cockroachdb#103963 for the dist sender, to
alert when localities were misconfigured. In some clusters, especially
test clusters, these events are unnecessarily verbose in traces.

Change the log from `VEvent(5)` to `VInfo(5)` in the dist sender path.

Resolves: cockroachdb#110648
Epic: none
Release note: None
@wenyihu6 wenyihu6 deleted the crosslocality-new branch October 30, 2023 17:34
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.

6 participants