Skip to content

Commit

Permalink
[usm] reliability, http, simplify BenchmarkHTTPStatkeeperWithPool/NoP…
Browse files Browse the repository at this point in the history
…ool.
  • Loading branch information
yuri-lipnesh committed Dec 10, 2024
1 parent d6b8218 commit 2e05247
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
10 changes: 6 additions & 4 deletions pkg/network/protocols/http/statkeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
}
}
46 changes: 11 additions & 35 deletions pkg/network/protocols/http/statkeeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/network/protocols/http/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2e05247

Please sign in to comment.