X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6eb3d1fb8fe71623fa63da46c250184cf2e4fbb8..2e104941dbf1e4bf92e0632cadeb946be0595d67:/services/keepstore/bufferpool.go?ds=sidebyside diff --git a/services/keepstore/bufferpool.go b/services/keepstore/bufferpool.go index 373bfc75a1..38f97aff11 100644 --- a/services/keepstore/bufferpool.go +++ b/services/keepstore/bufferpool.go @@ -1,14 +1,18 @@ package main import ( - "log" "sync" + "sync/atomic" "time" + + log "github.com/Sirupsen/logrus" ) type bufferPool struct { // limiter has a "true" placeholder for each in-use buffer. limiter chan bool + // allocated is the number of bytes currently allocated to buffers. + allocated uint64 // Pool has unused buffers. sync.Pool } @@ -16,6 +20,7 @@ type bufferPool struct { func newBufferPool(count int, bufSize int) *bufferPool { p := bufferPool{} p.New = func() interface{} { + atomic.AddUint64(&p.allocated, uint64(bufSize)) return make([]byte, bufSize) } p.limiter = make(chan bool, count) @@ -42,3 +47,18 @@ func (p *bufferPool) Put(buf []byte) { p.Pool.Put(buf) <-p.limiter } + +// Alloc returns the number of bytes allocated to buffers. +func (p *bufferPool) Alloc() uint64 { + return atomic.LoadUint64(&p.allocated) +} + +// Cap returns the maximum number of buffers allowed. +func (p *bufferPool) Cap() int { + return cap(p.limiter) +} + +// Len returns the number of buffers in use right now. +func (p *bufferPool) Len() int { + return len(p.limiter) +}