Skip to content

Commit

Permalink
Add parallel test on ptpool (#131)
Browse files Browse the repository at this point in the history
* test: add case for parallel point-pool

* fix metric error on ptpool
  • Loading branch information
coanor authored Dec 20, 2024
1 parent 47ffa4e commit febc32f
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 14 deletions.
4 changes: 2 additions & 2 deletions point/ptpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (cpp *ReservedCapPointPool) chanPut() int64 {
}

func (cpp *ReservedCapPointPool) poolGet() int64 {
return cpp.apool.chanGet.Load() +
return cpp.apool.poolGet.Load() +
cpp.bpool.poolGet.Load() +
cpp.dpool.poolGet.Load() +
cpp.fpool.poolGet.Load() +
Expand All @@ -391,7 +391,7 @@ func (cpp *ReservedCapPointPool) poolGet() int64 {
}

func (cpp *ReservedCapPointPool) poolPut() int64 {
return cpp.apool.chanGet.Load() +
return cpp.apool.poolGet.Load() +
cpp.bpool.poolPut.Load() +
cpp.dpool.poolPut.Load() +
cpp.fpool.poolPut.Load() +
Expand Down
114 changes: 102 additions & 12 deletions point/ptpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var sampleLogs = []string{
`2022-10-27T16:12:42.050+0800 DEBUG ddtrace ddtrace/ddtrace_http.go:34 ### received tracing data from path: /v0.4/traces`,
}

func BenchmarkReservedCapPool(b *T.B) {
func BenchmarkNoReservedCapPool(b *T.B) {
now := time.Now()

b.Run("without-pool", func(b *T.B) {
Expand All @@ -123,23 +123,116 @@ func BenchmarkReservedCapPool(b *T.B) {
NewPointV2("m1", kvs, WithTime(now), WithPrecheck(false))
}
})
}

func BenchmarkReserved1KCapPool(b *T.B) {
pp := NewReservedCapPointPool(1000)
SetPointPool(pp)
defer func() {
SetPointPool(nil)
}()

b.Cleanup(func() {
metrics.Unregister(pp)
})

metrics.MustRegister(pp)

b.ResetTimer()
var kvs KVs
for i := 0; i < b.N; i++ {
kvs = kvs.Add("f0", 123, false, false)
kvs = kvs.Add("f1", 3.14, false, false)
kvs = kvs.Add("f2", "hello", false, false)
kvs = kvs.Add("f3", []byte("some looooooooooooooooooooooooooooooooooooooooooooooong text"), false, false)
kvs = kvs.Add("f4", false, false, false)
kvs = kvs.Add("f5", -123, false, false)

pt := NewPointV2("m1", kvs, WithPrecheck(false))
pp.Put(pt)
}
}

func BenchmarkReservedZeroCapPool(b *T.B) {
pp := NewReservedCapPointPool(0)
SetPointPool(pp)
defer func() {
SetPointPool(nil)
}()

b.Cleanup(func() {
metrics.Unregister(pp)
})

metrics.MustRegister(pp)

b.ResetTimer()
var kvs KVs
for i := 0; i < b.N; i++ {
kvs = kvs.Add("f0", 123, false, false)
kvs = kvs.Add("f1", 3.14, false, false)
kvs = kvs.Add("f2", "hello", false, false)
kvs = kvs.Add("f3", []byte("some looooooooooooooooooooooooooooooooooooooooooooooong text"), false, false)
kvs = kvs.Add("f4", false, false, false)
kvs = kvs.Add("f5", -123, false, false)

pt := NewPointV2("m1", kvs, WithPrecheck(false))
pp.Put(pt)
}
}

func BenchmarkParallelNoPool(b *T.B) {
now := time.Now()

b.RunParallel(func(b *T.PB) {
for b.Next() {
var kvs KVs

kvs = kvs.Add("f0", 123, false, true)
kvs = kvs.Add("f1", 3.14, false, true)
kvs = kvs.Add("f2", "hello", false, true)
kvs = kvs.Add("f3", []byte("some looooooooooooooooooooooooooooooooooooooooooooooong text"), false, true)
kvs = kvs.Add("f4", false, false, false)
kvs = kvs.Add("f5", -123, false, false)

NewPointV2("m1", kvs, WithTime(now), WithPrecheck(false))
}
})
}

b.Run("reservedCapPool", func(b *T.B) {
func BenchmarkParallelReserveCapPool(b *T.B) {
b.RunParallel(func(b *T.PB) {
pp := NewReservedCapPointPool(1000)
SetPointPool(pp)
defer func() {
SetPointPool(nil)
}()

b.Cleanup(func() {
metrics.Unregister(pp)
})
for b.Next() {
var kvs KVs
kvs = kvs.Add("f0", 123, false, false)
kvs = kvs.Add("f1", 3.14, false, false)
kvs = kvs.Add("f2", "hello", false, false)
kvs = kvs.Add("f3", []byte("some looooooooooooooooooooooooooooooooooooooooooooooong text"), false, false)
kvs = kvs.Add("f4", false, false, false)
kvs = kvs.Add("f5", -123, false, false)

metrics.MustRegister(pp)
pt := NewPointV2("m1", kvs, WithPrecheck(false))
pp.Put(pt)
}
})
}

b.ResetTimer()
var kvs KVs
for i := 0; i < b.N; i++ {
func BenchmarkParallelNoReserveCapPool(b *T.B) {
b.RunParallel(func(b *T.PB) {
pp := NewReservedCapPointPool(0)
SetPointPool(pp)
defer func() {
SetPointPool(nil)
}()

for b.Next() {
var kvs KVs
kvs = kvs.Add("f0", 123, false, false)
kvs = kvs.Add("f1", 3.14, false, false)
kvs = kvs.Add("f2", "hello", false, false)
Expand All @@ -150,9 +243,6 @@ func BenchmarkReservedCapPool(b *T.B) {
pt := NewPointV2("m1", kvs, WithPrecheck(false))
pp.Put(pt)
}

_, err := metrics.Gather()
assert.NoError(b, err)
})
}

Expand Down

0 comments on commit febc32f

Please sign in to comment.