Skip to content

Commit 1ef6a23

Browse files
committed
Add -time-resolvers option for more summary
Use `-time-resolvers` to see a duration summary for each resolver, highlighting which the slow ones are. Combines nicely with `-progress`. It was adding this option (upstream) which revealed the bug fixed in the previous commit, that I hadn't switched which set of strings we iterate over when I added flag parsing.
1 parent 9b20a1c commit 1ef6a23

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/dns_cache_warm.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"math/rand"
1616
"net"
1717
"os"
18+
"sort"
1819
"strconv"
1920
"strings"
2021
"sync"
@@ -87,6 +88,7 @@ type Stats struct {
8788
unhandledCount uint32
8889
noresultsCount uint32
8990
startTime time.Time
91+
durations sync.Map
9092
}
9193

9294
func startResolver(resolverHosts []string) (rw *ResolveWrapper, err error) {
@@ -151,6 +153,7 @@ func (rw *ResolveWrapper) Wait() {
151153

152154
func oneResolverStdlib(index int, ch <-chan Item, wg *sync.WaitGroup, stats *Stats) {
153155
defer wg.Done()
156+
start := time.Now()
154157
res := &net.Resolver{}
155158
for {
156159
item, ok := <-ch
@@ -159,6 +162,7 @@ func oneResolverStdlib(index int, ch <-chan Item, wg *sync.WaitGroup, stats *Sta
159162
}
160163
resolveStdlib(index, res, item, stats)
161164
}
165+
stats.durations.Store("stdlib", time.Now().Sub(start))
162166
}
163167

164168
func adminResolver(index int, inbound <-chan Item, chList []chan<- Item, wg *sync.WaitGroup) {
@@ -181,6 +185,7 @@ func adminResolver(index int, inbound <-chan Item, chList []chan<- Item, wg *syn
181185

182186
func oneResolverPerTarget(resIndex int, ch <-chan Item, wg *sync.WaitGroup, resolverName string, stats *Stats) {
183187
defer wg.Done()
188+
start := time.Now()
184189
rc := &RecClient{
185190
client: dns.Client{
186191
Timeout: DNS_TIMEOUT,
@@ -195,6 +200,7 @@ func oneResolverPerTarget(resIndex int, ch <-chan Item, wg *sync.WaitGroup, reso
195200
}
196201
resolvePerTarget(resIndex, rc, item, stats)
197202
}
203+
stats.durations.Store(resolverName, time.Now().Sub(start))
198204
}
199205

200206
func resolveStdlib(index int, res *net.Resolver, item Item, stats *Stats) {
@@ -545,11 +551,31 @@ func (rw *ResolveWrapper) PrintSummary() {
545551
log.Printf("Summary: %v for %d requests %s, taking %d queries%s",
546552
duration, requested, targetRepr,
547553
queries, statsRepr)
554+
555+
// We actually time always, it's simpler than making the time conditional
556+
// and the overhead is low. So really it's "report that we timed".
557+
if opts.TimeResolvers {
558+
// it's servers else 1, Go has no ternary, just add 1
559+
names := make([]string, 0, servers+1)
560+
durations := make(map[string]time.Duration, servers+1)
561+
rw.stats.durations.Range(func(i, v interface{}) bool {
562+
n := i.(string)
563+
d := v.(time.Duration)
564+
names = append(names, n)
565+
durations[n] = d
566+
return true
567+
})
568+
sort.Strings(names) // do I have a convenient IPsort/HOSTsort around?
569+
for _, name := range names {
570+
log.Printf(" [%7s] %s", durations[name].Round(time.Millisecond), name)
571+
}
572+
}
548573
}
549574

550575
var opts struct {
551-
ProgressOnly bool
552-
ConfigFile string
576+
ProgressOnly bool
577+
TimeResolvers bool
578+
ConfigFile string
553579
}
554580

555581
type progressT struct {
@@ -571,6 +597,7 @@ func registerFlags() {
571597

572598
flag.BoolVar(&opts.ProgressOnly, "progress", false, "show progress & summary only")
573599
flag.BoolVar(&opts.ProgressOnly, "p", false, "show progress & summary only")
600+
flag.BoolVar(&opts.TimeResolvers, "time-resolvers", false, "show summary times per resolver")
574601
flag.StringVar(&opts.ConfigFile, "config", defaultConfig, "file with DNS entries to resolve")
575602
}
576603

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy