限制内存缓存最大容量为系统内存的三分之一

This commit is contained in:
GoEdgeLab
2023-10-16 14:28:07 +08:00
parent 81e5a5ca34
commit 836c92ed24
3 changed files with 24 additions and 9 deletions
+9 -1
View File
@@ -8,6 +8,7 @@ import (
)
var systemTotalMemory = -1
var systemMemoryBytes uint64
func init() {
if !teaconst.IsMain {
@@ -29,7 +30,9 @@ func SystemMemoryGB() int {
return 1
}
systemTotalMemory = int(stat.Total / (1<<30))
systemMemoryBytes = stat.Total
systemTotalMemory = int(stat.Total / (1 << 30))
if systemTotalMemory <= 0 {
systemTotalMemory = 1
}
@@ -38,3 +41,8 @@ func SystemMemoryGB() int {
return systemTotalMemory
}
// SystemMemoryBytes 系统内存总字节数
func SystemMemoryBytes() uint64 {
return systemMemoryBytes
}
+3
View File
@@ -8,4 +8,7 @@ func TestSystemMemoryGB(t *testing.T) {
t.Log(SystemMemoryGB())
t.Log(SystemMemoryGB())
t.Log(SystemMemoryGB())
t.Log(SystemMemoryBytes())
t.Log(SystemMemoryBytes())
t.Log(SystemMemoryBytes()>>30, "GB")
}