From 4bda1db8399af2743f88be0ddb0761dfa89f2853 Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Fri, 17 Aug 2018 01:40:20 +0930 Subject: [PATCH] Improve documentation of maxWorkersCount const (#726) While I'm here, rename it to maxIdleWorkersCount so it's purpose is clearer. Updates #722 Updates #725 --- server.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server.go b/server.go index 7284f1a7..575c657d 100644 --- a/server.go +++ b/server.go @@ -16,11 +16,18 @@ import ( // Default maximum number of TCP queries before we close the socket. const maxTCPQueries = 128 -// Interval for stop worker if no load -const idleWorkerTimeout = 10 * time.Second +// The maximum number of idle workers. +// +// This controls the maximum number of workers that are allowed to stay +// idle waiting for incoming requests before being torn down. +// +// If this limit is reached, the server will just keep spawning new +// workers (goroutines) for each incoming request. In this case, each +// worker will only be used for a single request. +const maxIdleWorkersCount = 10000 -// Maximum number of workers -const maxWorkersCount = 10000 +// The maximum length of time a worker may idle for before being destroyed. +const idleWorkerTimeout = 10 * time.Second // Handler is implemented by any value that implements ServeDNS. type Handler interface { @@ -327,7 +334,7 @@ func (srv *Server) worker(w *response) { for { count := atomic.LoadInt32(&srv.workersCount) - if count > maxWorkersCount { + if count > maxIdleWorkersCount { return } if atomic.CompareAndSwapInt32(&srv.workersCount, count, count+1) {