mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-05 01:20:26 +08:00
将获取系统内存函数放入到utils中
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package ttlcache
|
package ttlcache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ func NewCache(opt ...OptionInterface) *Cache {
|
|||||||
var countPieces = 128
|
var countPieces = 128
|
||||||
var maxItems = 2_000_000
|
var maxItems = 2_000_000
|
||||||
|
|
||||||
var totalMemory = systemMemoryGB()
|
var totalMemory = utils.SystemMemoryGB()
|
||||||
if totalMemory < 2 {
|
if totalMemory < 2 {
|
||||||
// 我们限制内存过小的服务能够使用的数量
|
// 我们限制内存过小的服务能够使用的数量
|
||||||
maxItems = 1_000_000
|
maxItems = 1_000_000
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
package ttlcache
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
@@ -8,7 +8,11 @@ import (
|
|||||||
|
|
||||||
var systemTotalMemory = -1
|
var systemTotalMemory = -1
|
||||||
|
|
||||||
func systemMemoryGB() int {
|
func init() {
|
||||||
|
_ = SystemMemoryGB()
|
||||||
|
}
|
||||||
|
|
||||||
|
func SystemMemoryGB() int {
|
||||||
if systemTotalMemory > 0 {
|
if systemTotalMemory > 0 {
|
||||||
return systemTotalMemory
|
return systemTotalMemory
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
package ttlcache
|
package utils
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestSystemMemoryGB(t *testing.T) {
|
func TestSystemMemoryGB(t *testing.T) {
|
||||||
t.Log(systemMemoryGB())
|
t.Log(SystemMemoryGB())
|
||||||
t.Log(systemMemoryGB())
|
t.Log(SystemMemoryGB())
|
||||||
t.Log(systemMemoryGB())
|
t.Log(SystemMemoryGB())
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user