From 7c2c1ea4459e72d70c76bba207b1eb8778bae7d3 Mon Sep 17 00:00:00 2001
From: Spike Curtis <spike@coder.com>
Date: Thu, 30 May 2024 10:51:18 +0400
Subject: [PATCH] fix: increases DERP send queue length to 512 for increased
 throughput

Signed-off-by: Spike Curtis <spike@coder.com>
---
 derp/derp_server.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/derp/derp_server.go b/derp/derp_server.go
index 422ae2cfb942b..46a3be2c3c988 100644
--- a/derp/derp_server.go
+++ b/derp/derp_server.go
@@ -70,7 +70,13 @@ func init() {
 }
 
 const (
-	perClientSendQueueDepth = 32 // packets buffered for sending
+	// perClientSendQueueDepth is the number of packets to buffer for sending.
+	// CODER: We've modified this to 512, up from 32 in upstream Tailscale to improve DERP
+	// throughput.  32 is an understandable number for big, public DERP servers that Tailscale run,
+	// serving many thousands of connections, and where Tailscale is footing the bill.  In Coder's
+	// use case, we are serving hundreds to low thousands of users and the user's own company is
+	// paying the bills.  In testing, it increases DERP throughput up to 6x.
+	perClientSendQueueDepth = 512
 	writeTimeout            = 2 * time.Second
 )