perf: optimize throughput and scheduler efficency

This commit is contained in:
xboard
2026-03-23 14:46:43 +08:00
parent 4f1f41aa5d
commit e8e2abbc37
4 changed files with 135 additions and 46 deletions
+10 -1
View File
@@ -10,6 +10,7 @@ import (
"log/slog"
"math"
"sort"
"sync/atomic"
"time"
"github.com/cedar2025/xboard-node/internal/cert"
@@ -45,6 +46,8 @@ type Service struct {
pushInterval int // seconds
pullInterval int // seconds
trackRunning atomic.Bool // prevents concurrent trackAndEnforce goroutines
lastUserHash string // hash of user list for change detection
lastConfigHash string // hash of full config for change detection
pullBackoff apiBackoff // backoff for panel pull failures
@@ -166,7 +169,12 @@ func (s *Service) Run(ctx context.Context) error {
return nil
case <-trackTicker.C:
s.trackAndEnforce(ctx)
if s.trackRunning.CompareAndSwap(false, true) {
go func() {
defer s.trackRunning.Store(false)
s.trackAndEnforce(ctx)
}()
}
case <-reportTicker.C:
s.pushReport()
@@ -762,6 +770,7 @@ func (s *Service) trackAndEnforce(ctx context.Context) {
slog.Debug("get connections failed", "error", err)
return
}
defer kernel.ReleaseConnectionSlice(conns)
s.tracker.Process(conns)
s.tracker.LogStats()