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:
MHSanaei
2026-06-22 02:48:58 +02:00
parent 679d2e1cca
commit 7d23a2c15b
11 changed files with 234 additions and 27 deletions
+17
View File
@@ -6,6 +6,8 @@ import (
"flag"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
@@ -49,6 +51,21 @@ func runWebServer() {
godotenv.Load()
if limit, source := sys.ApplyMemoryLimit(); limit > 0 {
logger.Infof("Go memory soft limit set to %d MiB (%s)", limit>>20, source)
} else {
logger.Info("Go memory soft limit not enforced: ", source)
}
if os.Getenv("XUI_PPROF") == "true" {
go func() {
logger.Info("pprof profiling server listening on 127.0.0.1:6060")
if err := http.ListenAndServe("127.0.0.1:6060", nil); err != nil {
logger.Warning("pprof server stopped: ", err)
}
}()
}
err := database.InitDB(config.GetDBPath())
if err != nil {
log.Fatalf("Error initializing database: %v", err)