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

Merge pull request #14268 from unclejack/lower_allocations_execdriver

daemon: lower allocations
This commit is contained in:
Alexander Morozov 2015-06-30 12:12:06 -07:00
commit bb364ff459
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/pkg/broadcastwriter"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/runconfig"
)
@ -187,7 +188,7 @@ func (d *Daemon) ContainerExecStart(execName string, stdin io.ReadCloser, stdout
go func() {
defer w.Close()
defer logrus.Debugf("Closing buffered stdin pipe")
io.Copy(w, stdin)
pools.Copy(w, stdin)
}()
cStdin = r
}

View file

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

View file

@ -57,6 +57,14 @@ func (bufPool *BufioReaderPool) Put(b *bufio.Reader) {
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
// 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 {