mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 16:04:50 +03:00
perf(clients): batch client creation by destination node (#7367)
Group compatible client creates by destination and effective payload via the existing clients/add API. Resolve node-local inbound IDs, preserve distinct flow/address/credential payloads, bound delivery concurrency and use a shared four-second remote delivery budget after local commits.
Advance reconciliation fingerprints only for acknowledged intended settings, retaining previous-fingerprint CAS rather than stamping unrelated rebased changes. Preserve FIFO turns, node-wide barriers, dirty generations, durable delete supersession, partial and uncertain delivery recovery and downstream outcomes. Protect later reattachments in final Delete cleanup and complete Create metadata before remote delivery.
Validation: all 12 CI jobs passed on 63e70cda38 (run 46935177853). PostgreSQL logs confirm 21 ordering/grouped-create tests and prior reporter-lock, reconciliation and traffic contention gates; node E2E confirms all four version pairings. Author reports SQLite/PostgreSQL race tests, make verify and isolated full make race.
Author-reported paired PostgreSQL 18 benchmark: 11 -> 1 RPC, fixed 200 ms peer delay 11-target p95 1552.0 -> 731.9 ms, timeout probe 12.41–12.42 -> 4.41–4.50 s. Size-dependent peer cost can instead cause pending delivery (1.74 -> 4.51 s with 0.74 s recovery); four stalled nodes can defer a fifth. Monitor production convergence and pending rate. No general production latency or allocation improvement claimed.
Refs #7299
This commit is contained in:
@@ -22,6 +22,7 @@ type nodeConfigQueue struct {
|
||||
groups list.List
|
||||
reconciles int
|
||||
live int
|
||||
changed chan struct{}
|
||||
}
|
||||
|
||||
// Inbounds in the same group can push concurrently. A node-wide operation
|
||||
@@ -109,6 +110,10 @@ func (t *nodeConfigTurn) release() {
|
||||
return
|
||||
}
|
||||
q, group := t.queue, t.group
|
||||
if q.changed != nil {
|
||||
close(q.changed)
|
||||
q.changed = nil
|
||||
}
|
||||
lane := group.inbounds[t.inboundID]
|
||||
wasReady := q.groups.Front() == group.position && lane.Front() == t.position
|
||||
lane.Remove(t.position)
|
||||
@@ -136,6 +141,31 @@ func (t *nodeConfigTurn) release() {
|
||||
}
|
||||
}
|
||||
|
||||
func (q *nodeConfigQueue) changes() <-chan struct{} {
|
||||
nodeConfigDispatchMu.Lock()
|
||||
defer nodeConfigDispatchMu.Unlock()
|
||||
if q.changed == nil {
|
||||
q.changed = make(chan struct{})
|
||||
}
|
||||
return q.changed
|
||||
}
|
||||
|
||||
func (q *nodeConfigQueue) acquireLive() bool {
|
||||
nodeConfigDispatchMu.Lock()
|
||||
defer nodeConfigDispatchMu.Unlock()
|
||||
if q.live >= inboundFanoutConcurrency {
|
||||
return false
|
||||
}
|
||||
q.live++
|
||||
return true
|
||||
}
|
||||
|
||||
func (q *nodeConfigQueue) releaseLive() {
|
||||
nodeConfigDispatchMu.Lock()
|
||||
defer nodeConfigDispatchMu.Unlock()
|
||||
q.live--
|
||||
}
|
||||
|
||||
type inboundClientMutation struct {
|
||||
lock *inboundMutationLock
|
||||
turn *nodeConfigTurn
|
||||
@@ -211,19 +241,11 @@ func (m *inboundClientMutation) push(s *ClientService, rt runtime.Runtime, inbou
|
||||
return
|
||||
}
|
||||
// Conflicting turns wait without consuming a live slot.
|
||||
nodeConfigDispatchMu.Lock()
|
||||
if m.turn.queue.live >= inboundFanoutConcurrency {
|
||||
nodeConfigDispatchMu.Unlock()
|
||||
if !m.turn.queue.acquireLive() {
|
||||
s.recordClientNodePush(nodeID, true, runtime.ClientApplyResult{}, errClientNodePushBusy)
|
||||
return
|
||||
}
|
||||
m.turn.queue.live++
|
||||
nodeConfigDispatchMu.Unlock()
|
||||
defer func() {
|
||||
nodeConfigDispatchMu.Lock()
|
||||
m.turn.queue.live--
|
||||
nodeConfigDispatchMu.Unlock()
|
||||
}()
|
||||
defer m.turn.queue.releaseLive()
|
||||
ctx, cancel := nodePushContext()
|
||||
defer cancel()
|
||||
complete := false
|
||||
|
||||
Reference in New Issue
Block a user