-
Notifications
You must be signed in to change notification settings - Fork 725
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: unify RRU and WRU into RU for token limit #5888
Changes from 4 commits
3e23636
de561ae
6883da9
ec33590
289c6e8
07fd57e
03dd887
949a73b
a7a27a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,10 @@ import ( | |
) | ||
|
||
var ( | ||
requestUnitList map[rmpb.RequestUnitType]struct{} = map[rmpb.RequestUnitType]struct{}{ | ||
rmpb.RequestUnitType_RRU: {}, | ||
rmpb.RequestUnitType_WRU: {}, | ||
requestUnitLimitTypeList map[rmpb.RequestUnitType]struct{} = map[rmpb.RequestUnitType]struct{}{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the proto keeps |
||
rmpb.RequestUnitType_RU: {}, | ||
} | ||
requestResourceList map[rmpb.RawResourceType]struct{} = map[rmpb.RawResourceType]struct{}{ | ||
requestResourceLimitTypeList map[rmpb.RawResourceType]struct{} = map[rmpb.RawResourceType]struct{}{ | ||
rmpb.RawResourceType_IOReadFlow: {}, | ||
rmpb.RawResourceType_IOWriteFlow: {}, | ||
rmpb.RawResourceType_CPU: {}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,27 +74,33 @@ func (kc *KVCalculator) BeforeKVRequest(consumption *rmpb.Consumption, req Reque | |
// Write bytes are knowable in advance, so we can calculate the WRU cost here. | ||
writeBytes := float64(req.WriteBytes()) | ||
consumption.WriteBytes += writeBytes | ||
consumption.WRU += float64(kc.WriteBaseCost) + float64(kc.WriteBytesCost)*writeBytes | ||
wru := float64(kc.WriteBaseCost) + float64(kc.WriteBytesCost)*writeBytes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why create a new variable? |
||
consumption.WRU += wru | ||
consumption.RU += wru | ||
} else { | ||
consumption.KvReadRpcCount += 1 | ||
// Read bytes could not be known before the request is executed, | ||
// so we only add the base cost here. | ||
consumption.RRU += float64(kc.ReadBaseCost) | ||
consumption.RU += float64(kc.ReadBaseCost) | ||
} | ||
} | ||
|
||
// AfterKVRequest ... | ||
func (kc *KVCalculator) AfterKVRequest(consumption *rmpb.Consumption, req RequestInfo, res ResponseInfo) { | ||
rru := 0. | ||
// For now, we can only collect the KV CPU cost for a read request. | ||
if !req.IsWrite() { | ||
kvCPUMs := float64(res.KVCPUMs()) | ||
consumption.TotalCpuTimeMs += kvCPUMs | ||
consumption.RRU += float64(kc.ReadCPUMsCost) * kvCPUMs | ||
rru += float64(kc.ReadCPUMsCost) * kvCPUMs | ||
} | ||
// A write request may also read data, which should be counted into the RRU cost. | ||
readBytes := float64(res.ReadBytes()) | ||
consumption.ReadBytes += readBytes | ||
consumption.RRU += float64(kc.ReadBytesCost) * readBytes | ||
rru += float64(kc.ReadBytesCost) * readBytes | ||
consumption.RRU += rru | ||
consumption.RU += rru | ||
} | ||
|
||
// SQLCalculator is used to calculate the SQL-side consumption. | ||
|
@@ -124,8 +130,10 @@ func (dsc *SQLCalculator) AfterKVRequest(consumption *rmpb.Consumption, req Requ | |
func getRUValueFromConsumption(custom *rmpb.Consumption, typ rmpb.RequestUnitType) float64 { | ||
switch typ { | ||
case 0: | ||
return custom.RRU | ||
return custom.RU | ||
case 1: | ||
return custom.RRU | ||
case 2: | ||
return custom.WRU | ||
} | ||
return 0 | ||
|
@@ -144,6 +152,7 @@ func getRawResourceValueFromConsumption(custom *rmpb.Consumption, typ rmpb.RawRe | |
} | ||
|
||
func add(custom1 *rmpb.Consumption, custom2 *rmpb.Consumption) { | ||
custom1.RU += custom2.RU | ||
custom1.RRU += custom2.RRU | ||
custom1.WRU += custom2.WRU | ||
custom1.ReadBytes += custom2.ReadBytes | ||
|
@@ -155,6 +164,7 @@ func add(custom1 *rmpb.Consumption, custom2 *rmpb.Consumption) { | |
} | ||
|
||
func sub(custom1 *rmpb.Consumption, custom2 *rmpb.Consumption) { | ||
custom1.RU -= custom2.RU | ||
custom1.RRU -= custom2.RRU | ||
custom1.WRU -= custom2.WRU | ||
custom1.ReadBytes -= custom2.ReadBytes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update with new kvproto master