Skip to content

Commit

Permalink
kv/tscache: clean up per-op allocations in IntervalSklAdd benchmarks
Browse files Browse the repository at this point in the history
These allocations in the benchmark harness were obscuring the behavior
of the timestamp cache.

Also, remove the unused `parallel` knob in BenchmarkIntervalSklAddAndLookup.

```
name                                old time/op    new time/op    delta
IntervalSklAddAndLookup/frac_0-16     2.20µs ± 3%    0.61µs ± 5%   -72.27%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_1-16     2.07µs ± 3%    0.61µs ± 6%   -70.80%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_2-16     1.94µs ± 1%    0.60µs ± 8%   -69.02%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_3-16     1.86µs ± 4%    0.59µs ± 9%   -68.03%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_4-16     1.76µs ± 5%    0.61µs ± 7%   -65.68%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_5-16     1.57µs ± 7%    0.60µs ± 4%   -61.64%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_6-16     1.37µs ± 7%    0.60µs ± 6%   -56.41%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_7-16     1.18µs ± 1%    0.60µs ± 7%   -49.05%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_8-16     1.05µs ± 1%    0.61µs ± 9%   -42.30%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_9-16      919ns ± 4%     643ns ±29%   -30.02%  (p=0.008 n=5+5)
IntervalSklAdd/size_1-16              2.31µs ± 1%    1.77µs ± 2%   -23.35%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_10-16     775ns ± 9%     603ns ± 7%   -22.21%  (p=0.008 n=5+5)
IntervalSklAdd/size_10-16             3.96µs ± 2%    3.21µs ± 2%   -18.80%  (p=0.008 n=5+5)
IntervalSklAdd/size_10000-16          4.31µs ± 1%    3.52µs ± 2%   -18.43%  (p=0.008 n=5+5)
IntervalSklAdd/size_1000-16           3.96µs ± 2%    3.32µs ± 3%   -16.21%  (p=0.008 n=5+5)
IntervalSklAdd/size_100-16            3.85µs ± 1%    3.25µs ± 4%   -15.51%  (p=0.008 n=5+5)
IntervalSklAdd/size_1000000-16        8.02µs ± 3%    7.28µs ± 1%    -9.27%  (p=0.008 n=5+5)
IntervalSklAdd/size_10000000-16       16.5µs ± 2%    15.8µs ± 2%    -3.91%  (p=0.008 n=5+5)
IntervalSklAdd/size_100000-16         5.44µs ± 9%    4.82µs ±14%      ~     (p=0.095 n=5+5)
IntervalSklAdd/size_100000000-16      42.1µs ± 4%    41.4µs ± 2%      ~     (p=0.421 n=5+5)

name                                old alloc/op   new alloc/op   delta
IntervalSklAddAndLookup/frac_0-16       789B ± 4%        0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_1-16       716B ± 3%        0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_2-16       632B ± 2%        0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_3-16       565B ± 5%        0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_4-16       473B ± 2%        0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_5-16       323B ±74%        0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_6-16      75.8B ± 1%      0.0B       -100.00%  (p=0.000 n=4+5)
IntervalSklAddAndLookup/frac_7-16      65.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_8-16      55.4B ± 1%      0.0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_9-16      45.6B ± 1%      0.0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_10-16     36.0B ± 0%      0.0B       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_1-16                240B ± 2%       99B ± 0%   -58.82%  (p=0.008 n=5+5)
IntervalSklAdd/size_10-16               373B ± 7%      202B ± 2%   -45.73%  (p=0.008 n=5+5)
IntervalSklAdd/size_100-16              339B ± 4%      188B ± 3%   -44.52%  (p=0.008 n=5+5)
IntervalSklAdd/size_10000-16            526B ± 8%      302B ±23%   -42.63%  (p=0.008 n=5+5)
IntervalSklAdd/size_1000-16             365B ± 5%      215B ± 3%   -41.02%  (p=0.008 n=5+5)
IntervalSklAdd/size_100000-16           919B ± 8%      763B ± 4%   -16.99%  (p=0.008 n=5+5)
IntervalSklAdd/size_1000000-16        2.25kB ± 4%    1.92kB ± 6%   -14.45%  (p=0.008 n=5+5)
IntervalSklAdd/size_10000000-16       6.11kB ± 6%    5.65kB ± 9%      ~     (p=0.056 n=5+5)
IntervalSklAdd/size_100000000-16      16.7kB ± 5%    17.0kB ±12%      ~     (p=0.841 n=5+5)

name                                old allocs/op  new allocs/op  delta
IntervalSklAdd/size_1-16                6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_10-16               6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_100-16              6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_1000-16             6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_10000-16            6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_100000-16           6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_1000000-16          6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_10000000-16         6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAdd/size_100000000-16        6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_0-16       6.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_1-16       5.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_2-16       5.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_3-16       4.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_4-16       4.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_5-16       3.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_6-16       3.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_7-16       3.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_8-16       2.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_9-16       2.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
IntervalSklAddAndLookup/frac_10-16      2.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)
```
  • Loading branch information
