对于小内存(不大于2G),缩短服务统计导入数据库的时间

This commit is contained in:
GoEdgeLab
2022-06-25 20:57:03 +08:00
parent e6dded1965
commit b7682af9dc
3 changed files with 48 additions and 0 deletions

27
internal/utils/system.go Normal file
View File

@@ -0,0 +1,27 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils
import (
"github.com/shirou/gopsutil/v3/mem"
)
var systemTotalMemory = -1
func init() {
_ = SystemMemoryGB()
}
func SystemMemoryGB() int {
if systemTotalMemory > 0 {
return systemTotalMemory
}
stat, err := mem.VirtualMemory()
if err != nil {
return 0
}
systemTotalMemory = int(stat.Total / 1024 / 1024 / 1024)
return systemTotalMemory
}