perf(logging): aggregate disabled-client logs in Xray config generation (#7055)

GetXrayConfig logged one INFO line for every client whose traffic row is
disabled, on every config generation: each reconcile, restart and node
traffic sync, changed or not. With a few thousand expired clients that
flooded the journal and pushed everything else out of the panel's in-memory
log buffer. The line also said "Remove Inbound User", although nothing is
removed there; the client is only left out of the config being built.

A successful generation now writes one summary with the number of excluded
client entries and affected inbounds, and a failed one writes none. The
filter and the generated config are unchanged.

Closes #7054
This commit is contained in:
Hamed
2026-11-13 22:25:21 +03:30
committed by GitHub
parent 2fab6c3d50
commit 5297fd3c84
3 changed files with 210 additions and 1 deletions
@@ -3,13 +3,60 @@ package service
import (
"encoding/json"
"fmt"
"strings"
"testing"
"time"
"github.com/mhsanaei/3x-ui/v3/internal/database"
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
"github.com/mhsanaei/3x-ui/v3/internal/logger"
"github.com/mhsanaei/3x-ui/v3/internal/xray"
)
func BenchmarkGetXrayConfigDisabledClients(b *testing.B) {
b.Setenv("XUI_LOG_FOLDER", b.TempDir())
setupScaleDB(b)
b.Cleanup(logger.CloseLogger)
seedScaleDataset(b, 2000, 5)
db := database.GetDB()
// Fix the generated credentials and lifecycle values for before/after comparisons.
if err := db.Model(&model.ClientRecord{}).Where("id > 0").
Updates(map[string]any{"uuid": "11111111-1111-1111-1111-111111111111", "expiry_time": 0}).Error; err != nil {
b.Fatal(err)
}
if err := db.Model(&model.Inbound{}).Where("id > 0").Update("settings", `{"clients":[]}`).Error; err != nil {
b.Fatal(err)
}
if err := db.Model(&xray.ClientTraffic{}).Where("id > 0").
Updates(map[string]any{"enable": false, "expiry_time": 0}).Error; err != nil {
b.Fatal(err)
}
svc := &XrayService{}
b.ReportAllocs()
b.ResetTimer()
for range b.N {
if _, err := svc.GetXrayConfig(); err != nil {
b.Fatal(err)
}
}
b.StopTimer()
const marker = "disabled-client benchmark log boundary"
logger.Info(marker)
if _, err := svc.GetXrayConfig(); err != nil {
b.Fatal(err)
}
entries, bytes := 0, 0
for _, line := range logger.GetLogs(10000, "DEBUG") {
if strings.HasSuffix(line, " INFO - "+marker) {
break
}
entries++
bytes += len(line) + 1
}
b.ReportMetric(float64(entries), "logs/op")
b.ReportMetric(float64(bytes), "buffered-log-bytes/op")
}
// TestGetXrayConfigScale measures building the full Xray config (the path
// every restart/reconcile takes) and, separately, how much of the per-inbound
// settings rebuild is spent on indented vs plain JSON marshaling.