kvccl: re-order enterprise check in canSendToFollower#62465
kvccl: re-order enterprise check in canSendToFollower#62465craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
Fixes cockroachdb#62447. In cockroachdb#62447, Erik found that cockroachdb#59571 had re-ordered the call to `utilccl.CheckEnterpriseEnabled` to occur before checking the batch in `canSendToFollower`, instead of after. This added an error allocation into the hot path of all reads, which showed up in CPU profiles and caused an 8% performance regression on `kv95`. This commit fixes this by moving the enterprise check back out of the hot-path for all non-stale read-only batches. A follow up to this PR would be to make `utilccl.CheckEnterpriseEnabled` cheaper by avoiding the error allocation for callers that don't need an error. This work is not done in this commit.
|
I still need to run |
erikgrinaker
left a comment
There was a problem hiding this comment.
Good place to start, can look into the enterprise check follow-up. Let me know if you'd like a hand with kv95 benchmarks as well.
Reviewable status:
complete! 1 of 0 LGTMs obtained
All good, I can kick them off. Do you have a pointer to which kv95 roachtest you were running? |
|
Yep. We usually do |
|
I'm not seeing much of a top-line improvement with this change when using benchstat to look at statistical significance over 10 runs, but the improvement is pretty clear from CPU profiles taken before and after: BeforeAfterIt's possible that the call to |
I ran another 10 runs with the following patch, which makes This resulted in the following change in performance: So while there are likely some wins here to be had, likely around exposing a version of |
|
Hm, if we're hitting this often enough for the clock to be significant here, I'd be even more worried about hitting this for users that do have a license: cockroach/pkg/ccl/utilccl/license_check.go Lines 120 to 127 in c834bd8 Maybe we need to consider caching the enterprise settings? |
|
Agreed. With this PR, the clock is hit on the hot path for all requests but the enterprise license is only hit for follower reads, instead of the other way around, but I agree that we should make that check cheaper if it's going to be on the hot path of any type of request. |
|
I ran So I feel comfortable with merging this fix and calling it a day. Thanks again for finding this @erikgrinaker! bors r+ |
|
Thanks! I'll do a couple more runs as well to recheck the numbers -- kv95 does tend do be a bit unreliable. |
|
Build failed (retrying...): |
|
Build succeeded: |
|
Opened #62489 for |
|
I see significant gains with this patch, going from 61656 ops/s before to 65841 ops/s after on |


Fixes #62447.
In #62447, Erik found that #59571 had re-ordered the call to
utilccl.CheckEnterpriseEnabledto occur before checking the batch incanSendToFollower, instead of after. This added an error allocationinto the hot path of all reads, which showed up in CPU profiles and
caused an 8% performance regression on
kv95. This commit fixes this bymoving the enterprise check back out of the hot-path for all non-stale
read-only batches.
A follow up to this PR would be to make
utilccl.CheckEnterpriseEnabledcheaper by avoiding the error allocation for callers that don't need an
error. This work is not done in this commit.