refactor buffer pool

This commit is contained in:
Chris Lu 2021-04-01 02:20:00 -07:00
parent b5880334fc
commit 1f984d2645
3 changed files with 26 additions and 4 deletions

View file

@ -174,7 +174,7 @@ func (fo *FilerOptions) startFiler() {
Host: *fo.ip,
Port: uint32(*fo.port),
Cipher: *fo.cipher,
SaveToFilerLimit: *fo.saveToFilerLimit,
SaveToFilerLimit: int64(*fo.saveToFilerLimit),
Filers: peers,
ConcurrentUploadLimit: int64(*fo.concurrentUploadLimitMB) * 1024 * 1024,
})

View file

@ -0,0 +1,23 @@
package operation
import (
"github.com/valyala/bytebufferpool"
"sync/atomic"
)
var bufferCounter int64
func GetBuffer() *bytebufferpool.ByteBuffer {
defer func() {
atomic.AddInt64(&bufferCounter, 1)
// println("+", bufferCounter)
}()
return bytebufferpool.Get()
}
func PutBuffer(buf *bytebufferpool.ByteBuffer) {
defer func() {
atomic.AddInt64(&bufferCounter, -1)
// println("-", bufferCounter)
}()
bytebufferpool.Put(buf)
}

View file

@ -19,7 +19,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/security"
"github.com/chrislusf/seaweedfs/weed/util"
"github.com/valyala/bytebufferpool"
)
type UploadResult struct {
@ -190,8 +189,8 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
}
func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) error, filename string, isGzipped bool, originalDataSize int, mtype string, pairMap map[string]string, jwt security.EncodedJwt) (*UploadResult, error) {
buf := bytebufferpool.Get()
defer bytebufferpool.Put(buf)
buf := GetBuffer()
defer PutBuffer(buf)
body_writer := multipart.NewWriter(buf)
h := make(textproto.MIMEHeader)
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, fileNameEscaper.Replace(filename)))