提交 8dfaa5ec 编写于 作者: J Julius Volz 提交者: Bjoern Rabenstein

Remove use of freelists for chunk bufs.

Change-Id: Ib887fdb61e1d96da0cd32545817b925ba88831c1
上级 7b35e0f0
......@@ -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{}
......
......@@ -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())
}
......
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()
}
......@@ -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)
......
......@@ -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
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册