@@ -13,14 +13,23 @@ import (
1313 runc "github.com/containerd/go-runc"
1414)
1515
16+ var bufPool = sync.Pool {
17+ New : func () interface {} {
18+ buffer := make ([]byte , 32 << 10 )
19+ return & buffer
20+ },
21+ }
22+
1623func copyPipes (ctx context.Context , rio runc.IO , stdin , stdout , stderr string , wg , cwg * sync.WaitGroup ) error {
1724 for name , dest := range map [string ]func (wc io.WriteCloser , rc io.Closer ){
1825 stdout : func (wc io.WriteCloser , rc io.Closer ) {
1926 wg .Add (1 )
2027 cwg .Add (1 )
2128 go func () {
2229 cwg .Done ()
23- io .Copy (wc , rio .Stdout ())
30+ p := bufPool .Get ().(* []byte )
31+ defer bufPool .Put (p )
32+ io .CopyBuffer (wc , rio .Stdout (), * p )
2433 wg .Done ()
2534 wc .Close ()
2635 rc .Close ()
@@ -31,7 +40,10 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w
3140 cwg .Add (1 )
3241 go func () {
3342 cwg .Done ()
34- io .Copy (wc , rio .Stderr ())
43+ p := bufPool .Get ().(* []byte )
44+ defer bufPool .Put (p )
45+
46+ io .CopyBuffer (wc , rio .Stderr (), * p )
3547 wg .Done ()
3648 wc .Close ()
3749 rc .Close ()
@@ -59,7 +71,10 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w
5971 cwg .Add (1 )
6072 go func () {
6173 cwg .Done ()
62- io .Copy (rio .Stdin (), f )
74+ p := bufPool .Get ().(* []byte )
75+ defer bufPool .Put (p )
76+
77+ io .CopyBuffer (rio .Stdin (), f , * p )
6378 rio .Stdin ().Close ()
6479 f .Close ()
6580 }()
0 commit comments