-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: Update Stream to accept a bufSize for tar CopyBuffer window #26964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master-1.x
Are you sure you want to change the base?
Conversation
| # The size of tar buffer window size in bytes while running tar | ||
| # streaming operations such as renaming and copying tar files during backups. | ||
| # The default value is 1MB. This should only change if backups are having performance issues | ||
| # and you understand that this value is a heuristic that may need to be tweaked. | ||
| # tar-stream-buffer-size = 1048576 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the tar buffer size is only used in the backup code paths. If this is correct, I wonder if backup-stream-buffer-size would be a better name.
gwossum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
io.CopyN did some additional error checking that io.CopyBuffer does not. We should probably do the error checking ourselves now.
gwossum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're throwing away the error now.
pkg/tar/stream.go
Outdated
| if err != nil { | ||
| return err | ||
| } else if bytesWritten != h.Size { | ||
| return fmt.Errorf("error while copying buffer, expected %d bytes but wrote %d", h.Size, bytesWritten) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add the method the error occurred in so we can track it down if needed.
io.Copy&io.CopyNuses a default window size of 32KB during copyCopy(N)callscopyBufferwithbufset tonilhttps://cs.opensource.google/go/go/+/refs/tags/go1.25.4:src/io/io.go;l=387-389
When
bufisnilgo will set the default buffer size to 32KBhttps://cs.opensource.google/go/go/+/refs/tags/go1.25.4:src/io/io.go;l=418
This PR replaces
io.CopyNwithio.CopyBufferintar.Stream. It also adds a new configuration valuetar-stream-buffer-sizewhich can be adjusted to allow for larger or smaller tar buffer sizes to be used during backup operations.It is suggested to keep the default as is, while testing different buffer sizes to be used with
CopyBufferI found that1MBwas the best performance-wise.