Browse Source

refactor buffer pool

pull/1960/head
Chris Lu 4 years ago
parent
commit
1f984d2645
  1. 2
      weed/command/filer.go
  2. 23
      weed/operation/buffer_pool.go
  3. 5
      weed/operation/upload_content.go

2
weed/command/filer.go

@ -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,
})

23
weed/operation/buffer_pool.go

@ -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)
}

5
weed/operation/upload_content.go

@ -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)))

Loading…
Cancel
Save