Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
unclejack authored on 2015/06/30 05:27:54... | ... |
@@ -11,6 +11,7 @@ import ( |
11 | 11 |
"github.com/docker/docker/daemon/execdriver" |
12 | 12 |
"github.com/docker/docker/pkg/broadcastwriter" |
13 | 13 |
"github.com/docker/docker/pkg/ioutils" |
14 |
+ "github.com/docker/docker/pkg/pools" |
|
14 | 15 |
"github.com/docker/docker/pkg/stringid" |
15 | 16 |
"github.com/docker/docker/runconfig" |
16 | 17 |
) |
... | ... |
@@ -183,7 +184,7 @@ func (d *Daemon) ContainerExecStart(execName string, stdin io.ReadCloser, stdout |
183 | 183 |
go func() { |
184 | 184 |
defer w.Close() |
185 | 185 |
defer logrus.Debugf("Closing buffered stdin pipe") |
186 |
- io.Copy(w, stdin) |
|
186 |
+ pools.Copy(w, stdin) |
|
187 | 187 |
}() |
188 | 188 |
cStdin = r |
189 | 189 |
} |
... | ... |
@@ -16,6 +16,7 @@ import ( |
16 | 16 |
"github.com/Sirupsen/logrus" |
17 | 17 |
"github.com/docker/docker/daemon/execdriver" |
18 | 18 |
"github.com/docker/docker/pkg/parsers" |
19 |
+ "github.com/docker/docker/pkg/pools" |
|
19 | 20 |
"github.com/docker/docker/pkg/reexec" |
20 | 21 |
sysinfo "github.com/docker/docker/pkg/system" |
21 | 22 |
"github.com/docker/docker/pkg/term" |
... | ... |
@@ -394,12 +395,12 @@ func (t *TtyConsole) AttachPipes(pipes *execdriver.Pipes) error { |
394 | 394 |
defer wb.CloseWriters() |
395 | 395 |
} |
396 | 396 |
|
397 |
- io.Copy(pipes.Stdout, t.console) |
|
397 |
+ pools.Copy(pipes.Stdout, t.console) |
|
398 | 398 |
}() |
399 | 399 |
|
400 | 400 |
if pipes.Stdin != nil { |
401 | 401 |
go func() { |
402 |
- io.Copy(t.console, pipes.Stdin) |
|
402 |
+ pools.Copy(t.console, pipes.Stdin) |
|
403 | 403 |
|
404 | 404 |
pipes.Stdin.Close() |
405 | 405 |
}() |
... | ... |
@@ -57,6 +57,14 @@ func (bufPool *BufioReaderPool) Put(b *bufio.Reader) { |
57 | 57 |
bufPool.pool.Put(b) |
58 | 58 |
} |
59 | 59 |
|
60 |
+// Copy is a convenience wrapper which uses a buffer to avoid allocation in io.Copy |
|
61 |
+func Copy(dst io.Writer, src io.Reader) (written int64, err error) { |
|
62 |
+ buf := BufioReader32KPool.Get(src) |
|
63 |
+ written, err = io.Copy(dst, buf) |
|
64 |
+ BufioReader32KPool.Put(buf) |
|
65 |
+ return |
|
66 |
+} |
|
67 |
+ |
|
60 | 68 |
// NewReadCloserWrapper returns a wrapper which puts the bufio.Reader back |
61 | 69 |
// into the pool and closes the reader if it's an io.ReadCloser. |
62 | 70 |
func (bufPool *BufioReaderPool) NewReadCloserWrapper(buf *bufio.Reader, r io.Reader) io.ReadCloser { |