Browse Source

benchmark now displays 100% when finished, error tolerance now configurable

master
Tim Schuster 1 year ago
parent
commit
ead34d06d9
Signed by: Tim Schuster <mail@timschuster.info> GPG Key ID: F9E27097EFB77F61
2 changed files with 9 additions and 3 deletions
  1. 7
    3
      bench.go
  2. 2
    0
      main.go

+ 7
- 3
bench.go View File

@@ -40,20 +40,23 @@ func bench(dnsServer, target string, measurements uint16, cb ProgressCallback) (
40 40
 		DNSSECSupport: false,
41 41
 	}
42 42
 
43
-	fmt.Println("Checking DNSSEC...")
43
+	fmt.Print("Checking DNSSEC...")
44 44
 	// verify DNSSEC
45 45
 	m := new(dns.Msg)
46 46
 	m.SetEdns0(4096, true) // Set DNSSEC OK
47 47
 	m.SetQuestion("www.dnssec-failed.org.", dns.TypeA)
48 48
 	r, _, err := c.Exchange(m, dnsServer)
49 49
 	if err != nil {
50
+		fmt.Println("FAIL")
50 51
 		return nil, errors.Wrap(err, "Could not check DNSSEC")
51 52
 	}
52 53
 	if r.Rcode == dns.RcodeServerFailure {
53 54
 		result.DNSSECSupport = true
54 55
 	}
56
+	fmt.Println("OK")
55 57
 
56
-	errTolerance := 80
58
+	fmt.Println("Running benchmark...")
59
+	errTolerance := *errorTolerance
57 60
 	// execute measurements
58 61
 	var ttls = make([]time.Duration, 0)
59 62
 	for i := measurements; i > 0; i-- {
@@ -70,7 +73,7 @@ func bench(dnsServer, target string, measurements uint16, cb ProgressCallback) (
70 73
 			if errTolerance <= 0 {
71 74
 				return nil, errors.Wrap(err, "Bench Question failed")
72 75
 			}
73
-			fmt.Printf("Error (tolerance=%d): %s\n", errTolerance, err)
76
+			fmt.Printf("\nError (tolerance=%d): %s\n", errTolerance, err)
74 77
 			errTolerance--
75 78
 			ttl = time.Second
76 79
 		} else {
@@ -80,6 +83,7 @@ func bench(dnsServer, target string, measurements uint16, cb ProgressCallback) (
80 83
 		}
81 84
 		ttls = append(ttls, ttl)
82 85
 	}
86
+	cb(measurements, measurements)
83 87
 
84 88
 	sort.Slice(ttls, func(i, j int) bool {
85 89
 		return ttls[i].Nanoseconds() < ttls[j].Nanoseconds()

+ 2
- 0
main.go View File

@@ -14,6 +14,7 @@ var (
14 14
 	dnsServers       = kingpin.Arg("dns servers", "DNS Servers to ping").Default("127.0.0.1", "8.8.8.8").Strings()
15 15
 	sleepTimeout     = kingpin.Flag("wait-request", "Time to wait between requests in milliseconds").Default("100").Uint()
16 16
 	antiCache        = kingpin.Flag("anti-cache", "Prepend randomized subdomains to query to prevent some caching. THIS REQUIRES A WILDCARD DNS ENTRY!").Default("false").Bool()
17
+	errorTolerance   = kingpin.Flag("error-tolerance", "Number of errors that may occur per server before the test is aborted").Short('z').Default("80").Int()
17 18
 )
18 19
 
19 20
 func main() {
@@ -28,6 +29,7 @@ func main() {
28 29
 			fmt.Printf("Error: %s\n", err)
29 30
 			return
30 31
 		}
32
+		bar.Show()
31 33
 		fmt.Printf("\n"+
32 34
 			"\tP00.5  = % 6.3fms\n"+
33 35
 			"\tP05.0  = % 6.3fms\n"+

Loading…
Cancel
Save