Skip to content

Commit

Permalink
Remove additional buffering
Browse files Browse the repository at this point in the history
Most backed-up files are more than large enough to quickly fill network
buffers.
  • Loading branch information
hansmi committed Nov 21, 2022
1 parent f64d26f commit bb3315a
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions internal/snapshotstream/stream.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package snapshotstream

import (
"bufio"
"compress/gzip"
"crypto/sha256"
"encoding/hex"
Expand Down Expand Up @@ -93,21 +92,15 @@ func (s *Stream) Status() api.DownloadStatus {
}

func (s *Stream) writeTo(w io.Writer) (err error) {
bufWriter := bufio.NewWriterSize(w, 1024*1024)

defer func() {
multierr.AppendInto(&err, bufWriter.Flush())
}()

var archiveWriter io.Writer
var compressionFlush func() error

switch s.format {
case api.ArchiveTar:
archiveWriter = bufWriter
archiveWriter = w

case api.ArchiveTarGzip:
gzipWriter := gzip.NewWriter(bufWriter)
gzipWriter := gzip.NewWriter(w)
gzipWriter.Header.Name = strings.TrimSuffix(filepath.Base(s.Filename), filepath.Ext(s.Filename))
gzipWriter.Header.Comment = fmt.Sprintf("Prometheus snapshot %s", s.name)

Expand Down

0 comments on commit bb3315a

Please sign in to comment.