daemon/logger: Increase initial buffers size
Make the allocated buffers bigger to allow better reusability and avoid frequent reallocations. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
parent
98810847c4
commit
d8a731c3aa
|
@ -23,7 +23,7 @@ const Name = "json-file"
|
||||||
// Every buffer will have to store the same constant json structure with the message
|
// 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.
|
// len(`{"log":"","stream:"stdout","time":"2000-01-01T00:00:00.000000000Z"}\n`) = 68.
|
||||||
// So let's start with a buffer bigger than this.
|
// 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)) }}
|
var buffersPool = sync.Pool{New: func() interface{} { return bytes.NewBuffer(make([]byte, 0, initialBufSize)) }}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package local // import "github.com/docker/docker/daemon/logger/local"
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
|
"math/bits"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -110,7 +111,11 @@ func marshal(m *logger.Message, buffer *[]byte) error {
|
||||||
|
|
||||||
buf := *buffer
|
buf := *buffer
|
||||||
if writeLen > cap(buf) {
|
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 {
|
} else {
|
||||||
buf = buf[:writeLen]
|
buf = buf[:writeLen]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue