From ceb89917f9a78deae8e87fe8ec21013cace67225 Mon Sep 17 00:00:00 2001 From: xtaci Date: Mon, 25 Mar 2019 11:51:21 +0800 Subject: [PATCH] allow access to `-smuxbuf` parameter for handling HOLB --- README.md | 3 +++ build/build-release.sh | 1 - client/config.go | 1 + client/main.go | 9 ++++++++- go.mod | 8 ++++---- go.sum | 8 ++++++++ server/config.go | 1 + server/main.go | 9 ++++++++- 8 files changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 37be22502..fc191f6c1 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,10 @@ All precompiled releases are genereated from `build-release.sh` script. > *fast3 > fast2 > fast > normal > default* +#### HOLB +Since streams are multiplexed into a single physical channel, head of line blocking may appear under certain circumstances, by +increasing `-smuxbuf` to a larger value (default 4MB) may mitigate this problem, obviously this will costs more memory. ### Expert Tuning Guide diff --git a/build/build-release.sh b/build/build-release.sh index 90c24db5a..a375c8f6a 100755 --- a/build/build-release.sh +++ b/build/build-release.sh @@ -1,5 +1,4 @@ #!/bin/bash -export GO111MODULE=on sum="sha1sum" if ! hash sha1sum 2>/dev/null; then diff --git a/client/config.go b/client/config.go index 6d9fb5e95..a5d3ed4bc 100644 --- a/client/config.go +++ b/client/config.go @@ -28,6 +28,7 @@ type Config struct { Resend int `json:"resend"` NoCongestion int `json:"nc"` SockBuf int `json:"sockbuf"` + SmuxBuf int `json:"smuxbuf"` KeepAlive int `json:"keepalive"` Log string `json:"log"` SnmpLog string `json:"snmplog"` diff --git a/client/main.go b/client/main.go index 756cd2562..1cc2c57d3 100644 --- a/client/main.go +++ b/client/main.go @@ -209,6 +209,11 @@ func main() { Value: 4194304, // socket buffer size in bytes Usage: "per-socket buffer in bytes", }, + cli.IntFlag{ + Name: "smuxbuf", + Value: 4194304, + Usage: "the overall de-mux buffer in bytes", + }, cli.IntFlag{ Name: "keepalive", Value: 10, // nat keepalive interval in seconds @@ -262,6 +267,7 @@ func main() { config.Resend = c.Int("resend") config.NoCongestion = c.Int("nc") config.SockBuf = c.Int("sockbuf") + config.SmuxBuf = c.Int("smuxbuf") config.KeepAlive = c.Int("keepalive") config.Log = c.String("log") config.SnmpLog = c.String("snmplog") @@ -342,6 +348,7 @@ func main() { log.Println("acknodelay:", config.AckNodelay) log.Println("dscp:", config.DSCP) log.Println("sockbuf:", config.SockBuf) + log.Println("smuxbuf:", config.SmuxBuf) log.Println("keepalive:", config.KeepAlive) log.Println("conn:", config.Conn) log.Println("autoexpire:", config.AutoExpire) @@ -351,7 +358,7 @@ func main() { log.Println("quiet:", config.Quiet) smuxConfig := smux.DefaultConfig() - smuxConfig.MaxReceiveBuffer = config.SockBuf + smuxConfig.MaxReceiveBuffer = config.SmuxBuf smuxConfig.KeepAliveInterval = time.Duration(config.KeepAlive) * time.Second createConn := func() (*smux.Session, error) { diff --git a/go.mod b/go.mod index 9ab22fa87..51b453ddc 100644 --- a/go.mod +++ b/go.mod @@ -9,9 +9,9 @@ require ( github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b // indirect github.com/tjfoc/gmsm v1.0.1 // indirect github.com/urfave/cli v1.20.0 - github.com/xtaci/kcp-go v5.1.2+incompatible - github.com/xtaci/smux v1.1.1 + github.com/xtaci/kcp-go v5.1.3+incompatible + github.com/xtaci/smux v1.1.2 golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576 - golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53 // indirect - golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54 // indirect + golang.org/x/net v0.0.0-20190324223953-e3b2ff56ed87 // indirect + golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc // indirect ) diff --git a/go.sum b/go.sum index a81fcedc7..3d2bd71e5 100644 --- a/go.sum +++ b/go.sum @@ -17,14 +17,22 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/xtaci/kcp-go v5.0.7+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= github.com/xtaci/kcp-go v5.1.1+incompatible h1:A6zXUGblo98vosfEdaHcy0cTBZKY2dByJxICuaV+L5g= github.com/xtaci/kcp-go v5.1.1+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= +github.com/xtaci/kcp-go v5.1.2+incompatible h1:UafCgw2Yk3QOf8MRm8jYEWJt1l4J61BgLpMsROkJQxo= github.com/xtaci/kcp-go v5.1.2+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= +github.com/xtaci/kcp-go v5.1.3+incompatible h1:s96+ulBrZlxk4DPRPgEGPBV8o55kYKKFVivDwVgZNcA= +github.com/xtaci/kcp-go v5.1.3+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE= github.com/xtaci/smux v1.1.1 h1:ZyIo9XHuHkAeENzHR8yGWC+6xUSCTeP2tPTRE8mnLvc= github.com/xtaci/smux v1.1.1/go.mod h1:f+nYm6SpuHMy/SH0zpbvAFHT1QoMcgLOsWcFip5KfPw= +github.com/xtaci/smux v1.1.2 h1:AeAzHKqvDeFEcicL9Q06LTjIVW2I55iooUbpDRGHth4= +github.com/xtaci/smux v1.1.2/go.mod h1:f+nYm6SpuHMy/SH0zpbvAFHT1QoMcgLOsWcFip5KfPw= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576 h1:aUX/1G2gFSs4AsJJg2cL3HuoRhCSCz733FE5GUSuaT4= golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53 h1:kcXqo9vE6fsZY5X5Rd7R1l7fTgnWaDCVmln65REefiE= golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190324223953-e3b2ff56ed87 h1:yh5/K199RObPR6zqVBYf+AyJuweAqx+fOe9s3cekn1Y= +golang.org/x/net v0.0.0-20190324223953-e3b2ff56ed87/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/server/config.go b/server/config.go index 361c1673b..b3c7ea64c 100644 --- a/server/config.go +++ b/server/config.go @@ -25,6 +25,7 @@ type Config struct { Resend int `json:"resend"` NoCongestion int `json:"nc"` SockBuf int `json:"sockbuf"` + SmuxBuf int `json:"smuxbuf"` KeepAlive int `json:"keepalive"` Log string `json:"log"` SnmpLog string `json:"snmplog"` diff --git a/server/main.go b/server/main.go index db2b8ca72..70ed785b0 100644 --- a/server/main.go +++ b/server/main.go @@ -62,7 +62,7 @@ func newCompStream(conn net.Conn) *compStream { func handleMux(conn io.ReadWriteCloser, config *Config) { // stream multiplex smuxConfig := smux.DefaultConfig() - smuxConfig.MaxReceiveBuffer = config.SockBuf + smuxConfig.MaxReceiveBuffer = config.SmuxBuf smuxConfig.KeepAliveInterval = time.Duration(config.KeepAlive) * time.Second mux, err := smux.Server(conn, smuxConfig) @@ -219,6 +219,11 @@ func main() { Value: 4194304, // socket buffer size in bytes Usage: "per-socket buffer in bytes", }, + cli.IntFlag{ + Name: "smuxbuf", + Value: 4194304, + Usage: "the overall de-mux buffer in bytes", + }, cli.IntFlag{ Name: "keepalive", Value: 10, // nat keepalive interval in seconds @@ -273,6 +278,7 @@ func main() { config.Resend = c.Int("resend") config.NoCongestion = c.Int("nc") config.SockBuf = c.Int("sockbuf") + config.SmuxBuf = c.Int("smuxbuf") config.KeepAlive = c.Int("keepalive") config.Log = c.String("log") config.SnmpLog = c.String("snmplog") @@ -352,6 +358,7 @@ func main() { log.Println("acknodelay:", config.AckNodelay) log.Println("dscp:", config.DSCP) log.Println("sockbuf:", config.SockBuf) + log.Println("smuxbuf:", config.SmuxBuf) log.Println("keepalive:", config.KeepAlive) log.Println("snmplog:", config.SnmpLog) log.Println("snmpperiod:", config.SnmpPeriod)