Skip to content

Commit

Permalink
Grow buffer to bufsz #33
Browse files Browse the repository at this point in the history
  • Loading branch information
rlmcpherson committed Oct 2, 2014
1 parent 48fa76e commit 549f4bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func newBufferPool(bufsz int64) (np *bp) {
select {
case b := <-np.give:
timeout.Stop()
b.Reset()
q.PushFront(qBuf{when: time.Now(), buffer: b})

case np.get <- e.Value.(qBuf).buffer:
Expand All @@ -60,7 +61,6 @@ func newBufferPool(bufsz int64) (np *bp) {
for e != nil {
n := e.Next()
if time.Since(e.Value.(qBuf).when) > np.timeout {
logger.debugPrintln("removing buffer from queue")
q.Remove(e)
e.Value = nil
}
Expand Down
9 changes: 4 additions & 5 deletions putter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"math"
"net/http"
"net/url"
"runtime/debug"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -114,7 +113,8 @@ func (p *putter) Write(b []byte) (int, error) {
}
if p.buf == nil {
p.buf = <-p.bp.get
p.buf.Reset()
// grow to bufsz, allocating overhead to avoid slice growth
p.buf.Grow(int(p.bufsz + 100*kb))
}
n, err := p.buf.Write(b)
if err != nil {
Expand Down Expand Up @@ -148,9 +148,8 @@ func (p *putter) flush() {
if p.part%1000 == 0 {
p.bufsz = min64(p.bufsz*2, maxPartSize)
p.bp.makeSize = p.bufsz
logger.debugPrintf("doubling buffer size to %d", p.bufsz)
debug.FreeOSMemory()
logger.debugPrintln("os memory freed")
logger.debugPrintf("part size doubled to %d", p.bufsz)

}

}
Expand Down

0 comments on commit 549f4bb

Please sign in to comment.