-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ii2day <ji.li@daocloud.io>
- Loading branch information
ii2day
committed
May 23, 2023
1 parent
0a82158
commit 05a90cd
Showing
24 changed files
with
339 additions
and
1,157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2022 Authors of spidernet-io | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package loadDns | ||
|
||
import ( | ||
"github.com/miekg/dns" | ||
"time" | ||
) | ||
|
||
// We report for max 1M results. | ||
const maxRes = 1000000 | ||
|
||
type report struct { | ||
avgTotal float64 | ||
average float64 | ||
tps float64 | ||
|
||
results chan *result | ||
done chan bool | ||
total time.Duration | ||
dnsAnswer []dns.RR | ||
errorDist map[string]int | ||
lats []float32 | ||
totalCount int64 | ||
successCount int64 | ||
failedCount int64 | ||
ReplyCode map[string]int | ||
} | ||
|
||
func newReport(results chan *result) *report { | ||
return &report{ | ||
results: results, | ||
done: make(chan bool, 1), | ||
errorDist: make(map[string]int), | ||
lats: make([]float32, 0, maxRes), | ||
ReplyCode: make(map[string]int), | ||
} | ||
} | ||
|
||
func runReporter(r *report) { | ||
// Loop will continue until channel is closed | ||
for res := range r.results { | ||
r.totalCount++ | ||
if res.err != nil { | ||
r.errorDist[res.err.Error()]++ | ||
r.failedCount++ | ||
} else { | ||
r.avgTotal += res.duration.Seconds() | ||
if len(r.lats) < maxRes { | ||
r.lats = append(r.lats, float32(res.duration.Milliseconds())) | ||
} | ||
rcodeStr := dns.RcodeToString[res.msg.Rcode] | ||
r.ReplyCode[rcodeStr]++ | ||
r.successCount++ | ||
} | ||
} | ||
// Signal reporter is done. | ||
r.done <- true | ||
} | ||
|
||
func (r *report) finalize(total time.Duration) { | ||
r.total = total | ||
r.tps = float64(r.totalCount) / r.total.Seconds() | ||
r.average = r.avgTotal / float64(len(r.lats)) | ||
} |
Oops, something went wrong.