perf(clients): batch client creation by destination node

Group compatible committed adds into the existing multi-inbound request. Keep lane ordering, preserve target-specific payloads, and bound remote delivery across the create so unavailable nodes can converge through reconciliation.
This commit is contained in:
Hamed Sanaei
2026-12-02 20:08:47 +03:30
parent 32e4b8bcfe
commit da015758c0
11 changed files with 610 additions and 45 deletions
+32 -10
View File
@@ -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