Skip to content

Commit

Permalink
Fix cuio calculated result as float64 val (#20421)
Browse files Browse the repository at this point in the history
fix s3ioinput as float64 value while do cu calculation.

Approved by: @m-schen, @heni02, @sukki37
  • Loading branch information
xzxiong authored Nov 28, 2024
1 parent d8ca23f commit c7092ed
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/plan/function/func_builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2455,10 +2455,10 @@ func buildInMOCUWithCfg(parameters []*vector.Vector, result vector.FunctionResul
case "mem":
cu = motrace.CalculateCUMem(int64(stats.GetMemorySize()), durationNS, cfg)
case "ioin":
cu = motrace.CalculateCUIOIn(int64(stats.GetS3IOInputCount()), cfg) +
cu = motrace.CalculateCUIOIn(stats.GetS3IOInputCount(), cfg) +
motrace.CalculateCUIODelete(stats.GetS3IODeleteCount(), cfg)
case "ioout":
cu = motrace.CalculateCUIOOut(int64(stats.GetS3IOOutputCount()), cfg) +
cu = motrace.CalculateCUIOOut(stats.GetS3IOOutputCount(), cfg) +
motrace.CalculateCUIOList(stats.GetS3IOListCount(), cfg)
case "iolist":
cu = motrace.CalculateCUIOList(stats.GetS3IOListCount(), cfg)
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/trace/impl/motrace/cu.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ func CalculateCUMemDecimal(memByte, durationNS int64, memPrice, cuUnit float64)
return types.Decimal256ToFloat64(val1, cuScale), nil
}

func CalculateCUIOIn(ioCnt int64, cfg *config.OBCUConfig) float64 {
func CalculateCUIOIn(ioCnt float64, cfg *config.OBCUConfig) float64 {
if cfg == nil {
cfg = GetCUConfig()
}
return float64(ioCnt) * cfg.IoInPrice / cfg.CUUnit
return ioCnt * cfg.IoInPrice / cfg.CUUnit
}

func CalculateCUIOOut(ioCnt int64, cfg *config.OBCUConfig) float64 {
func CalculateCUIOOut(ioCnt float64, cfg *config.OBCUConfig) float64 {
if cfg == nil {
cfg = GetCUConfig()
}
return float64(ioCnt) * cfg.IoOutPrice / cfg.CUUnit
return ioCnt * cfg.IoOutPrice / cfg.CUUnit
}

func CalculateCUIOList(ioCnt float64, cfg *config.OBCUConfig) float64 {
Expand Down
9 changes: 5 additions & 4 deletions pkg/util/trace/impl/motrace/cu_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package motrace

import (
"github.com/matrixorigin/matrixone/pkg/config"
"github.com/matrixorigin/matrixone/pkg/util/trace/impl/motrace/statistic"
"testing"
"time"

"github.com/matrixorigin/matrixone/pkg/config"
"github.com/matrixorigin/matrixone/pkg/util/trace/impl/motrace/statistic"
)

// BenchmarkCalculateMem
Expand Down Expand Up @@ -229,8 +230,8 @@ func BenchmarkCalculateElem(b *testing.B) {
b.Run(bm.name+"/io", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = CalculateCUIOIn(int64(bm.args.stats.GetS3IOInputCount()), bm.args.cfg)
_ = CalculateCUIOOut(int64(bm.args.stats.GetS3IOOutputCount()), bm.args.cfg)
_ = CalculateCUIOIn(bm.args.stats.GetS3IOInputCount(), bm.args.cfg)
_ = CalculateCUIOOut(bm.args.stats.GetS3IOOutputCount(), bm.args.cfg)
}
})
}
Expand Down
9 changes: 9 additions & 0 deletions test/distributed/cases/log/query_cu.result
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ val
select CAST(mo_cu('[5,1,2,3,4,5,6,7,8,1,2]', 0, 'iodelete') AS DECIMAL(32,4)) val;
val
11.3097
select CAST(mo_cu('[5,1,2,0.000122,4,5,6,7,8,1,2]', 0, 'ioin') AS DECIMAL(32,4)) val;
val
11.3104
select CAST(mo_cu('[5,1,2,0.000122,4,5,6,7,8,0,0]', 0, 'ioin') AS DECIMAL(32,4)) val;
val
0.0007
select CAST(mo_cu('[5,1,2,0.000244,4,5,6,7,8,0,0]', 0, 'ioin') AS DECIMAL(32,4)) val;
val
0.0014
5 changes: 5 additions & 0 deletions test/distributed/cases/log/query_cu.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ select mo_cu('[4,1,2,3,4,5,6,7,8]', 0, 'iolist') val;
-- 10 | delete
select CAST(mo_cu('[5,1,2,3,4,5,6,7,8,1,2]', 0, 'iolist') AS DECIMAL(32,4)) val;
select CAST(mo_cu('[5,1,2,3,4,5,6,7,8,1,2]', 0, 'iodelete') AS DECIMAL(32,4)) val;
-- issue moc-4510
-- cu_ioin = 0.000122 * 5.67e-06 / 1.002678e-06 ~= 0.0007
select CAST(mo_cu('[5,1,2,0.000122,4,5,6,7,8,1,2]', 0, 'ioin') AS DECIMAL(32,4)) val;
select CAST(mo_cu('[5,1,2,0.000122,4,5,6,7,8,0,0]', 0, 'ioin') AS DECIMAL(32,4)) val;
select CAST(mo_cu('[5,1,2,0.000244,4,5,6,7,8,0,0]', 0, 'ioin') AS DECIMAL(32,4)) val;

0 comments on commit c7092ed

Please sign in to comment.