Browse Source

cmd/strelaysrv: Smaller, adjustable network buffer

Jakob Borg 8 years ago
parent
commit
70d121a94b
2 changed files with 9 additions and 7 deletions
  1. 8 6
      cmd/strelaysrv/main.go
  2. 1 1
      cmd/strelaysrv/session.go

+ 8 - 6
cmd/strelaysrv/main.go

@@ -64,12 +64,13 @@ var (
 
 	limitCheckTimer *time.Timer
 
-	sessionLimitBps int
-	globalLimitBps  int
-	overLimit       int32
-	descriptorLimit int64
-	sessionLimiter  *rate.Limiter
-	globalLimiter   *rate.Limiter
+	sessionLimitBps   int
+	globalLimitBps    int
+	overLimit         int32
+	descriptorLimit   int64
+	sessionLimiter    *rate.Limiter
+	globalLimiter     *rate.Limiter
+	networkBufferSize int
 
 	statusAddr       string
 	poolAddrs        string
@@ -108,6 +109,7 @@ func main() {
 	flag.IntVar(&natRenewal, "nat-renewal", 30, "NAT renewal frequency in minutes")
 	flag.IntVar(&natTimeout, "nat-timeout", 10, "NAT discovery timeout in seconds")
 	flag.BoolVar(&pprofEnabled, "pprof", false, "Enable the built in profiling on the status server")
+	flag.IntVar(&networkBufferSize, "network-buffer", 2048, "Network buffer size (two of these per proxied connection)")
 	flag.Parse()
 
 	if extAddress == "" {

+ 1 - 1
cmd/strelaysrv/session.go

@@ -254,7 +254,7 @@ func (s *session) proxy(c1, c2 net.Conn) error {
 	atomic.AddInt64(&numProxies, 1)
 	defer atomic.AddInt64(&numProxies, -1)
 
-	buf := make([]byte, 65536)
+	buf := make([]byte, networkBufferSize)
 	for {
 		c1.SetReadDeadline(time.Now().Add(networkTimeout))
 		n, err := c1.Read(buf)