diff --git a/persistence.go b/persistence.go index 1eaa94b..605877e 100644 --- a/persistence.go +++ b/persistence.go @@ -2,6 +2,7 @@ package main import ( "archive/tar" + "bufio" "context" "encoding/json" "fmt" @@ -27,7 +28,8 @@ type DumpChunkName struct { func (that *GlobalBackfeedManager) HandleLoad(res http.ResponseWriter, req *http.Request) { defer req.Body.Close() - tarReader := tar.NewReader(req.Body) + reqBuffer := bufio.NewReader(req.Body) + tarReader := tar.NewReader(reqBuffer) existed := []string{} imported := []string{} recreate := req.URL.Query().Get("recreate") != "" @@ -153,7 +155,9 @@ func (that *GlobalBackfeedManager) HandleDump(res http.ResponseWriter, req *http WriteResponse(res, http.StatusNoContent, nil) return } - tarWriter := tar.NewWriter(res) + resBuf := bufio.NewWriterSize(res, 16*1024*1024) + defer resBuf.Flush() + tarWriter := tar.NewWriter(resBuf) defer tarWriter.Close() pipe := that.BackfeedRedis.Pipeline() writeError := func(err error) {