mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-08 02:40:32 +08:00
写入和删除缓存文件时增加线程数限制
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/shirou/gopsutil/v3/load"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -37,9 +36,8 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
DiskSpeed = SpeedLow
|
||||
DiskMaxWrites int32 = 32
|
||||
DiskSpeedMB float64
|
||||
DiskSpeed = SpeedLow
|
||||
DiskSpeedMB float64
|
||||
)
|
||||
|
||||
var IsInHighLoad = false
|
||||
@@ -65,7 +63,6 @@ func init() {
|
||||
if err == nil && cache.SpeedMB > 0 {
|
||||
DiskSpeedMB = cache.SpeedMB
|
||||
DiskSpeed = cache.Speed
|
||||
calculateDiskMaxWrites()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,39 +106,6 @@ func DiskIsExtremelyFast() bool {
|
||||
return DiskSpeed == SpeedExtremelyFast
|
||||
}
|
||||
|
||||
var countWrites int32 = 0
|
||||
|
||||
func WriteReady() bool {
|
||||
if IsInExtremelyHighLoad {
|
||||
return false
|
||||
}
|
||||
|
||||
return atomic.LoadInt32(&countWrites) < DiskMaxWrites
|
||||
}
|
||||
|
||||
func WriteBegin() {
|
||||
atomic.AddInt32(&countWrites, 1)
|
||||
}
|
||||
|
||||
func WriteEnd() {
|
||||
atomic.AddInt32(&countWrites, -1)
|
||||
}
|
||||
|
||||
func calculateDiskMaxWrites() {
|
||||
switch DiskSpeed {
|
||||
case SpeedExtremelyFast:
|
||||
DiskMaxWrites = 32
|
||||
case SpeedFast:
|
||||
DiskMaxWrites = 16
|
||||
case SpeedLow:
|
||||
DiskMaxWrites = 8
|
||||
case SpeedExtremelySlow:
|
||||
DiskMaxWrites = 4
|
||||
default:
|
||||
DiskMaxWrites = 4
|
||||
}
|
||||
}
|
||||
|
||||
// WaitLoad wait system load to downgrade
|
||||
func WaitLoad(maxLoad float64, maxLoops int, delay time.Duration) {
|
||||
for i := 0; i < maxLoops; i++ {
|
||||
|
||||
Reference in New Issue
Block a user