milvus/internal/querynode/scheduler_policy.go
zhenshan.cao 1647bebaf4
Count growing segment number to estimate cpu usage (#17820) (#18027)
Signed-off-by: zhenshan.cao <zhenshan.cao@zilliz.com>
2022-07-04 15:10:20 +08:00

27 lines
602 B
Go

package querynode
import (
"container/list"
)
type scheduleReadTaskPolicy func(sqTasks *list.List, targetUsage int32, maxNum int32) ([]readTask, int32)
func defaultScheduleReadPolicy(sqTasks *list.List, targetUsage int32, maxNum int32) ([]readTask, int32) {
var ret []readTask
usage := int32(0)
var next *list.Element
for e := sqTasks.Front(); e != nil && maxNum > 0; e = next {
next = e.Next()
t, _ := e.Value.(readTask)
tUsage := t.CPUUsage()
if usage+tUsage > targetUsage {
break
}
usage += tUsage
sqTasks.Remove(e)
ret = append(ret, t)
maxNum--
}
return ret, usage
}