Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource_control: add ru details in ExecDetails #1070

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

glorv
Copy link
Contributor

@glorv glorv commented Nov 30, 2023

cherry-pick #1032 to master and add RUWaitDuration to RUDetails. RUDetails is used in recording executing log and slow log in tidb.

@glorv
Copy link
Contributor Author

glorv commented Nov 30, 2023

@nolouch @bufferflies PTAL

@glorv
Copy link
Contributor Author

glorv commented Dec 1, 2023

/cc @JmPotato As we add ru metrics into ExecDetails, seems we can let explain analyze also depend on it and remove the global sync Map used in resourceInterceptor. Please help verify if I missed something.

@@ -115,13 +116,14 @@ func buildResourceControlInterceptor(
if reqInfo.Bypass() || resourceControlInterceptor.IsBackgroundRequest(ctx, resourceGroupName, req.RequestSource) {
return next(target, req)
}

consumption, penalty, priority, err := resourceControlInterceptor.OnRequestWait(ctx, resourceGroupName, reqInfo)
consumption, penalty, waitDuration, priority, err := resourceControlInterceptor.OnRequestWait(ctx, resourceGroupName, reqInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

how about use one struct ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there is a best practice. The different between tuple and struct is not large, I see many other functions return multiple parameters.

if stmtExec := ctx.Value(util.ExecDetailsKey); stmtExec != nil {
detail := stmtExec.(*util.ExecDetails)
atomic.AddInt64(&detail.MilliRRU, int64(consumption.RRU*1000.0))
atomic.AddInt64(&detail.MilliRRU, int64(consumption.RRU*1000.0))
Copy link
Contributor

@bufferflies bufferflies Dec 1, 2023

Choose a reason for hiding this comment

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

why it needs to retry again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

retry what?

WaitRUDuration int64
// total read ans write ru in 1/1000
MilliRRU int64
MilliWRU int64
Copy link
Contributor

Choose a reason for hiding this comment

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

where does it use in this pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return
}
if stmtExec := ctx.Value(util.ExecDetailsKey); stmtExec != nil {
detail := stmtExec.(*util.ExecDetails)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it maybe nil in some scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. If the value exists, it should not be nil, otherwise the context value should not exist.

detail := stmtExec.(*util.ExecDetails)
atomic.AddInt64(&detail.MilliRRU, int64(consumption.RRU*1000.0))
atomic.AddInt64(&detail.MilliWRU, int64(consumption.WRU*1000.0))
if waitDuration > time.Duration(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 different if remove this condition? I think zero doesn't need to treat alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the Duration is always 0 in OnResponse call, it's a very frequent value, so not need to do the atomic operation in this case. Though, the performance difference should be quite low.

@bufferflies
Copy link
Contributor

Rest LGTM, you need to sync the upstream.

@@ -329,6 +329,10 @@ type ExecDetails struct {
BackoffDuration int64
WaitKVRespDuration int64
WaitPDRespDuration int64
WaitRUDuration int64
// total read ans write ru in 1/1000
MilliRRU int64
Copy link
Contributor

@nolouch nolouch Dec 4, 2023

Choose a reason for hiding this comment

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

Is Milli for precision? I think it correspond to milliseconds, but this is multiplied by 1000.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe RRUx1000 :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. naming similar to millisecond, not sure if it is the correct naming.

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

lgtm

@bufferflies bufferflies merged commit e80e9ca into tikv:master Dec 4, 2023
9 of 10 checks passed
@glorv glorv deleted the ru-details branch December 4, 2023 07:44
iosmanthus pushed a commit to iosmanthus/client-go that referenced this pull request Dec 21, 2023
* collecting the RU information by pasing point through context.Value (tikv#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
Signed-off-by: iosmanthus <[email protected]>
nolouch pushed a commit to nolouch/client-go that referenced this pull request Feb 2, 2024
* collecting the RU information by pasing point through context.Value (tikv#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
glorv added a commit that referenced this pull request Feb 18, 2024
…#1151)

* resource_control: add ru details in ExecDetails (#1070)

* collecting the RU information by pasing point through context.Value (#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>

* use latest pd-client of release-7.5

Signed-off-by: nolouch <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Signed-off-by: nolouch <[email protected]>
Co-authored-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
zeminzhou added a commit to zeminzhou/client-go that referenced this pull request Feb 28, 2024
* collecting the RU information by pasing point through context.Value (tikv#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
Signed-off-by: iosmanthus <[email protected]>
zeminzhou added a commit to zeminzhou/client-go that referenced this pull request Feb 28, 2024
* collecting the RU information by pasing point through context.Value (tikv#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
Signed-off-by: iosmanthus <[email protected]>
zeminzhou added a commit to zeminzhou/client-go that referenced this pull request Feb 28, 2024
* collecting the RU information by pasing point through context.Value (tikv#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
Signed-off-by: iosmanthus <[email protected]>
zeminzhou added a commit to zeminzhou/client-go that referenced this pull request Feb 28, 2024
) (tikv#1151)

* resource_control: add ru details in ExecDetails (tikv#1070)

* collecting the RU information by pasing point through context.Value (tikv#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>

* use latest pd-client of release-7.5

Signed-off-by: nolouch <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Signed-off-by: nolouch <[email protected]>
Co-authored-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
Signed-off-by: zzm <[email protected]>
zeminzhou added a commit to zeminzhou/client-go that referenced this pull request Feb 28, 2024
* collecting the RU information by pasing point through context.Value (tikv#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
Signed-off-by: iosmanthus <[email protected]>
Signed-off-by: zzm <[email protected]>
zeminzhou added a commit to zeminzhou/client-go that referenced this pull request Mar 13, 2024
* collecting the RU information by pasing point through context.Value (tikv#1032)

Signed-off-by: zzm <[email protected]>

* add ruWaitDuration to RUDetails and update pd-client

Signed-off-by: glorv <[email protected]>

---------

Signed-off-by: zzm <[email protected]>
Signed-off-by: glorv <[email protected]>
Co-authored-by: zzm <[email protected]>
Signed-off-by: iosmanthus <[email protected]>
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.

4 participants