Skip to content

Commit

Permalink
Merge pull request #1 from aeoluswing/fix-uplimit-20210326
Browse files Browse the repository at this point in the history
Optimize the performance of the copy phase during the upload process
  • Loading branch information
aeoluswing committed Mar 26, 2021
2 parents b6200a8 + a60a9c4 commit 1258ac7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion httpstaticserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"
"time"

"regexp"
Expand Down Expand Up @@ -248,7 +249,13 @@ func (s *HTTPStaticServer) hUploadOrMkdir(w http.ResponseWriter, req *http.Reque
http.Error(w, "File create "+err.Error(), http.StatusInternalServerError)
return
}
_, copyErr = io.Copy(dst, file)
// Note: very large size file might cause poor performance
// _, copyErr = io.Copy(dst, file)
// use sync.Pool caching buf to reduce gc ratio
var bufPtr = &sync.Pool{
New: func() interface{} { return make([]byte, 32*1024) },
}
_, copyErr = io.CopyBuffer(dst, file, bufPtr.Get().([]byte))
dst.Close()
// }
if copyErr != nil {
Expand Down

0 comments on commit 1258ac7

Please sign in to comment.