merge pull request
This commit is contained in:
@@ -54,6 +54,7 @@ type HTTPStaticServer struct {
|
||||
|
||||
indexes []IndexFileItem
|
||||
m *mux.Router
|
||||
bufPool sync.Pool // use sync.Pool caching buf to reduce gc ratio
|
||||
}
|
||||
|
||||
func NewHTTPStaticServer(root string) *HTTPStaticServer {
|
||||
@@ -70,6 +71,9 @@ func NewHTTPStaticServer(root string) *HTTPStaticServer {
|
||||
Root: root,
|
||||
Theme: "black",
|
||||
m: m,
|
||||
bufPool: sync.Pool{
|
||||
New: func() interface{} { return make([]byte, 32*1024) },
|
||||
},
|
||||
}
|
||||
|
||||
go func() {
|
||||
@@ -249,16 +253,12 @@ func (s *HTTPStaticServer) hUploadOrMkdir(w http.ResponseWriter, req *http.Reque
|
||||
http.Error(w, "File create "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// 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)
|
||||
buf := s.bufPool.Get().([]byte)
|
||||
defer s.bufPool.Put(buf)
|
||||
_, copyErr = io.CopyBuffer(dst, file, buf)
|
||||
defer bufPool.Put(&buf)
|
||||
dst.Close()
|
||||
// }
|
||||
if copyErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user