114 lines
2.7 KiB
Go
114 lines
2.7 KiB
Go
package resolver
|
|
|
|
func ComputeNextLiveBatchTarget(current, minV, maxV int, dnsStats DNSMetrics, deferred int) (int, string) {
|
|
if current < minV {
|
|
current = minV
|
|
}
|
|
if current > maxV {
|
|
current = maxV
|
|
}
|
|
next := current
|
|
reason := "stable"
|
|
attempts := dnsStats.Attempts
|
|
timeoutRate := 0.0
|
|
if attempts > 0 {
|
|
timeoutRate = float64(dnsStats.Timeout) / float64(attempts)
|
|
}
|
|
|
|
switch {
|
|
case attempts == 0:
|
|
reason = "no_dns_attempts"
|
|
case dnsStats.Skipped > 0 || timeoutRate >= 0.15:
|
|
next = int(float64(current) * 0.75)
|
|
reason = "timeout_high_or_cooldown"
|
|
case timeoutRate >= 0.08:
|
|
next = int(float64(current) * 0.90)
|
|
reason = "timeout_medium"
|
|
case timeoutRate <= 0.03 && deferred > 0:
|
|
next = int(float64(current) * 1.15)
|
|
reason = "timeout_low_expand"
|
|
case timeoutRate <= 0.03:
|
|
next = int(float64(current) * 1.10)
|
|
reason = "timeout_low"
|
|
}
|
|
|
|
if next < minV {
|
|
next = minV
|
|
}
|
|
if next > maxV {
|
|
next = maxV
|
|
}
|
|
if next == current && reason == "timeout_low" {
|
|
reason = "stable"
|
|
}
|
|
return next, reason
|
|
}
|
|
|
|
func ComputeNextLiveBatchNXHeavyPct(
|
|
current, minV, maxV int,
|
|
dnsStats DNSMetrics,
|
|
resolvedNowDNS int,
|
|
selectedP3 int,
|
|
nxTotal int,
|
|
liveNXHeavySkip int,
|
|
) (int, string) {
|
|
if current < minV {
|
|
current = minV
|
|
}
|
|
if current > maxV {
|
|
current = maxV
|
|
}
|
|
next := current
|
|
reason := "stable"
|
|
|
|
attempts := dnsStats.Attempts
|
|
timeoutRate := 0.0
|
|
okRate := 0.0
|
|
nxRate := 0.0
|
|
if attempts > 0 {
|
|
timeoutRate = float64(dnsStats.Timeout) / float64(attempts)
|
|
okRate = float64(dnsStats.OK) / float64(attempts)
|
|
nxRate = float64(dnsStats.NXDomain) / float64(attempts)
|
|
}
|
|
nxSelectedRatio := 0.0
|
|
if nxTotal > 0 {
|
|
nxSelectedRatio = float64(selectedP3) / float64(nxTotal)
|
|
}
|
|
|
|
switch {
|
|
case attempts == 0:
|
|
reason = "no_dns_attempts"
|
|
case timeoutRate >= 0.20 || dnsStats.Skipped > 0:
|
|
next = current - 3
|
|
reason = "timeout_very_high_or_cooldown"
|
|
case timeoutRate >= 0.12:
|
|
next = current - 2
|
|
reason = "timeout_high"
|
|
case dnsStats.OK == 0 && dnsStats.NXDomain > 0:
|
|
next = current - 2
|
|
reason = "no_success_nx_only"
|
|
case nxRate >= 0.90 && resolvedNowDNS == 0:
|
|
next = current - 2
|
|
reason = "nx_dominant_no_resolve"
|
|
case nxSelectedRatio >= 0.95 && resolvedNowDNS == 0:
|
|
next = current - 1
|
|
reason = "nxheavy_selected_dominant"
|
|
case timeoutRate <= 0.02 && okRate >= 0.10 && liveNXHeavySkip > 0:
|
|
next = current + 2
|
|
reason = "healthy_fast_reintroduce_nxheavy"
|
|
case timeoutRate <= 0.04 && resolvedNowDNS > 0 && liveNXHeavySkip > 0:
|
|
next = current + 1
|
|
reason = "healthy_reintroduce_nxheavy"
|
|
}
|
|
if next < minV {
|
|
next = minV
|
|
}
|
|
if next > maxV {
|
|
next = maxV
|
|
}
|
|
if next == current && reason != "no_dns_attempts" {
|
|
reason = "stable"
|
|
}
|
|
return next, reason
|
|
}
|