nvanbenschoten committed Jan 5, 2021
1 parent cc61e09 commit cb1bb98
Showing 1 changed file with 47 additions and 29 deletions.
76 changes: 47 additions & 29 deletions pkg/kv/kvserver/tscache/interval_skl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1326,11 +1326,23 @@ func BenchmarkIntervalSklAdd(b *testing.B) {
size := 1
for i := 0; i < 9; i++ {
b.Run(fmt.Sprintf("size_%d", size), func(b *testing.B) {
for iter := 0; iter < b.N; iter++ {
type op struct {
from, to []byte
val cacheValue
}
ops := make([]op, b.N)
for i := range ops {
rnd := int64(rng.Int31n(max))
from := []byte(fmt.Sprintf("%020d", rnd))
to := []byte(fmt.Sprintf("%020d", rnd+int64(size-1)))
s.AddRange(from, to, 0, makeVal(clock.Now(), txnID))
ops[i] = op{
from: []byte(fmt.Sprintf("%020d", rnd)),
to: []byte(fmt.Sprintf("%020d", rnd+int64(size-1))),
val: makeVal(clock.Now(), txnID),
}
}

b.ResetTimer()
for _, op := range ops {
s.AddRange(op.from, op.to, 0, op.val)
}
})

Expand All @@ -1339,7 +1351,6 @@ func BenchmarkIntervalSklAdd(b *testing.B) {
}

func BenchmarkIntervalSklAddAndLookup(b *testing.B) {
const parallel = 1
const max = 1000000000 // max size of range
const data = 500000 // number of ranges
const txnID = "123"
Expand All @@ -1356,33 +1367,40 @@ func BenchmarkIntervalSklAddAndLookup(b *testing.B) {

for i := 0; i <= 10; i++ {
b.Run(fmt.Sprintf("frac_%d", i), func(b *testing.B) {
var wg sync.WaitGroup

for p := 0; p < parallel; p++ {
wg.Add(1)

go func(i int) {
defer wg.Done()

rng := rand.New(rand.NewSource(timeutil.Now().UnixNano()))

for n := 0; n < b.N/parallel; n++ {
readFrac := rng.Int31n(10)
keyNum := rng.Int31n(max)

if readFrac < int32(i) {
key := []byte(fmt.Sprintf("%020d", keyNum))
s.LookupTimestamp(key)
} else {
from, to := makeRange(keyNum)
nowVal := makeVal(clock.Now(), txnID)
s.AddRange(from, to, excludeFrom|excludeTo, nowVal)
}
type op struct {
read bool
from, to []byte
val cacheValue
}
ops := make([]op, b.N)
for i := range ops {
readFrac := rng.Int31n(10)
keyNum := rng.Int31n(max)

if readFrac < int32(i) {
ops[i] = op{
read: true,
from: []byte(fmt.Sprintf("%020d", keyNum)),
}
} else {
from, to := makeRange(keyNum)
ops[i] = op{
read: false,
from: from,
to: to,
val: makeVal(clock.Now(), txnID),
}
}(i)
}
}

wg.Wait()
b.ResetTimer()
for _, op := range ops {
if op.read {
s.LookupTimestamp(op.from)
} else {
s.AddRange(op.from, op.to, excludeFrom|excludeTo, op.val)
}
}
})
}
}
Expand Down

0 comments on commit cb1bb98

Please sign in to comment.