mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
Fix GetMemoryCount, get min as total memory (#15931)
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
parent
9deb245d77
commit
2fcf7b9760
@ -66,22 +66,28 @@ func GetMemoryCount() uint64 {
|
||||
log.Error(icErr.Error())
|
||||
return 0
|
||||
}
|
||||
if ic {
|
||||
// in container, calculate by `cgroups`
|
||||
limit, err := getContainerMemLimit()
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return 0
|
||||
}
|
||||
return limit
|
||||
}
|
||||
// not in container, calculate by `gopsutil`
|
||||
// get host memory by `gopsutil`
|
||||
stats, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
log.Warn("failed to get memory count",
|
||||
zap.Error(err))
|
||||
return 0
|
||||
}
|
||||
// not in container, return host memory
|
||||
if !ic {
|
||||
return stats.Total
|
||||
}
|
||||
|
||||
// get container memory by `cgroups`
|
||||
limit, err := getContainerMemLimit()
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return 0
|
||||
}
|
||||
// in container, return min(hostMem, containerMem)
|
||||
if limit < stats.Total {
|
||||
return limit
|
||||
}
|
||||
return stats.Total
|
||||
}
|
||||
|
||||
|
||||
@ -14,8 +14,10 @@ package metricsinfo
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/log"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/log"
|
||||
)
|
||||
|
||||
func Test_GetCPUCoreCount(t *testing.T) {
|
||||
@ -34,6 +36,8 @@ func Test_GetCPUUsage(t *testing.T) {
|
||||
func Test_GetMemoryCount(t *testing.T) {
|
||||
log.Info("TestGetMemoryCount",
|
||||
zap.Uint64("MemoryCount", GetMemoryCount()))
|
||||
|
||||
assert.NotZero(t, GetMemoryCount())
|
||||
}
|
||||
|
||||
func Test_GetUsedMemoryCount(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user