mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-21 16:56:27 -05:00
refine sending window size
This commit is contained in:
parent
6a1054a0f3
commit
165e323fab
@ -14,7 +14,7 @@ func (this *Config) Apply() {
|
|||||||
effectiveConfig = *this
|
effectiveConfig = *this
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Config) GetSendingWindowSize() uint32 {
|
func (this *Config) GetSendingInFlightSize() uint32 {
|
||||||
size := this.UplinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
|
size := this.UplinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
size = 8
|
size = 8
|
||||||
@ -22,6 +22,10 @@ func (this *Config) GetSendingWindowSize() uint32 {
|
|||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Config) GetSendingWindowSize() uint32 {
|
||||||
|
return this.GetSendingInFlightSize() * 4
|
||||||
|
}
|
||||||
|
|
||||||
func (this *Config) GetSendingQueueSize() uint32 {
|
func (this *Config) GetSendingQueueSize() uint32 {
|
||||||
return this.WriteBuffer / this.Mtu
|
return this.WriteBuffer / this.Mtu
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,12 @@ type SendingWindow struct {
|
|||||||
prev []uint32
|
prev []uint32
|
||||||
next []uint32
|
next []uint32
|
||||||
|
|
||||||
|
inFlightSize uint32
|
||||||
writer SegmentWriter
|
writer SegmentWriter
|
||||||
onPacketLoss func(bool)
|
onPacketLoss func(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSendingWindow(size uint32, writer SegmentWriter, onPacketLoss func(bool)) *SendingWindow {
|
func NewSendingWindow(size uint32, inFlightSize uint32, writer SegmentWriter, onPacketLoss func(bool)) *SendingWindow {
|
||||||
window := &SendingWindow{
|
window := &SendingWindow{
|
||||||
start: 0,
|
start: 0,
|
||||||
cap: size,
|
cap: size,
|
||||||
@ -31,6 +32,7 @@ func NewSendingWindow(size uint32, writer SegmentWriter, onPacketLoss func(bool)
|
|||||||
next: make([]uint32, size),
|
next: make([]uint32, size),
|
||||||
writer: writer,
|
writer: writer,
|
||||||
onPacketLoss: onPacketLoss,
|
onPacketLoss: onPacketLoss,
|
||||||
|
inFlightSize: inFlightSize,
|
||||||
}
|
}
|
||||||
return window
|
return window
|
||||||
}
|
}
|
||||||
@ -116,6 +118,7 @@ func (this *SendingWindow) Flush(current uint32, resend uint32, rto uint32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lost := false
|
lost := false
|
||||||
|
var inFlightSize uint32
|
||||||
|
|
||||||
for i := this.start; ; i = this.next[i] {
|
for i := this.start; ; i = this.next[i] {
|
||||||
segment := this.data[i]
|
segment := this.data[i]
|
||||||
@ -139,6 +142,10 @@ func (this *SendingWindow) Flush(current uint32, resend uint32, rto uint32) {
|
|||||||
|
|
||||||
if needsend {
|
if needsend {
|
||||||
this.writer.Write(segment)
|
this.writer.Write(segment)
|
||||||
|
inFlightSize++
|
||||||
|
if inFlightSize >= this.inFlightSize {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if i == this.last {
|
if i == this.last {
|
||||||
break
|
break
|
||||||
@ -230,7 +237,7 @@ func NewSendingWorker(kcp *KCP) *SendingWorker {
|
|||||||
windowSize: effectiveConfig.GetSendingWindowSize(),
|
windowSize: effectiveConfig.GetSendingWindowSize(),
|
||||||
controlWindow: effectiveConfig.GetSendingWindowSize(),
|
controlWindow: effectiveConfig.GetSendingWindowSize(),
|
||||||
}
|
}
|
||||||
worker.window = NewSendingWindow(effectiveConfig.GetSendingWindowSize(), worker, worker.OnPacketLoss)
|
worker.window = NewSendingWindow(effectiveConfig.GetSendingWindowSize(), effectiveConfig.GetSendingInFlightSize(), worker, worker.OnPacketLoss)
|
||||||
return worker
|
return worker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ func TestSendingQueueClear(t *testing.T) {
|
|||||||
func TestSendingWindow(t *testing.T) {
|
func TestSendingWindow(t *testing.T) {
|
||||||
assert := assert.On(t)
|
assert := assert.On(t)
|
||||||
|
|
||||||
window := NewSendingWindow(5, nil, nil)
|
window := NewSendingWindow(5, 5, nil, nil)
|
||||||
window.Push(&DataSegment{
|
window.Push(&DataSegment{
|
||||||
Number: 0,
|
Number: 0,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user