1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-03 06:30:42 +00:00

refine sending window size

This commit is contained in:
v2ray 2016-07-04 13:37:42 +02:00
parent 6a1054a0f3
commit 165e323fab
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 15 additions and 4 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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,
})