aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@uber.com>2021-04-01 02:20:00 -0700
committerChris Lu <chris.lu@uber.com>2021-04-01 02:20:00 -0700
commit1f984d26453bc97c95a8aa51e69d05ac74942685 (patch)
treeae5578554257d16edab838750cf36f2af329a835
parentb5880334fce31d1c4d728b2ca5c5141ef11b908a (diff)
downloadseaweedfs-1f984d26453bc97c95a8aa51e69d05ac74942685.tar.xz
seaweedfs-1f984d26453bc97c95a8aa51e69d05ac74942685.zip
refactor buffer pool
-rw-r--r--weed/command/filer.go2
-rw-r--r--weed/operation/buffer_pool.go23
-rw-r--r--weed/operation/upload_content.go5
3 files changed, 26 insertions, 4 deletions
diff --git a/weed/command/filer.go b/weed/command/filer.go
index 82994b971..e9e3237df 100644
--- a/weed/command/filer.go
+++ b/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,
})
diff --git a/weed/operation/buffer_pool.go b/weed/operation/buffer_pool.go
new file mode 100644
index 000000000..4003f7d70
--- /dev/null
+++ b/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)
+}
diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go
index 9957a04cd..e891ae03b 100644
--- a/weed/operation/upload_content.go
+++ b/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)))