-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_cache_warm.go
More file actions
42 lines (36 loc) · 1.07 KB
/
main_cache_warm.go
File metadata and controls
42 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2024-2026 George (earentir) Pantazis (https://earentir.dev)
// SPDX-License-Identifier: GPL-2.0-only
package main
import (
"strings"
"time"
"dnsplane/data"
"github.com/miekg/dns"
)
// runCacheWarmLoop sends a periodic self-query (localhost A to 127.0.0.1) to keep the Go
// process hot (CPU caches, memory pages, goroutine scheduling). localhost is answered
// in-process (RFC 6761) and does not hit public upstreams — only the UDP receive path runs.
func runCacheWarmLoop(dnsData *data.DNSResolverData, dnsPort string) {
for {
cfg := dnsData.GetResolverSettings()
if !cfg.CacheWarmEnabled {
time.Sleep(30 * time.Second)
continue
}
interval := time.Duration(cfg.CacheWarmIntervalSeconds) * time.Second
if interval < 1*time.Second {
interval = 10 * time.Second
}
time.Sleep(interval)
port := strings.TrimSpace(dnsPort)
if port == "" {
port = "53"
}
m := new(dns.Msg)
m.SetQuestion("localhost.", dns.TypeA)
m.RecursionDesired = false
c := new(dns.Client)
c.Timeout = 1 * time.Second
_, _, _ = c.Exchange(m, "127.0.0.1:"+port)
}
}