mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 10:00:24 +08:00
对于小内存(不大于2G),缩短服务统计导入数据库的时间
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
@@ -43,6 +44,12 @@ func init() {
|
|||||||
// 导入统计数据
|
// 导入统计数据
|
||||||
goman.New(func() {
|
goman.New(func() {
|
||||||
var duration = 30 * time.Minute
|
var duration = 30 * time.Minute
|
||||||
|
|
||||||
|
// 小内存的要快速处理
|
||||||
|
if utils.SystemMemoryGB() <= 2 {
|
||||||
|
duration = 15 * time.Minute
|
||||||
|
}
|
||||||
|
|
||||||
if Tea.IsTesting() {
|
if Tea.IsTesting() {
|
||||||
// 测试条件下缩短时间,以便进行观察
|
// 测试条件下缩短时间,以便进行观察
|
||||||
duration = 10 * time.Second
|
duration = 10 * time.Second
|
||||||
|
|||||||
27
internal/utils/system.go
Normal file
27
internal/utils/system.go
Normal 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
|
||||||
|
}
|
||||||
14
internal/utils/system_test.go
Normal file
14
internal/utils/system_test.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package utils_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSystemMemoryGB(t *testing.T) {
|
||||||
|
t.Log(utils.SystemMemoryGB())
|
||||||
|
t.Log(utils.SystemMemoryGB())
|
||||||
|
t.Log(utils.SystemMemoryGB())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user