xtaci / kcp-go

A Crypto-Secure Reliable-UDP Library for golang with FEC
MIT License
4.12k stars 737 forks source link

Bad behavior when using congestion control #141

Open nullchinchilla opened 5 years ago

nullchinchilla commented 5 years ago

When using congestion control, packets continued to be queued up far past the congestion window, all the way to the send window. This cause extreme bufferbloat when congestion control is enabled.

Pull request #140 fixes this issue.

xtaci commented 5 years ago

it's non-trivial, changes should consider corresponding notification scheme

if s.kcp.WaitSnd() < waitsnd 
nullchinchilla commented 5 years ago
// kcp update, returns interval for next calling
func (s *UDPSession) update() (interval time.Duration) {
    s.mu.Lock()
    waitsnd := s.kcp.WaitSnd()
    interval = time.Duration(s.kcp.flush(false)) * time.Millisecond
    if s.kcp.WaitSnd() < waitsnd {
        s.notifyWriteEvent()
    }
    s.uncork()
    s.mu.Unlock()
    return
}

I'm not really sure how this works. When can s.kcp.WaitSnd() < waitsnd { given the waitsnd := s.kcp.WaitSnd() above? 可以用中文回覆

xtaci commented 5 years ago

check these places : https://github.com/xtaci/kcp-go/blob/master/sess.go#L679 https://github.com/xtaci/kcp-go/blob/master/sess.go#L648 https://github.com/xtaci/kcp-go/blob/master/sess.go#L699