Skip to content

Commit

Permalink
resource_manager: change cpu time unit from ms to ns (#6102)
Browse files Browse the repository at this point in the history
ref #5851

Signed-off-by: glorv <glorvs@163.com>
  • Loading branch information
glorv authored Mar 7, 2023
1 parent 253c798 commit 0c3ac6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 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 @@ -40,7 +41,7 @@ type RequestInfo interface {
// able to tell how many bytes it read and KV CPU cost in milliseconds.
type ResponseInfo interface {
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

0 comments on commit 0c3ac6e

Please sign in to comment.