TSDB: Demonstrating Chunk pool is unnecessary

We only Put chunks in one place, that isn't called very often, so almost
every Get results in allocating fresh memory.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Ganesh Vernekar 2024-08-26 12:57:26 -04:00 committed by Bryan Boreham
parent 4dacd7572a
commit c5e8fe6b71
3 changed files with 0 additions and 73 deletions

View File

@ -273,7 +273,6 @@ func (nopIterator) Err() error { return nil }
// Pool is used to create and reuse chunk references to avoid allocations.
type Pool interface {
Put(Chunk) error
Get(e Encoding, b []byte) (Chunk, error)
}
@ -322,34 +321,6 @@ func (p *pool) Get(e Encoding, b []byte) (Chunk, error) {
return c, nil
}
func (p *pool) Put(c Chunk) error {
var sp *sync.Pool
var ok bool
switch c.Encoding() {
case EncXOR:
_, ok = c.(*XORChunk)
sp = &p.xor
case EncHistogram:
_, ok = c.(*HistogramChunk)
sp = &p.histogram
case EncFloatHistogram:
_, ok = c.(*FloatHistogramChunk)
sp = &p.floatHistogram
default:
return fmt.Errorf("invalid chunk encoding %q", c.Encoding())
}
if !ok {
// This may happen often with wrapped chunks. Nothing we can really do about
// it but returning an error would cause a lot of allocations again. Thus,
// we just skip it.
return nil
}
c.Reset(nil)
sp.Put(c)
return nil
}
// FromData returns a chunk from a byte slice of chunk data.
// This is there so that users of the library can easily create chunks from
// bytes.

View File

@ -158,46 +158,8 @@ func TestPool(t *testing.T) {
stream: []byte("test"),
count: 0,
}, b)
b.count = 1
require.NoError(t, p.Put(c))
require.Equal(t, &bstream{
stream: nil,
count: 0,
}, b)
})
}
t.Run("put bad chunk wrapper", func(t *testing.T) {
// When a wrapping chunk poses as an encoding it can't be converted to, Put should skip it.
c := fakeChunk{
encoding: EncXOR,
t: t,
}
require.NoError(t, p.Put(c))
})
t.Run("put invalid encoding", func(t *testing.T) {
c := fakeChunk{
encoding: EncNone,
t: t,
}
require.EqualError(t, p.Put(c), `invalid chunk encoding "none"`)
})
}
type fakeChunk struct {
Chunk
encoding Encoding
t *testing.T
}
func (c fakeChunk) Encoding() Encoding {
return c.encoding
}
func (c fakeChunk) Reset([]byte) {
c.t.Fatal("Reset should not be called")
}
func benchmarkIterator(b *testing.B, newChunk func() Chunk) {

View File

@ -882,12 +882,6 @@ func (c DefaultBlockPopulator) PopulateBlock(ctx context.Context, metrics *Compa
for _, chk := range chks {
meta.Stats.NumSamples += uint64(chk.Chunk.NumSamples())
}
for _, chk := range chks {
if err := chunkPool.Put(chk.Chunk); err != nil {
return fmt.Errorf("put chunk: %w", err)
}
}
ref++
}
if err := set.Err(); err != nil {