mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-30 06:57:14 +00:00
perf: prevent cron job overlap, auto-set GOMEMLIMIT, fix tgbot userStates race
cron: SkipIfStillRunning stops a slow 5s/10s job from overlapping itself and racing the shared xrayAPI (grpc conn leak) and the StatsLastValues map (fatal concurrent map write). memlimit: auto-detect a Go soft memory limit from XUI_MEMORY_LIMIT, the cgroup limit, or system RAM (about 90 percent); opt-in pprof via XUI_PPROF. tgbot: userStates now goes through a mutex-guarded store with TTL pruning (was raced by worker-pool and delayed-delete goroutines). check_client_ip: prefilter inbounds by settings LIKE limitIp instead of loading and JSON-parsing all of them every scan. minor: prune StatsLastValues, RateLimiter.lastSent, reportedRemoteTagConflict. docker-compose: document the memory knobs.
This commit is contained in:
@@ -594,6 +594,19 @@ func (x *XrayAPI) GetTraffic() ([]*Traffic, []*ClientTraffic, error) {
|
||||
processClientTraffic(matches, value, emailTrafficMap)
|
||||
}
|
||||
}
|
||||
|
||||
// Drop delta baselines for stats that no longer exist (deleted inbounds or
|
||||
// clients), which otherwise linger until the next Xray restart. Only rebuild
|
||||
// when the map has drifted past 2x the live set, so the steady-state hot path
|
||||
// stays allocation-free.
|
||||
if n := len(resp.GetStat()); n > 0 && len(x.StatsLastValues) > 2*n {
|
||||
pruned := make(map[string]int64, n)
|
||||
for _, stat := range resp.GetStat() {
|
||||
pruned[stat.Name] = x.StatsLastValues[stat.Name]
|
||||
}
|
||||
x.StatsLastValues = pruned
|
||||
}
|
||||
|
||||
return mapToSlice(tagTrafficMap), mapToSlice(emailTrafficMap), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user