feat: introduce theme management and performance improvements (#7)
This commit is contained in:
@@ -2,12 +2,16 @@ package resolver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var debugTiming = os.Getenv("SNITCH_DEBUG_TIMING") != ""
|
||||
|
||||
// Resolver handles DNS and service name resolution with caching and timeouts
|
||||
type Resolver struct {
|
||||
timeout time.Duration
|
||||
@@ -41,6 +45,7 @@ func (r *Resolver) ResolveAddr(addr string) string {
|
||||
}
|
||||
|
||||
// Perform resolution with timeout
|
||||
start := time.Now()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -55,6 +60,11 @@ func (r *Resolver) ResolveAddr(addr string) string {
|
||||
}
|
||||
}
|
||||
|
||||
elapsed := time.Since(start)
|
||||
if debugTiming && elapsed > 50*time.Millisecond {
|
||||
fmt.Fprintf(os.Stderr, "[timing] slow DNS lookup: %s -> %s (%v)\n", addr, resolved, elapsed)
|
||||
}
|
||||
|
||||
// Cache the result
|
||||
r.mutex.Lock()
|
||||
r.cache[addr] = resolved
|
||||
|
||||
Reference in New Issue
Block a user