summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Fifield <david@bamsoftware.com>2020-02-22 11:04:27 -0700
committerDavid Fifield <david@bamsoftware.com>2020-02-22 16:31:47 -0700
commit47312dd1eccc8456652853bd66f8ed396e9ba6ec (patch)
tree75fa9119daf33aaefc3bbc2d8aecc8b235c45f8e
parent924593615c5a8fca7e0d9b4c0fafbd143db1bb62 (diff)
Disable KCP congestion control and enable stream mode.
This is some experimenting with parameters to try and provide better performance with KCP. Without these changes, I was having trouble getting more than about 40 KB/s. (And it was something latency related, because I could run at essentially line rate if I ran a local proxy and bridge instead of relying on public ones.) Stream mode just gives kcp-go license to coalesce the payloads of adjacent packets. https://github.com/xtaci/kcp-go/blob/3bedbae3ba26dfa4356f797bc1a165f7ef9d76c0/kcp.go#L313-L337 The number of packets in flight is constrained to be the minimum of the local send window (default 32), the remote receive window (default 32), and the congestion window (uses TCP-like slow start and congestion avoidance). Or, you can disable the congestion window and then the constraint is just the minimum of the first two values. https://github.com/xtaci/kcp-go/blob/3bedbae3ba26dfa4356f797bc1a165f7ef9d76c0/kcp.go#L746-L750 I added some printf statements and saw that the congestion window seemed to be growing slowly (Seemed like linearly? though I didn't check it thoroughly. Maybe the ssthresh gets set too low?) and was usually below 10. Disabling the congestion window allows 32 packets in flight in both directions. Because we are tunnelling through channels that have their own congestion control (SCTP on the WebRTC link and TCP on the WebSocket link), we probably don't want any dynamic congestion control in this inner layer anyway.
-rw-r--r--server/server.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go
index 7db36d1..390788a 100644
--- a/server/server.go
+++ b/server/server.go
@@ -352,6 +352,16 @@ func acceptSessionsKCP(ln *kcp.Listener) error {
}
return err
}
+ // Permit coalescing the payloads of consecutive sends.
+ conn.SetStreamMode(true)
+ // Disable the dynamic congestion window (limit only by the
+ // maximum of local and remote static windows).
+ conn.SetNoDelay(
+ 0, // default nodelay
+ 0, // default interval
+ 0, // default resend
+ 1, // nc=1 => congestion window off
+ )
go func() {
defer conn.Close()
err := acceptStreamsKCP(conn)