mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-01-06 07:45:47 +08:00
执行定时任务时自动根据负载进行延后执行
This commit is contained in:
@@ -140,3 +140,13 @@ func calculateDiskMaxWrites() {
|
||||
DiskMaxWrites = 4
|
||||
}
|
||||
}
|
||||
|
||||
// WaitLoad wait system load to downgrade
|
||||
func WaitLoad(maxLoad float64, maxLoops int, delay time.Duration) {
|
||||
for i := 0; i < maxLoops; i++ {
|
||||
stat, err := load.Avg()
|
||||
if err == nil && stat.Load1 > maxLoad {
|
||||
time.Sleep(delay)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
fsutils "github.com/TeaOSLab/EdgeNode/internal/utils/fs"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWrites(t *testing.T) {
|
||||
@@ -20,6 +21,10 @@ func TestWrites(t *testing.T) {
|
||||
a.IsTrue(fsutils.WriteReady())
|
||||
}
|
||||
|
||||
func TestWaitLoad(t *testing.T) {
|
||||
fsutils.WaitLoad(100, 1, 1 * time.Minute)
|
||||
}
|
||||
|
||||
func BenchmarkWrites(b *testing.B) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
|
||||
Reference in New Issue
Block a user