Skip to content

Commit b57c95e

Browse files
committed
based on Release v2026.04.04.210334-f62330c
1 parent de83032 commit b57c95e

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

internal/udpserver/deferred_session.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ type deferredSessionProcessor struct {
4646
nextWorker int
4747
}
4848

49+
func deriveDeferredSessionPendingCap(workerCount int, queueLimit int) int32 {
50+
if workerCount <= 0 {
51+
workerCount = 1
52+
}
53+
54+
if queueLimit < 1 {
55+
queueLimit = 256
56+
}
57+
58+
// Keep the per-session cap comfortably below the total queue budget, but
59+
// large enough that one busy session does not trip overflow logs long before
60+
// the processor itself is under real pressure.
61+
capGuess := min(max(queueLimit/2, 32), 1024)
62+
63+
totalCapacity := workerCount * queueLimit
64+
if capGuess > totalCapacity {
65+
capGuess = totalCapacity
66+
}
67+
68+
if capGuess < 8 {
69+
capGuess = 8
70+
}
71+
72+
return int32(capGuess)
73+
}
74+
4975
func newDeferredSessionProcessor(workerCount int, queueLimit int, log *logger.Logger) *deferredSessionProcessor {
5076
if workerCount <= 0 {
5177
return nil
@@ -72,7 +98,7 @@ func newDeferredSessionProcessor(workerCount int, queueLimit int, log *logger.Lo
7298
cancelled: make(map[deferredSessionLane]struct{}, 128),
7399
running: make(map[deferredSessionLane]context.CancelFunc, 128),
74100
sessionPending: make(map[uint8]int32, 64),
75-
sessionPendingCap: int32(max(8, workerCount*4)),
101+
sessionPendingCap: deriveDeferredSessionPendingCap(workerCount, queueLimit),
76102
}
77103
}
78104

internal/udpserver/stream_syn_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,17 @@ func TestDeferredSessionProcessorSessionCapRejectsExcessSingleSessionLoad(t *tes
625625
}
626626
}
627627

628+
func TestDeferredSessionProcessorSessionCapScalesForDNSSizedQueue(t *testing.T) {
629+
processor := newDeferredSessionProcessor(1, 256, nil)
630+
if processor == nil {
631+
t.Fatal("expected deferred processor")
632+
}
633+
634+
if got := processor.sessionCap(); got != 128 {
635+
t.Fatalf("expected dns-sized deferred session cap of 128, got %d", got)
636+
}
637+
}
638+
628639
func TestDeferredSessionProcessorFastFailsWhenWorkerQueueIsFull(t *testing.T) {
629640
processor := newDeferredSessionProcessor(1, 1, nil)
630641
if processor == nil {

0 commit comments

Comments
 (0)