From 2e05247c73bdb8f6c0e2ac21207110aa3c7d0b80 Mon Sep 17 00:00:00 2001 From: "yuri.lipnesh" Date: Tue, 10 Dec 2024 09:42:00 -0500 Subject: [PATCH] [usm] reliability, http, simplify BenchmarkHTTPStatkeeperWithPool/NoPool. --- pkg/network/protocols/http/statkeeper.go | 10 ++-- pkg/network/protocols/http/statkeeper_test.go | 46 +++++-------------- pkg/network/protocols/http/stats.go | 4 +- 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/pkg/network/protocols/http/statkeeper.go b/pkg/network/protocols/http/statkeeper.go index 030f49a02627d..79c36bf35a878 100644 --- a/pkg/network/protocols/http/statkeeper.go +++ b/pkg/network/protocols/http/statkeeper.go @@ -93,9 +93,11 @@ func (h *StatKeeper) GetAndResetAllStats() (stats map[Key]*RequestStats) { h.add(tx) } + // put back 'DDSketch' objects to pool + h.releaseSketchPool() + // Rotate stats stats = h.stats - h.releaseSketchPool() h.stats = make(map[Key]*RequestStats) // Rotate ConnectionAggregator @@ -228,7 +230,7 @@ func (h *StatKeeper) clearEphemeralPorts(aggregator *utils.ConnectionAggregator, } } -// newSketchPool creates new pool of DDSketch objects. +// newSketchPool creates new pool of 'DDSketch' objects. func newSketchPool() *ddsync.TypedPool[ddsketch.DDSketch] { sketchPool := ddsync.NewTypedPool(func() *ddsketch.DDSketch { sketch, err := ddsketch.NewDefaultDDSketch(RelativeAccuracy) @@ -240,9 +242,9 @@ func newSketchPool() *ddsync.TypedPool[ddsketch.DDSketch] { return sketchPool } -// releaseSketchPool put DDSketch objects to pool. +// releaseSketchPool puts 'DDSketch' objects back to pool. func (h *StatKeeper) releaseSketchPool() { for _, stats := range h.stats { - stats.PutSketches() + stats.putSketches() } } diff --git a/pkg/network/protocols/http/statkeeper_test.go b/pkg/network/protocols/http/statkeeper_test.go index 773c208d343ed..0c359d9e532ad 100644 --- a/pkg/network/protocols/http/statkeeper_test.go +++ b/pkg/network/protocols/http/statkeeper_test.go @@ -330,10 +330,7 @@ func makeStatkeeper() *StatKeeper { return NewStatkeeper(cfg, tel, NewIncompleteBuffer(cfg, tel)) } -// BenchmarkHTTPStatkeeperWithPool benchmark allocations with pool of 'DDSketch' objects -func BenchmarkHTTPStatkeeperWithPool(b *testing.B) { - sk := makeStatkeeper() - +func benchmarkHTTPStatkeeper(b *testing.B, sk *StatKeeper) { sourceIP := util.AddressFromString("1.1.1.1") sourcePort := 1234 destIP := util.AddressFromString("2.2.2.2") @@ -361,39 +358,18 @@ func BenchmarkHTTPStatkeeperWithPool(b *testing.B) { b.StopTimer() } -// BenchmarkHTTPStatkeeperNoPool benchmark allocations without pool of 'DDSketch' objects -func BenchmarkHTTPStatkeeperNoPool(b *testing.B) { +// BenchmarkHTTPStatkeeperWithPool benchmark allocations with pool of 'DDSketch' objects +func BenchmarkHTTPStatkeeperWithPool(b *testing.B) { sk := makeStatkeeper() - sk.DisableSketchPool() - sourceIP := util.AddressFromString("1.1.1.1") - sourcePort := 1234 - destIP := util.AddressFromString("2.2.2.2") - destPort := 8080 - - const numPaths = 10000 - const uniqPaths = 50 - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - sk.GetAndResetAllStats() - for p := 0; p < numPaths; p++ { - b.StopTimer() - //we use subset of unique endpoints, but those will occur over and over again like in regular target application - path := "/testpath/blablabla/dsadas/isdaasd/asdasadsadasd" + strconv.Itoa(p%uniqPaths) - //we simulate different conn tuples by increasing the port number - newSourcePort := sourcePort + (p % 30) - statusCode := (i%5 + 1) * 100 - latency := time.Duration(i%5+1) * time.Millisecond - tx := generateIPv4HTTPTransaction(sourceIP, destIP, newSourcePort, destPort, path, statusCode, latency) - b.StartTimer() - sk.Process(tx) - } - } - b.StopTimer() + benchmarkHTTPStatkeeper(b, sk) } -// DisableSketchPool disable pool of 'DDSketch' objects for testing purpose. -func (h *StatKeeper) DisableSketchPool() { - h.ddsketchPool = nil +// BenchmarkHTTPStatkeeperNoPool benchmark allocations without pool of 'DDSketch' objects +func BenchmarkHTTPStatkeeperNoPool(b *testing.B) { + sk := makeStatkeeper() + // disable pool of 'DDSketch' objects + sk.ddsketchPool = nil + + benchmarkHTTPStatkeeper(b, sk) } diff --git a/pkg/network/protocols/http/stats.go b/pkg/network/protocols/http/stats.go index a6eef775ca69d..189621a290814 100644 --- a/pkg/network/protocols/http/stats.go +++ b/pkg/network/protocols/http/stats.go @@ -249,8 +249,8 @@ func (r *RequestStats) HalfAllCounts() { } } -// PutSketches adds all obtained sketch objects to the pool. -func (r *RequestStats) PutSketches() { +// putSketches returns all obtained 'DDSketch' objects to the pool. +func (r *RequestStats) putSketches() { if r.SketchPool != nil { for _, stats := range r.Data { r.SketchPool.Put(stats.Latencies)