refine sending window size

pull/215/head
v2ray 9 years ago
parent 6a1054a0f3
commit 165e323fab
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -14,7 +14,7 @@ func (this *Config) Apply() {
effectiveConfig = *this
}
func (this *Config) GetSendingWindowSize() uint32 {
func (this *Config) GetSendingInFlightSize() uint32 {
size := this.UplinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
if size == 0 {
size = 8
@ -22,6 +22,10 @@ func (this *Config) GetSendingWindowSize() uint32 {
return size
}
func (this *Config) GetSendingWindowSize() uint32 {
return this.GetSendingInFlightSize() * 4
}
func (this *Config) GetSendingQueueSize() uint32 {
return this.WriteBuffer / this.Mtu
}

@ -16,11 +16,12 @@ type SendingWindow struct {
prev []uint32
next []uint32
inFlightSize uint32
writer SegmentWriter
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{
start: 0,
cap: size,
@ -31,6 +32,7 @@ func NewSendingWindow(size uint32, writer SegmentWriter, onPacketLoss func(bool)
next: make([]uint32, size),
writer: writer,
onPacketLoss: onPacketLoss,
inFlightSize: inFlightSize,
}
return window
}
@ -116,6 +118,7 @@ func (this *SendingWindow) Flush(current uint32, resend uint32, rto uint32) {
}
lost := false
var inFlightSize uint32
for i := this.start; ; i = this.next[i] {
segment := this.data[i]
@ -139,6 +142,10 @@ func (this *SendingWindow) Flush(current uint32, resend uint32, rto uint32) {
if needsend {
this.writer.Write(segment)
inFlightSize++
if inFlightSize >= this.inFlightSize {
break
}
}
if i == this.last {
break
@ -230,7 +237,7 @@ func NewSendingWorker(kcp *KCP) *SendingWorker {
windowSize: 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
}

@ -66,7 +66,7 @@ func TestSendingQueueClear(t *testing.T) {
func TestSendingWindow(t *testing.T) {
assert := assert.On(t)
window := NewSendingWindow(5, nil, nil)
window := NewSendingWindow(5, 5, nil, nil)
window.Push(&DataSegment{
Number: 0,
})

Loading…
Cancel
Save