diff options
author | Ruslan Andreev <kels9009@gmail.com> | 2021-11-01 18:17:49 +0000 |
---|---|---|
committer | David Chase <drchase@google.com> | 2021-11-01 19:42:30 +0000 |
commit | 5f1bcd1bc29615b4366f6da8df958bd048ef89a8 (patch) | |
tree | 2d6df95a980b73939e2e5349434234935570f18b /src/sync | |
parent | b5a5b7bfb1ba25abf8cad8b9ad9451fb6e79d941 (diff) | |
download | go-5f1bcd1bc29615b4366f6da8df958bd048ef89a8.tar.gz go-5f1bcd1bc29615b4366f6da8df958bd048ef89a8.zip |
sync: add PoolStarvation benchmark
This benchmark simulates object starvation in order to force Ps to steal
objects from other Ps. Extracted from CL 314229.
Change-Id: Iee31df355ba04d80fbd91c4414e397a375e6d6d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/360256
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Trust: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/sync')
-rw-r--r-- | src/sync/pool_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/sync/pool_test.go b/src/sync/pool_test.go index f94153c8d7..d991621624 100644 --- a/src/sync/pool_test.go +++ b/src/sync/pool_test.go @@ -270,6 +270,26 @@ func BenchmarkPoolOverflow(b *testing.B) { }) } +// Simulate object starvation in order to force Ps to steal objects +// from other Ps. +func BenchmarkPoolStarvation(b *testing.B) { + var p Pool + count := 100 + // Reduce number of putted objects by 33 %. It creates objects starvation + // that force P-local storage to steal objects from other Ps. + countStarved := count - int(float32(count)*0.33) + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + for b := 0; b < countStarved; b++ { + p.Put(1) + } + for b := 0; b < count; b++ { + p.Get() + } + } + }) +} + var globalSink interface{} func BenchmarkPoolSTW(b *testing.B) { |