diff --git a/daemon/logger/jsonfilelog/jsonfilelog.go b/daemon/logger/jsonfilelog/jsonfilelog.go index 0952267054..ce861bdd8a 100644 --- a/daemon/logger/jsonfilelog/jsonfilelog.go +++ b/daemon/logger/jsonfilelog/jsonfilelog.go @@ -23,7 +23,7 @@ const Name = "json-file" // Every buffer will have to store the same constant json structure with the message // len(`{"log":"","stream:"stdout","time":"2000-01-01T00:00:00.000000000Z"}\n`) = 68. // So let's start with a buffer bigger than this. -const initialBufSize = 128 +const initialBufSize = 256 var buffersPool = sync.Pool{New: func() interface{} { return bytes.NewBuffer(make([]byte, 0, initialBufSize)) }} diff --git a/daemon/logger/local/local.go b/daemon/logger/local/local.go index bc0ba26ee6..e5ab8d74f6 100644 --- a/daemon/logger/local/local.go +++ b/daemon/logger/local/local.go @@ -3,6 +3,7 @@ package local // import "github.com/docker/docker/daemon/logger/local" import ( "encoding/binary" "io" + "math/bits" "strconv" "sync" "time" @@ -110,7 +111,11 @@ func marshal(m *logger.Message, buffer *[]byte) error { buf := *buffer if writeLen > cap(buf) { - buf = make([]byte, writeLen) + // If we already need to reallocate the buffer, make it larger to be more reusable. + // Round to the next power of two. + capacity := 1 << (bits.Len(uint(writeLen)) + 1) + + buf = make([]byte, writeLen, capacity) } else { buf = buf[:writeLen] }