print throughput in SI units

This commit is contained in:
Norwin Roosen 2020-12-31 17:17:24 +01:00
parent fc85b32233
commit 997fbe0d2a
No known key found for this signature in database
GPG Key ID: 24BC059DE24C43A3
1 changed files with 22 additions and 4 deletions

View File

@ -8,6 +8,11 @@ import (
"time" "time"
) )
const (
timeoutMin = 100 * time.Millisecond
timeoutMax = 10 * time.Second
)
// Performance contains pixelflut metrics // Performance contains pixelflut metrics
type Performance struct { type Performance struct {
Enabled bool Enabled bool
@ -22,7 +27,7 @@ type Performance struct {
func (p Performance) String() string { func (p Performance) String() string {
return fmt.Sprintf("%v conns\t%v\t%v/s", return fmt.Sprintf("%v conns\t%v\t%v/s",
p.Conns, fmtBytes(p.BytesTotal), fmtBytes(p.BytesPerSec)) p.Conns, fmtBytes(p.BytesTotal), fmtBit(p.BytesPerSec))
} }
// https://yourbasic.org/golang/byte-count.go // https://yourbasic.org/golang/byte-count.go
@ -40,6 +45,21 @@ func fmtBytes(b int) string {
float64(b)/float64(div), "KMGTPE"[exp]) float64(b)/float64(div), "KMGTPE"[exp])
} }
func fmtBit(b int) string {
const unit = 1000
b *= 8
if b < unit {
return fmt.Sprintf("%d b", b)
}
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %cb",
float64(b)/float64(div), "kMGTPE"[exp])
}
// PerformanceReporter provides pixelflut performance metrics, when Enabled is true. // PerformanceReporter provides pixelflut performance metrics, when Enabled is true.
// @speed: Note that enabling costs ~9% bomb performance under high throughput. // @speed: Note that enabling costs ~9% bomb performance under high throughput.
var PerformanceReporter = initPerfReporter() var PerformanceReporter = initPerfReporter()
@ -78,9 +98,7 @@ func bombAddress(message []byte, address string, maxOffsetX, maxOffsetY int, sto
wg.Add(1) wg.Add(1)
defer wg.Done() defer wg.Done()
timeoutMin := 100 * time.Millisecond timeout := timeoutMin
timeoutMax := 10 * time.Second
timeout := 200 * time.Millisecond
for { for {
conn, err := net.Dial("tcp", address) conn, err := net.Dial("tcp", address)