From 8dfaa5ecd2161b5b391f33a91f0f2de635779754 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Wed, 20 Aug 2014 15:27:24 +0200 Subject: [PATCH] Remove use of freelists for chunk bufs. Change-Id: Ib887fdb61e1d96da0cd32545817b925ba88831c1 --- storage/local/chunk.go | 2 -- storage/local/delta.go | 11 ++------- storage/local/freelist.go | 44 ------------------------------------ storage/local/persistence.go | 3 --- storage/local/series.go | 1 - 5 files changed, 2 insertions(+), 59 deletions(-) delete mode 100644 storage/local/freelist.go diff --git a/storage/local/chunk.go b/storage/local/chunk.go index 92b6b479b7..feb7e5d042 100644 --- a/storage/local/chunk.go +++ b/storage/local/chunk.go @@ -18,7 +18,6 @@ type chunk interface { newIterator() chunkIterator marshal(io.Writer) error unmarshal(io.Reader) error - close() // TODO: remove? values() <-chan *metric.SamplePair @@ -33,7 +32,6 @@ type chunkIterator interface { func transcodeAndAdd(dst chunk, src chunk, s *metric.SamplePair) chunks { numTranscodes.Inc() - defer src.close() head := dst body := chunks{} diff --git a/storage/local/delta.go b/storage/local/delta.go index 5271bb9a6a..83a1fef7e1 100644 --- a/storage/local/delta.go +++ b/storage/local/delta.go @@ -51,8 +51,7 @@ type deltaEncodedChunk struct { } func newDeltaEncodedChunk(tb, vb deltaBytes, isInt bool) *deltaEncodedChunk { - buf := chunkBufs.Get() - buf = buf[:deltaHeaderIsIntOffset+1] + buf := make([]byte, deltaHeaderIsIntOffset+1, 1024) buf[deltaHeaderTimeBytesOffset] = byte(tb) buf[deltaHeaderValueBytesOffset] = byte(vb) @@ -73,8 +72,7 @@ func (c *deltaEncodedChunk) newFollowupChunk() chunk { } func (c *deltaEncodedChunk) clone() chunk { - buf := chunkBufs.Get() - buf = buf[:len(c.buf)] + buf := make([]byte, len(c.buf), 1024) copy(buf, c.buf) return &deltaEncodedChunk{ buf: buf, @@ -236,11 +234,6 @@ func (c *deltaEncodedChunk) add(s *metric.SamplePair) chunks { return chunks{c} } -func (c *deltaEncodedChunk) close() { - //fmt.Println("returning chunk") - chunkBufs.Give(c.buf) -} - func (c *deltaEncodedChunk) sampleSize() int { return int(c.timeBytes() + c.valueBytes()) } diff --git a/storage/local/freelist.go b/storage/local/freelist.go deleted file mode 100644 index 609c3e7aac..0000000000 --- a/storage/local/freelist.go +++ /dev/null @@ -1,44 +0,0 @@ -package storage_ng - -import ( - "github.com/prometheus/prometheus/utility" -) - -var chunkBufs = newChunkBufList(10000, 10000) - -type chunkBufList struct { - l utility.FreeList -} - -func newChunkBuf() []byte { - return make([]byte, 0, 1024) // TODO: This value somehow needs to be set in coordination with the one passed into the disk persistence. -} - -func newChunkBufList(length, capacity int) *chunkBufList { - l := &chunkBufList{ - l: utility.NewFreeList(capacity), - } - for i := 0; i < length; i++ { - l.l.Give(newChunkBuf()) - } - return l -} - -func (l *chunkBufList) Get() []byte { - numChunkGets.Inc() - if v, ok := l.l.Get(); ok { - return v.([]byte) - } - - return newChunkBuf() -} - -func (l *chunkBufList) Give(v []byte) bool { - numChunkGives.Inc() - v = v[:0] - return l.l.Give(v) -} - -func (l *chunkBufList) Close() { - l.l.Close() -} diff --git a/storage/local/persistence.go b/storage/local/persistence.go index 3104d8dcbb..8cb73406c9 100644 --- a/storage/local/persistence.go +++ b/storage/local/persistence.go @@ -148,9 +148,6 @@ func (p *diskPersistence) LoadChunks(fp clientmodel.Fingerprint, indexes []int) if err == nil { return } - for _, c := range chunks { - c.close() - } }() typeBuf := make([]byte, 1) diff --git a/storage/local/series.go b/storage/local/series.go index f4bac78fef..7ff6c09428 100644 --- a/storage/local/series.go +++ b/storage/local/series.go @@ -93,7 +93,6 @@ func (cd *chunkDesc) evictOnUnpin() { func (cd *chunkDesc) evictNow() { cd.firstTimeField = cd.chunk.firstTime() cd.lastTimeField = cd.chunk.lastTime() - cd.chunk.close() cd.chunk = nil }