mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-08 20:24:56 +03:00
Update sing-box core, refactor MASQUE, update XHTTP
This commit is contained in:
@@ -96,6 +96,7 @@ func (s *Service) Start(stage adapter.StartStage) error {
|
||||
|
||||
if s.hasTimerMode {
|
||||
s.adaptiveTimer = newAdaptiveTimer(s.logger, s.router, s.timerConfig)
|
||||
s.adaptiveTimer.start(false)
|
||||
if s.memoryLimit > 0 {
|
||||
s.logger.Info("started memory monitor with limit: ", s.memoryLimit/(1024*1024), " MiB")
|
||||
} else {
|
||||
@@ -164,7 +165,7 @@ func goMemoryPressureCallback(status C.ulong) {
|
||||
if isCritical {
|
||||
s.logger.Warn("memory pressure: ", level, ", usage: ", usage/(1024*1024), " MiB")
|
||||
if s.adaptiveTimer != nil {
|
||||
s.adaptiveTimer.startNow()
|
||||
s.adaptiveTimer.start(true)
|
||||
}
|
||||
} else if isWarning {
|
||||
s.logger.Warn("memory pressure: ", level, ", usage: ", usage/(1024*1024), " MiB")
|
||||
|
||||
@@ -64,7 +64,7 @@ func (s *Service) Start(stage adapter.StartStage) error {
|
||||
return E.New("memory pressure monitoring is not available on this platform without memory_limit")
|
||||
}
|
||||
s.adaptiveTimer = newAdaptiveTimer(s.logger, s.router, s.timerConfig)
|
||||
s.adaptiveTimer.start(0)
|
||||
s.adaptiveTimer.start(false)
|
||||
if s.useAvailable {
|
||||
s.logger.Info("started memory monitor with available memory detection")
|
||||
} else {
|
||||
|
||||
@@ -55,17 +55,13 @@ func newAdaptiveTimer(logger log.ContextLogger, router adapter.Router, config ti
|
||||
}
|
||||
}
|
||||
|
||||
func (t *adaptiveTimer) start(_ uint64) {
|
||||
t.access.Lock()
|
||||
defer t.access.Unlock()
|
||||
t.startLocked()
|
||||
}
|
||||
|
||||
func (t *adaptiveTimer) startNow() {
|
||||
func (t *adaptiveTimer) start(immediate bool) {
|
||||
t.access.Lock()
|
||||
t.startLocked()
|
||||
t.access.Unlock()
|
||||
t.poll()
|
||||
if immediate {
|
||||
t.poll()
|
||||
}
|
||||
}
|
||||
|
||||
func (t *adaptiveTimer) startLocked() {
|
||||
@@ -90,12 +86,6 @@ func (t *adaptiveTimer) stopLocked() {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *adaptiveTimer) running() bool {
|
||||
t.access.Lock()
|
||||
defer t.access.Unlock()
|
||||
return t.timer != nil
|
||||
}
|
||||
|
||||
func (t *adaptiveTimer) poll() {
|
||||
t.access.Lock()
|
||||
defer t.access.Unlock()
|
||||
@@ -144,13 +134,8 @@ func (t *adaptiveTimer) poll() {
|
||||
interval = t.maxInterval
|
||||
} else {
|
||||
timeToLimit := time.Duration(float64(remaining) / float64(delta) * float64(t.lastInterval))
|
||||
interval = timeToLimit / time.Duration(t.checksBeforeLimit)
|
||||
if interval < t.minInterval {
|
||||
interval = t.minInterval
|
||||
}
|
||||
if interval > t.maxInterval {
|
||||
interval = t.maxInterval
|
||||
}
|
||||
interval = max(timeToLimit/time.Duration(t.checksBeforeLimit), t.minInterval)
|
||||
interval = min(interval, t.maxInterval)
|
||||
}
|
||||
|
||||
t.lastInterval = interval
|
||||
|
||||
Reference in New Issue
Block a user