diff --git a/daemon/logger/jsonfilelog/jsonfilelog.go b/daemon/logger/jsonfilelog/jsonfilelog.go index 0952267054a744a7be715d489f31db12e0de5ed8..ce861bdd8a6e50a427d30d5a836d95b69ffdab0a 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 bc0ba26ee64432cc189d95667b0f88c574e4f6d1..e5ab8d74f6a8a92aa2dfda1129adb6b19492c6d7 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] }