1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

daemon: lower allocations

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
This commit is contained in:
unclejack 2015-06-29 23:27:54 +03:00
parent 40a41ffdf0
commit c1477db04f
3 changed files with 13 additions and 3 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/daemon/execdriver" "github.com/docker/docker/daemon/execdriver"
"github.com/docker/docker/pkg/broadcastwriter" "github.com/docker/docker/pkg/broadcastwriter"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
) )
@ -183,7 +184,7 @@ func (d *Daemon) ContainerExecStart(execName string, stdin io.ReadCloser, stdout
go func() { go func() {
defer w.Close() defer w.Close()
defer logrus.Debugf("Closing buffered stdin pipe") defer logrus.Debugf("Closing buffered stdin pipe")
io.Copy(w, stdin) pools.Copy(w, stdin)
}() }()
cStdin = r cStdin = r
} }

View file

@ -16,6 +16,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/execdriver" "github.com/docker/docker/daemon/execdriver"
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/reexec"
sysinfo "github.com/docker/docker/pkg/system" sysinfo "github.com/docker/docker/pkg/system"
"github.com/docker/docker/pkg/term" "github.com/docker/docker/pkg/term"
@ -394,12 +395,12 @@ func (t *TtyConsole) AttachPipes(pipes *execdriver.Pipes) error {
defer wb.CloseWriters() defer wb.CloseWriters()
} }
io.Copy(pipes.Stdout, t.console) pools.Copy(pipes.Stdout, t.console)
}() }()
if pipes.Stdin != nil { if pipes.Stdin != nil {
go func() { go func() {
io.Copy(t.console, pipes.Stdin) pools.Copy(t.console, pipes.Stdin)
pipes.Stdin.Close() pipes.Stdin.Close()
}() }()

View file

@ -57,6 +57,14 @@ func (bufPool *BufioReaderPool) Put(b *bufio.Reader) {
bufPool.pool.Put(b) bufPool.pool.Put(b)
} }
// Copy is a convenience wrapper which uses a buffer to avoid allocation in io.Copy
func Copy(dst io.Writer, src io.Reader) (written int64, err error) {
buf := BufioReader32KPool.Get(src)
written, err = io.Copy(dst, buf)
BufioReader32KPool.Put(buf)
return
}
// NewReadCloserWrapper returns a wrapper which puts the bufio.Reader back // NewReadCloserWrapper returns a wrapper which puts the bufio.Reader back
// into the pool and closes the reader if it's an io.ReadCloser. // into the pool and closes the reader if it's an io.ReadCloser.
func (bufPool *BufioReaderPool) NewReadCloserWrapper(buf *bufio.Reader, r io.Reader) io.ReadCloser { func (bufPool *BufioReaderPool) NewReadCloserWrapper(buf *bufio.Reader, r io.Reader) io.ReadCloser {