cmd/swarm-bench: replace go-metrics with local statistics - #3281
cmd/swarm-bench: replace go-metrics with local statistics#3281thaJeztah wants to merge 1 commit into
Conversation
| fmt.Fprintf(w, " 1-min rate: %12.2f\n", t.Rate1()) | ||
| fmt.Fprintf(w, " 5-min rate: %12.2f\n", t.Rate5()) | ||
| fmt.Fprintf(w, " 15-min rate: %12.2f\n", t.Rate15()) |
There was a problem hiding this comment.
I can add these back if we care deeply (not sure if this utility is even used by anyone though, so kept it minimal).
There was a problem hiding this comment.
Pull request overview
This PR removes the archived github.com/rcrowley/go-metrics dependency from cmd/swarm-bench and replaces it with a local, mutex-protected statistics collector that computes basic distribution stats and percentiles using the standard library.
Changes:
- Drop
go-metricsfromgo.mod/go.sumand remove its vendored sources. - Rework
swarm-bench’sCollectorto record per-task connection latencies and compute min/max/mean/stddev/percentiles and an overall completion rate. - Simplify
Benchmarkby makingCollectora local variable inBenchmark.Runand removing the constructor/field.
Reviewed changes
Copilot reviewed 3 out of 34 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vendor/modules.txt | Remove go-metrics from vendored module list |
| vendor/github.com/rcrowley/go-metrics/writer.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/validate.sh | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/timer.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/syslog.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/sample.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/runtime.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/runtime_no_gccpufraction.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/runtime_no_cgo.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/runtime_gccpufraction.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/runtime_cgo.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/registry.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/README.md | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/opentsdb.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/metrics.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/meter.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/memory.md | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/log.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/LICENSE | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/json.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/histogram.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/healthcheck.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/graphite.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/gauge.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/gauge_float64.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/ewma.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/debug.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/counter.go | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/.travis.yml | Remove vendored go-metrics file |
| vendor/github.com/rcrowley/go-metrics/.gitignore | Remove vendored go-metrics file |
| go.sum | Remove go-metrics checksums |
| go.mod | Remove go-metrics dependency |
| cmd/swarm-bench/collector.go | Add local statistics collector implementation |
| cmd/swarm-bench/benchmark.go | Use local collector; remove Benchmark field/ctor usage |
Suppressed comments (1)
cmd/swarm-bench/benchmark.go:66
- Benchmark.Run hard-codes the final stats display unit to
time.Second, ignoringConfig.Unit. Useb.cfg.Unithere as well for consistency with periodic reports.
fmt.Printf("\n%s: Benchmark completed\n", time.Now())
collector.Stats(os.Stdout, time.Second)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3281 +/- ##
==========================================
- Coverage 14.73% 14.68% -0.05%
==========================================
Files 200 200
Lines 93077 93055 -22
==========================================
- Hits 13712 13667 -45
- Misses 78019 78047 +28
+ Partials 1346 1341 -5 🚀 New features to boost your workflow:
|
c76cedb to
a16cc47
Compare
a16cc47 to
515f1ec
Compare
515f1ec to
db84341
Compare
The go-metrics repository is archived, and swarm-bench only uses a small part of its timer implementation. Replace it with a local collector that records task startup durations and calculates count, min, max, mean, standard deviation, and percentiles using the standard library. Preserve the percentile interpolation used by go-metrics, and replace its EWMA rates with the overall task completion rate. Protect collection and snapshots with a mutex so that periodic statistics can still be reported safely while tasks are connecting. Also make Collector's zero value usable and keep it local to Benchmark.Run, removing the now-unnecessary constructor and Benchmark field. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
db84341 to
40c4014
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 34 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
cmd/swarm-bench/collector.go:51
Collectcan spin indefinitely ifAccept()starts returning a persistent error (e.g., listener closed) because it logs andcontinues without an exit path, and it also doesn't honorctxcancellation to stop collection. Consider unblockingAccept()onctx.Done()and returning onnet.ErrClosedto avoid a tight error loop during shutdown/cancellation.
conn, err := c.ln.Accept()
if err != nil {
log.G(ctx).WithError(err).Error("failure accepting connection")
continue
}
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "math" |
The go-metrics repository is archived, and swarm-bench only uses a small part of its timer implementation.
Replace it with a local collector that records task startup durations and calculates count, min, max, mean, standard deviation, and percentiles using the standard library. Preserve the percentile interpolation used by go-metrics, and replace its EWMA rates with the overall task completion rate.
Protect collection and snapshots with a mutex so that periodic statistics can still be reported safely while tasks are connecting.
Also make Collector's zero value usable and keep it local to Benchmark.Run, removing the now-unnecessary constructor and Benchmark field.
- What I did
- How I did it
- How to test it
- Description for the changelog