Merge pull request #7921 from unclejack/increase_tarsum_buffer_size
pkg/tarsum: make buffer size dynamic
This commit is contained in:
commit
47dabd55c0
1 changed files with 19 additions and 6 deletions
|
@ -16,6 +16,12 @@ import (
|
||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
buf8K = 8 * 1024
|
||||||
|
buf16K = 16 * 1024
|
||||||
|
buf32K = 32 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
type TarSum struct {
|
type TarSum struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
tarR *tar.Reader
|
tarR *tar.Reader
|
||||||
|
@ -23,7 +29,7 @@ type TarSum struct {
|
||||||
gz writeCloseFlusher
|
gz writeCloseFlusher
|
||||||
bufTar *bytes.Buffer
|
bufTar *bytes.Buffer
|
||||||
bufGz *bytes.Buffer
|
bufGz *bytes.Buffer
|
||||||
bufData [8192]byte
|
bufData []byte
|
||||||
h hash.Hash
|
h hash.Hash
|
||||||
sums map[string]string
|
sums map[string]string
|
||||||
currentFile string
|
currentFile string
|
||||||
|
@ -93,12 +99,19 @@ func (ts *TarSum) Read(buf []byte) (int, error) {
|
||||||
if ts.finished {
|
if ts.finished {
|
||||||
return ts.bufGz.Read(buf)
|
return ts.bufGz.Read(buf)
|
||||||
}
|
}
|
||||||
var buf2 []byte
|
if ts.bufData == nil {
|
||||||
if len(buf) > 8192 {
|
switch {
|
||||||
buf2 = make([]byte, len(buf), cap(buf))
|
case len(buf) <= buf8K:
|
||||||
} else {
|
ts.bufData = make([]byte, buf8K)
|
||||||
buf2 = ts.bufData[:len(buf)-1]
|
case len(buf) <= buf16K:
|
||||||
|
ts.bufData = make([]byte, buf16K)
|
||||||
|
case len(buf) <= buf32K:
|
||||||
|
ts.bufData = make([]byte, buf32K)
|
||||||
|
default:
|
||||||
|
ts.bufData = make([]byte, len(buf))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
buf2 := ts.bufData[:len(buf)-1]
|
||||||
|
|
||||||
n, err := ts.tarR.Read(buf2)
|
n, err := ts.tarR.Read(buf2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue