-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbucket_bench_test.go
More file actions
174 lines (143 loc) · 4.57 KB
/
bucket_bench_test.go
File metadata and controls
174 lines (143 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
Copyright 2026 The ARCORIS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bufferpool
import (
"strconv"
"testing"
)
// BenchmarkBucketPushPopSegmented measures the raw segmented bucket LIFO loop.
//
// The benchmark intentionally pushes into an empty bucket and pops back to
// empty. That exposes the metadata allocation cost of the fully lazy model. Pool
// benchmarks below cover the ordinary steady-state data-plane loop where bucket
// metadata is usually already present through retained traffic.
func BenchmarkBucketPushPopSegmented(b *testing.B) {
buffer := make([]byte, 0, 1024)
bucket := newBucket(64, 8)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if !bucket.push(buffer) {
b.Fatal("bucket push rejected")
}
popped, ok := bucket.pop()
if !ok {
b.Fatal("bucket pop missed")
}
poolBenchmarkBufferSink = popped
}
}
// BenchmarkBucketPushPopSegmentSizes compares steady push/pop cost across
// supported lazy segment sizes.
func BenchmarkBucketPushPopSegmentSizes(b *testing.B) {
for _, segmentSlots := range []int{4, 8, 16, 32} {
segmentSlots := segmentSlots
b.Run("segment_slots_"+strconv.Itoa(segmentSlots), func(b *testing.B) {
buffer := make([]byte, 0, 1024)
bucket := newBucket(64, segmentSlots)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if !bucket.push(buffer) {
b.Fatal("bucket push rejected")
}
popped, ok := bucket.pop()
if !ok {
b.Fatal("bucket pop missed")
}
poolBenchmarkBufferSink = popped
}
})
}
}
// BenchmarkBucketPushPopFixedEquivalent is a lower-bound reference for the old
// eager fixed-slot shape.
//
// It does not implement full bucket invariants, retained-byte accounting, trim,
// or corruption checks. It exists only to keep segmented metadata overhead
// visible while the production bucket uses lazy segments.
func BenchmarkBucketPushPopFixedEquivalent(b *testing.B) {
buffer := make([]byte, 0, 1024)
slots := make([][]byte, 64)
var count int
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
slots[count] = buffer
count++
count--
popped := slots[count]
slots[count] = nil
poolBenchmarkBufferSink = popped
}
}
// BenchmarkBucketTrimSegmented measures bounded LIFO trim over segmented
// metadata.
//
// Setup is outside the timed region for each trim batch so the benchmark reports
// trim work, slot clearing, and segment release rather than seed allocation.
func BenchmarkBucketTrimSegmented(b *testing.B) {
const (
slotLimit = 64
segmentSlots = 8
capacity = 1024
)
b.ReportAllocs()
b.StopTimer()
for i := 0; i < b.N; i++ {
bucket := newBucket(slotLimit, segmentSlots)
for index := 0; index < slotLimit; index++ {
if !bucket.push(make([]byte, 0, capacity)) {
b.Fatal("bucket seed push rejected")
}
}
b.StartTimer()
result := bucket.trim(slotLimit)
b.StopTimer()
if result.RemovedBuffers != slotLimit {
b.Fatalf("trim removed %d buffers, want %d", result.RemovedBuffers, slotLimit)
}
poolBenchmarkIntSink = result.AvailableSlots
}
}
// BenchmarkPoolGetPutSegmentedBucket measures the full Pool data-plane loop
// with segmented bucket storage enabled.
//
// This benchmark keeps class routing, lifecycle checks, owner admission,
// selector behavior, shard locking, retained accounting, and bucket storage in
// the measured path. It is the semantic companion to raw bucket benchmarks.
func BenchmarkPoolGetPutSegmentedBucket(b *testing.B) {
tc := poolBenchmarkCase{
name: "segmented_bucket",
size: 900,
capacity: 1024,
shards: 4,
selector: ShardSelectionModeProcessorInspired,
bucketSlots: 64,
retainedSeed: 32,
}
pool := poolBenchmarkNewPool(b, poolBenchmarkPolicyForCase(tc))
poolBenchmarkSeedRetainedPublic(b, pool, tc.capacity, tc.retainedSeed)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
buffer, err := pool.Get(tc.size)
if err != nil {
b.Fatalf("Get() returned error: %v", err)
}
if err := pool.Put(buffer); err != nil {
b.Fatalf("Put() returned error: %v", err)
}
poolBenchmarkBufferSink = buffer
}
}