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_manager: change cpu time unit from ms to ns #6102

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions client/resource_group/controller/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package controller

import (
"os"
"time"

"github.com/elastic/gosigar"
"github.com/pingcap/log"
Expand All @@ -38,9 +39,9 @@ type RequestInfo interface {

// ResponseInfo is the interface of the response information provider. A response should be
// able to tell how many bytes it read and KV CPU cost in milliseconds.
type ResponseInfo interface {
type RespontokenConsumptionPerSecondseInfo interface {
JmPotato marked this conversation as resolved.
Show resolved Hide resolved
ReadBytes() uint64
KVCPUMs() uint64
KVCPU() time.Duration
// Succeed is used to tell whether the request is successfully returned.
// If not, we need to pay back the WRU cost of the request.
Succeed() bool
Expand Down Expand Up @@ -116,7 +117,7 @@ func (kc *KVCalculator) calculateReadCost(consumption *rmpb.Consumption, res Res
}

func (kc *KVCalculator) calculateCPUCost(consumption *rmpb.Consumption, res ResponseInfo) {
kvCPUMs := float64(res.KVCPUMs())
kvCPUMs := float64(res.KVCPU().Nanoseconds()) / 1000000.0
consumption.TotalCpuTimeMs += kvCPUMs
consumption.RRU += float64(kc.CPUMsCost) * kvCPUMs
}
Expand Down
10 changes: 5 additions & 5 deletions tests/mcs/resource_manager/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (ti *testRequestInfo) WriteBytes() uint64 {
}

type testResponseInfo struct {
cpuMs uint64
cpu time.Duration
readBytes uint64
succeed bool
}
Expand All @@ -239,8 +239,8 @@ func (tri *testResponseInfo) ReadBytes() uint64 {
return tri.readBytes
}

func (tri *testResponseInfo) KVCPUMs() uint64 {
return tri.cpuMs
func (tri *testResponseInfo) KVCPU() time.Duration {
return tri.cpu
}

func (tri *testResponseInfo) Succeed() bool {
Expand Down Expand Up @@ -271,14 +271,14 @@ func (t tokenConsumptionPerSecond) makeWriteRequest() *testRequestInfo {
func (t tokenConsumptionPerSecond) makeReadResponse() *testResponseInfo {
return &testResponseInfo{
readBytes: uint64((t.rruTokensAtATime - 1) / 2),
cpuMs: uint64(t.rruTokensAtATime / 2),
cpu: time.Duration(t.rruTokensAtATime/2) * time.Millisecond,
}
}

func (t tokenConsumptionPerSecond) makeWriteResponse() *testResponseInfo {
return &testResponseInfo{
readBytes: 0,
cpuMs: 0,
cpu: time.Duration(0),
succeed: true,
}
}
Expand Down