From dbfc916273396f14eb09def1153739e79ed947d9 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 20 Mar 2020 00:14:43 -0700 Subject: [PATCH] derp: add short queues between reader and writer, drop on overload. This avoids the server blocking on misbehaving or heavily contended clients. We attempt to drop from the head of the queue to keep overall queueing time lower. Also: - fixes server->client keepalives, which weren't happening. - removes read rate-limiter, deferring instead to kernel-level global limiter/fair queuer. Signed-off-by: David Anderson --- cmd/derper/derper.go | 5 - derp/derp_server.go | 267 ++++++++++++++++++++++++++----------------- 2 files changed, 161 insertions(+), 111 deletions(-) diff --git a/cmd/derper/derper.go b/cmd/derper/derper.go index 2854ca586..7e0561f84 100644 --- a/cmd/derper/derper.go +++ b/cmd/derper/derper.go @@ -40,7 +40,6 @@ var ( configPath = flag.String("c", "", "config file path") certDir = flag.String("certdir", tsweb.DefaultCertDir("derper-certs"), "directory to store LetsEncrypt certs, if addr's port is :443") hostname = flag.String("hostname", "derp.tailscale.com", "LetsEncrypt host name, if addr's port is :443") - mbps = flag.Int("mbps", 5, "Mbps (mebibit/s) per-client rate limit; 0 means unlimited") logCollection = flag.String("logcollection", "", "If non-empty, logtail collection to log to") runSTUN = flag.Bool("stun", false, "also run a STUN server") ) @@ -120,9 +119,6 @@ func main() { s := derp.NewServer(key.Private(cfg.PrivateKey), log.Printf) s.WriteTimeout = 2 * time.Second - if *mbps != 0 { - s.BytesPerSecond = (*mbps << 20) / 8 - } expvar.Publish("derp", s.ExpVar()) // Create our own mux so we don't expose /debug/ stuff to the world. @@ -196,7 +192,6 @@ func debugHandler(s *derp.Server) http.Handler {