Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/aeoluswing/gohttpserver i…
Browse files Browse the repository at this point in the history
…nto aeoluswing-master
  • Loading branch information
codeskyblue committed Mar 30, 2021
2 parents f706365 + e8af978 commit 86aeecf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 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,16 @@ 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
bufPool := sync.Pool{
New: func() interface{} { return make([]byte, 32*1024) },
}
buf := bufPool.Get().([]byte)
_, copyErr = io.CopyBuffer(dst, file, buf)
defer bufPool.Put(&buf)
dst.Close()
// }
if copyErr != nil {
Expand Down

0 comments on commit 86aeecf

Please sign in to comment.