Skip to content

Conversation

@JmPotato
Copy link
Member

@JmPotato JmPotato commented May 26, 2025

What problem does this PR solve?

Issue Number: ref #9296.

What is changed and how does it work?

Add a keyspace-level service limiter to control the maximum request rate for each keyspace.
The service limit is an unburstable RU per second rate limit that applies across all resource groups within a keyspace.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

With a resource group rg1 whose RU is 5000 and is non-burstable, set the service limit to 10000 RU > 5000 RU:

image image

Set the service limit to 2500 RU:

image image

rg1 5000 RU + rg2 2500 RU with 2500 RU service limit.

image

Release note

None.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented May 26, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has signed the dco. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 26, 2025
@JmPotato JmPotato force-pushed the keyspace_service_limit branch 2 times, most recently from 1236150 to 5543513 Compare May 27, 2025 05:25
@JmPotato JmPotato marked this pull request as ready for review May 27, 2025 05:25
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 27, 2025
@JmPotato
Copy link
Member Author

/cc @rleungx @lhy1024 @glorv

@ti-chi-bot ti-chi-bot bot requested a review from rleungx May 27, 2025 05:26
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented May 27, 2025

@JmPotato: GitHub didn't allow me to request PR reviews from the following users: glorv.

Note that only tikv members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @rleungx @lhy1024 @glorv

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot requested a review from lhy1024 May 27, 2025 05:26
@JmPotato JmPotato force-pushed the keyspace_service_limit branch from 5543513 to 96efc42 Compare May 27, 2025 05:33
@codecov
Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 89.57346% with 22 lines in your changes missing coverage. Please review.

Project coverage is 76.09%. Comparing base (3bc8b2c) to head (139cb8c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9354      +/-   ##
==========================================
- Coverage   76.13%   76.09%   -0.05%     
==========================================
  Files         477      478       +1     
  Lines       74282    74482     +200     
==========================================
+ Hits        56557    56674     +117     
- Misses      14211    14281      +70     
- Partials     3514     3527      +13     
Flag Coverage Δ
unittests 76.09% <89.57%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JmPotato
Copy link
Member Author

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 27, 2025
@JmPotato JmPotato force-pushed the keyspace_service_limit branch from 96efc42 to 34bdd9b Compare May 27, 2025 10:25
@JmPotato
Copy link
Member Author

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 27, 2025
oldServiceLimit := krl.ServiceLimit
krl.ServiceLimit = newServiceLimit
now := time.Now()
// If the old service limit was 0 (no limit) or the new service limit is 0,
Copy link
Member

Choose a reason for hiding this comment

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

Do we support forbidding a keyspace via setting the service limit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, we do not have this requirement. If there is, it should be relatively easy to achieve by using a negative service limit value. Or can we also achieve this by changing the state of the keyspace?

krl.ServiceLimit*serviceLimiterBurstFactor,
)
// Update the last update time.
krl.LastUpdate = now
Copy link
Member

Choose a reason for hiding this comment

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

How about moving it outside and merging it with line 65?

Copy link
Member Author

Choose a reason for hiding this comment

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

refillTokensLocked is widely used in the unit tests, moving this line out will cause us to manually update LastUpdate in the test.

c.String(http.StatusBadRequest, err.Error())
return
}
if req.ServiceLimit < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the expected behavior if limit is 0, IIRC, the ru_per_sec does not allow 0 value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, a zero value means no restriction at all, which is equivalent to the absence of a Service Limit.

@JmPotato JmPotato force-pushed the keyspace_service_limit branch from cc931e9 to c2df450 Compare May 29, 2025 02:46
Signed-off-by: JmPotato <github@ipotato.me>
JmPotato added 2 commits May 29, 2025 15:58
Signed-off-by: JmPotato <github@ipotato.me>
Signed-off-by: JmPotato <github@ipotato.me>
@JmPotato JmPotato force-pushed the keyspace_service_limit branch from 6df751f to 0843c7f Compare May 29, 2025 08:43
configEndpoint.DELETE("/group/:name", s.deleteResourceGroup)
configEndpoint.GET("/controller", s.getControllerConfig)
configEndpoint.POST("/controller", s.setControllerConfig)
// Without keyspace name, it will get/set the service limit of the null keyspace.
Copy link
Member

Choose a reason for hiding this comment

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

Does the null keyspace also have the service limit?

Copy link
Member Author

@JmPotato JmPotato May 29, 2025

Choose a reason for hiding this comment

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

I don't want to make the null keyspace too special within the system; also it's useful for the test's convenience.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Member

@rleungx rleungx left a comment

Choose a reason for hiding this comment

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

The rest LGTM

Signed-off-by: JmPotato <github@ipotato.me>
@JmPotato JmPotato force-pushed the keyspace_service_limit branch from d390f9f to 4e8043c Compare May 29, 2025 09:22
Signed-off-by: JmPotato <github@ipotato.me>
@JmPotato JmPotato requested review from glorv, nolouch and rleungx and removed request for glorv May 30, 2025 05:41
Copy link
Contributor

@glorv glorv left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented May 30, 2025

@glorv: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

LGTM

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels May 30, 2025
}
// Update the cache.
m.keyspaceNameLookup[id] = loadedName
m.updateKeyspaceNameLookup(id, loadedName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to change the keyspace name? If keyspace is modified or deleted, do we need to update it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, once a keyspace is created, its ID and name cannot be changed. Therefore, we don’t need to consider cache misses at this stage.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 30, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented May 30, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: glorv, lhy1024, rleungx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented May 30, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-05-30 06:58:04.906756512 +0000 UTC m=+174905.968774124: ☑️ agreed by rleungx.
  • 2025-05-30 13:28:53.899265928 +0000 UTC m=+16420.101611192: ☑️ agreed by lhy1024.

@ti-chi-bot ti-chi-bot bot merged commit 67b518d into tikv:master May 30, 2025
25 checks passed
@JmPotato JmPotato deleted the keyspace_service_limit branch May 31, 2025 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved component/keyspace Key space. component/resource-control dco-signoff: yes Indicates the PR's author has signed the dco. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants