feat(tcp, udp): implement stream state release after verdict and adjust flush interval logic
This commit is contained in:
+11
-2
@@ -20,9 +20,18 @@ const (
|
||||
defaultTCPTimeout = 10 * time.Minute
|
||||
defaultUDPMaxStreams = 4096
|
||||
|
||||
tcpFlushInterval = 1 * time.Minute
|
||||
// 超时 flush 的间隔范围。判定后的流走 connmark 旁路,FIN 到不了用户态,
|
||||
// 只能靠定时 flush 把它们从连接池里清掉。间隔取超时的一半:
|
||||
// 之前固定 1 分钟,30 秒的超时实际会让流在池里活到 90 秒。
|
||||
tcpMaxFlushInterval = 1 * time.Minute
|
||||
tcpMinFlushInterval = 1 * time.Second
|
||||
)
|
||||
|
||||
// tcpFlushIntervalFor 返回给定 TCP 超时下的 flush 间隔
|
||||
func tcpFlushIntervalFor(timeout time.Duration) time.Duration {
|
||||
return min(tcpMaxFlushInterval, max(timeout/2, tcpMinFlushInterval))
|
||||
}
|
||||
|
||||
type workerPacket struct {
|
||||
StreamID uint32
|
||||
Packet gopacket.Packet
|
||||
@@ -122,7 +131,7 @@ func (w *worker) Run(ctx context.Context) {
|
||||
w.logger.WorkerStart(w.id)
|
||||
defer w.logger.WorkerStop(w.id)
|
||||
|
||||
tcpFlushTicker := time.NewTicker(tcpFlushInterval)
|
||||
tcpFlushTicker := time.NewTicker(tcpFlushIntervalFor(w.tcpTimeout))
|
||||
defer tcpFlushTicker.Stop()
|
||||
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user