feat(http): accelerate connection expansion with squared batches (#1530)

This commit is contained in:
Levi authored and GitHub committed 2026-09-18 23:22:57 +08:00
1 parent 49aab4ea7c
commit 8301b1f9ce
1 file changed
+10 -2
+10 -2
View File
@@ -150,7 +150,7 @@ type slowStartController struct {
totalLaunched int
batchPending int // Connections in current batch waiting for HTTP response
batchReady int // Connections in current batch that succeeded
nextBatchSize int // Next batch size: 1, 2, 4, 8...
nextBatchSize int // Next batch size: 1, 2, 4, 16, 256... (capped)
expansionCh chan struct{} // Signal to trigger next expansion
paused bool // Pause expansion (e.g., on 429)
}
@@ -229,7 +229,15 @@ func (s *slowStartController) commitBatch(count int) {
defer s.mu.Unlock()
s.totalLaunched += count
s.nextBatchSize = s.nextBatchSize * 2 // Exponential growth: 1, 2, 4, 8...
if s.nextBatchSize == 1 {
// Bootstrap growth: squaring one would never increase the batch size.
s.nextBatchSize = min(2, s.maxConnections)
} else if s.nextBatchSize > s.maxConnections/s.nextBatchSize {
// Cap before multiplying to avoid integer overflow.
s.nextBatchSize = s.maxConnections
} else {
s.nextBatchSize *= s.nextBatchSize
}
s.batchPending = count
s.batchReady = 0
}