-
Notifications
You must be signed in to change notification settings - Fork 457
/
Copy pathpooling.go
231 lines (178 loc) · 8.05 KB
/
pooling.go
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package config
// PoolingType is a type of pooling, using runtime or mmap'd bytes pooling.
type PoolingType string
const (
// SimplePooling uses the basic Go runtime to allocate bytes for bytes pools.
SimplePooling PoolingType = "simple"
)
const (
defaultMaxFinalizerCapacity = 4
// defaultPostingsListPoolSize has a small default pool size since postings
// lists can frequently reach the size of 4mb each in practice even when
// reset.
defaultPostingsListPoolSize = 16
)
// PoolingPolicy specifies the pooling policy.
type PoolingPolicy struct {
// The initial alloc size for a block.
BlockAllocSize int `yaml:"blockAllocSize"`
// The general pool type (currently only supported: simple).
Type PoolingType `yaml:"type"`
// The Bytes pool buckets to use.
BytesPool BucketPoolPolicy `yaml:"bytesPool"`
// The policy for the Closers pool.
ClosersPool PoolPolicy `yaml:"closersPool"`
// The policy for the Context pool.
ContextPool ContextPoolPolicy `yaml:"contextPool"`
// The policy for the DatabaseSeries pool.
SeriesPool PoolPolicy `yaml:"seriesPool"`
// The policy for the DatabaseBlock pool.
BlockPool PoolPolicy `yaml:"blockPool"`
// The policy for the Encoder pool.
EncoderPool PoolPolicy `yaml:"encoderPool"`
// The policy for the Iterator pool.
IteratorPool PoolPolicy `yaml:"iteratorPool"`
// The policy for the Segment Reader pool.
SegmentReaderPool PoolPolicy `yaml:"segmentReaderPool"`
// The policy for the Identifier pool.
IdentifierPool PoolPolicy `yaml:"identifierPool"`
// The policy for the FetchBlockMetadataResult pool.
FetchBlockMetadataResultsPool CapacityPoolPolicy `yaml:"fetchBlockMetadataResultsPool"`
// The policy for the FetchBlocksMetadataResults pool.
FetchBlocksMetadataResultsPool CapacityPoolPolicy `yaml:"fetchBlocksMetadataResultsPool"`
// The policy for the HostBlockMetadataSlice pool.
HostBlockMetadataSlicePool CapacityPoolPolicy `yaml:"hostBlockMetadataSlicePool"`
// The policy for the BlockMetadat pool.
BlockMetadataPool PoolPolicy `yaml:"blockMetadataPool"`
// The policy for the BlockMetadataSlice pool.
BlockMetadataSlicePool CapacityPoolPolicy `yaml:"blockMetadataSlicePool"`
// The policy for the BlocksMetadata pool.
BlocksMetadataPool PoolPolicy `yaml:"blocksMetadataPool"`
// The policy for the BlocksMetadataSlice pool.
BlocksMetadataSlicePool CapacityPoolPolicy `yaml:"blocksMetadataSlicePool"`
// The policy for the tags pool.
TagsPool MaxCapacityPoolPolicy `yaml:"tagsPool"`
// The policy for the tags iterator pool.
TagsIteratorPool PoolPolicy `yaml:"tagIteratorPool"`
// The policy for the index.ResultsPool.
IndexResultsPool PoolPolicy `yaml:"indexResultsPool"`
// The policy for the TagEncoderPool.
TagEncoderPool PoolPolicy `yaml:"tagEncoderPool"`
// The policy for the TagDecoderPool.
TagDecoderPool PoolPolicy `yaml:"tagDecoderPool"`
// The policy for the WriteBatchPool.
WriteBatchPool WriteBatchPoolPolicy `yaml:"writeBatchPool"`
// The policy for the PostingsListPool.
PostingsListPool PoolPolicy `yaml:"postingsListPool"`
}
// PostingsListPoolPolicyWithDefaults returns the postings list pool policy
// and will set a sensible default size if not specified in the YAML
// configuration.
func (c PoolingPolicy) PostingsListPoolPolicyWithDefaults() PoolPolicy {
if c.PostingsListPool.Size > 0 {
return c.PostingsListPool
}
policy := c.PostingsListPool
policy.Size = defaultPostingsListPoolSize
return policy
}
// PoolPolicy specifies a single pool policy.
type PoolPolicy struct {
// The size of the pool.
Size int `yaml:"size"`
// The low watermark to start refilling the pool, if zero none.
RefillLowWaterMark float64 `yaml:"lowWatermark" validate:"min=0.0,max=1.0"`
// The high watermark to stop refilling the pool, if zero none.
RefillHighWaterMark float64 `yaml:"highWatermark" validate:"min=0.0,max=1.0"`
}
// CapacityPoolPolicy specifies a single pool policy that has a
// per element capacity.
type CapacityPoolPolicy struct {
// The size of the pool.
Size int `yaml:"size"`
// The capacity of items in the pool.
Capacity int `yaml:"capacity"`
// The low watermark to start refilling the pool, if zero none.
RefillLowWaterMark float64 `yaml:"lowWatermark" validate:"min=0.0,max=1.0"`
// The high watermark to stop refilling the pool, if zero none.
RefillHighWaterMark float64 `yaml:"highWatermark" validate:"min=0.0,max=1.0"`
}
// MaxCapacityPoolPolicy specifies a single pool policy that has a
// per element capacity, and a maximum allowed capacity as well.
type MaxCapacityPoolPolicy struct {
// The size of the pool.
Size int `yaml:"size"`
// The capacity of items in the pool.
Capacity int `yaml:"capacity"`
// The max capacity of items in the pool.
MaxCapacity int `yaml:"maxCapacity"`
// The low watermark to start refilling the pool, if zero none.
RefillLowWaterMark float64 `yaml:"lowWatermark" validate:"min=0.0,max=1.0"`
// The high watermark to stop refilling the pool, if zero none.
RefillHighWaterMark float64 `yaml:"highWatermark" validate:"min=0.0,max=1.0"`
}
// BucketPoolPolicy specifies a bucket pool policy.
type BucketPoolPolicy struct {
// The pool buckets sizes to use
Buckets []CapacityPoolPolicy `yaml:"buckets"`
}
// ContextPoolPolicy specifies the policy for the context pool.
type ContextPoolPolicy struct {
// The size of the pool
Size int `yaml:"size"`
// The low watermark to start refilling the pool, if zero none.
RefillLowWaterMark float64 `yaml:"lowWatermark" validate:"min=0.0,max=1.0"`
// The high watermark to stop refilling the pool, if zero none.
RefillHighWaterMark float64 `yaml:"highWatermark" validate:"min=0.0,max=1.0"`
// The maximum allowable size for a slice of finalizers that the
// pool will allow to be returned (finalizer slices that grow too
// large during use will be discarded instead of returning to the
// pool where they would consume more memory.)
MaxFinalizerCapacity int `yaml:"maxFinalizerCapacity" validate:"min=0"`
}
// WriteBatchPoolPolicy specifies the pooling policy for the WriteBatch pool.
type WriteBatchPoolPolicy struct {
// InitialBatchSize controls the initial batch size for each WriteBatch when
// the pool is being constructed / refilled.
InitialBatchSize *int `yaml:"initialBatchSize"`
// MaxBatchSize controls the maximum size that a pooled WriteBatch can grow to
// and still remain in the pool.
MaxBatchSize *int `yaml:"maxBatchSize"`
// Pool is the Pooling Policy for the WriteBatch pool.
Pool PoolPolicy `yaml:"pool"`
}
// PoolPolicy returns the PoolPolicy that is represented by the ContextPoolPolicy.
func (c ContextPoolPolicy) PoolPolicy() PoolPolicy {
return PoolPolicy{
Size: c.Size,
RefillLowWaterMark: c.RefillLowWaterMark,
RefillHighWaterMark: c.RefillHighWaterMark,
}
}
// MaxFinalizerCapacityWithDefault returns the maximum finalizer capacity and
// fallsback to the default value if its not set.
func (c ContextPoolPolicy) MaxFinalizerCapacityWithDefault() int {
if c.MaxFinalizerCapacity == 0 {
return defaultMaxFinalizerCapacity
}
return c.MaxFinalizerCapacity
}