Skip to content

Commit bdcb2aa

Browse files
authored
Copy images using a decently-sized buffer (#902)
Default implementation of io.Copy uses a tiny buffer which significantly impacts performance. On my machine with a local image (~2.5G) creation time went from ~10 minutes to ~2 seconds. Signed-off-by: Silvio Moioli <[email protected]>
1 parent 13f954c commit bdcb2aa

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

libvirt/utils_volume.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ func newCopier(virConn *libvirt.Libvirt, volume *libvirt.StorageVol, size uint64
1717
defer w.Close()
1818

1919
go func() error {
20-
bytesCopied, err := io.Copy(w, src)
20+
buffer := make([]byte, 4*1024*1024)
21+
bytesCopied, err := io.CopyBuffer(w, src, buffer)
2122

2223
// if we get unexpected EOF this mean that connection was closed suddently from server side
2324
// the problem is not on the plugin but on server hosting currupted images

0 commit comments

Comments
 (0)