Skip to content

Commit 9af397d

Browse files
committed
Reduce default TimeoutLoadReduction , use a quartic curve
1 parent 1e03995 commit 9af397d

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

dnscrypt-proxy/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func newConfig() Config {
148148
SourceDoH: true,
149149
SourceODoH: false,
150150
MaxClients: 250,
151-
TimeoutLoadReduction: 0.5,
151+
TimeoutLoadReduction: 0.4,
152152
BootstrapResolvers: []string{DefaultBootstrapResolver},
153153
IgnoreSystemDNS: false,
154154
LogMaxSize: 10,

dnscrypt-proxy/config_loader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ func configureServerParams(proxy *Proxy, config *Config) {
173173
proxy.maxClients = config.MaxClients
174174
proxy.timeoutLoadReduction = config.TimeoutLoadReduction
175175
if proxy.timeoutLoadReduction < 0.0 || proxy.timeoutLoadReduction > 1.0 {
176-
dlog.Warnf("timeout_load_reduction must be between 0.0 and 1.0, using default 0.5")
177-
proxy.timeoutLoadReduction = 0.5
176+
dlog.Warnf("timeout_load_reduction must be between 0.0 and 1.0, using default 0.4")
177+
proxy.timeoutLoadReduction = 0.4
178178
}
179179
proxy.mainProto = "udp"
180180
if config.ForceTCP {

dnscrypt-proxy/example-dnscrypt-proxy.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,15 @@ keepalive = 30
196196
## Dynamically reduce query timeout as the number of concurrent connections
197197
## approaches max_clients to prevent overload. Value must be between 0.0 and 1.0.
198198
## 0.0 = no reduction, 1.0 = maximum reduction.
199-
## For example, with timeout=5000ms, max_clients=250, and timeout_load_reduction=0.5:
200-
## - At 125 connections (50% load): timeout remains ~5000ms
201-
## - At 187 connections (75% load): timeout reduces to ~3750ms
202-
## - At 225 connections (90% load): timeout reduces to ~2500ms
199+
## Uses a quartic curve to keep timeout high at low load and reduce sharply near limit.
200+
## For example, with timeout=5000ms, max_clients=250, and timeout_load_reduction=0.4:
201+
## - At 125 connections (50% load): timeout remains ~4875ms (97.5%)
202+
## - At 187 connections (75% load): timeout reduces to ~4373ms (87.5%)
203+
## - At 225 connections (90% load): timeout reduces to ~3687ms (73.7%)
204+
## - At 250 connections (100% load): timeout reduces to ~3000ms (60%)
203205
## This helps maintain responsiveness under high load by failing fast.
204206

205-
# timeout_load_reduction = 0.5
207+
# timeout_load_reduction = 0.4
206208

207209
## Set to `true` to enable hot reloading of configuration files (like allowed-names.txt,
208210
## blocked-names.txt, etc.) when they are modified. This can increase CPU and memory usage.

dnscrypt-proxy/proxy.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,9 @@ func (proxy *Proxy) getDynamicTimeout() time.Duration {
696696
currentClients := atomic.LoadUint32(&proxy.clientsCount)
697697
utilization := float64(currentClients) / float64(proxy.maxClients)
698698

699-
factor := 1.0 - (utilization * utilization * proxy.timeoutLoadReduction)
699+
// Use quartic (power 4) curve for slow decrease at low load, sharp decrease near limit
700+
utilization4 := utilization * utilization * utilization * utilization
701+
factor := 1.0 - (utilization4 * proxy.timeoutLoadReduction)
700702
if factor < 0.1 {
701703
factor = 0.1
702704
}

0 commit comments

Comments
 (0)