Commit 4a0e6eb5 authored by sunjiapeng's avatar sunjiapeng Committed by Han-Wen Nienhuys

Fix sync.Pool leak

There is a sync.Pool leak in server.go, which triggers in case of
multi-threaded loads.

Benchmarks:

env: Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz (8core 16procs)
go test -bench="BenchmarkGoFuseRead" -benchmem

old:

2       10992 92501 ns/op 22671.71 MB/s 536981 B/op 196 allocs/op
4       19068 57959 ns/op 36183.44 MB/s 151877 B/op 170 allocs/op
8       27729 43796 ns/op 47884.39 MB/s 29068 B/op 162 allocs/op
16      28674 41403 ns/op 50651.65 MB/s 6704 B/op 160 allocs/op

fixed:

2       23667 46589 ns/op 45014.20 MB/s 5357 B/op 167 allocs/op
4       27753 42327 ns/op 49546.77 MB/s 4999 B/op 161 allocs/op
8       29648 40806 ns/op 51392.81 MB/s 4904 B/op 160 allocs/op
16      29389 40763 ns/op 51447.07 MB/s 4848 B/op 160 allocs/op

Change-Id: I062928203df5603ebca04c08c4d428d385f99c2c
parent 4c25c9c1
......@@ -305,9 +305,6 @@ func handleEINTR(fn func() error) (err error) {
// Returns a new request, or error. In case exitIdle is given, returns
// nil, OK if we have too many readers already.
func (ms *Server) readRequest(exitIdle bool) (req *request, code Status) {
req = ms.reqPool.Get().(*request)
dest := ms.readPool.Get().([]byte)
ms.reqMu.Lock()
if ms.reqReaders > ms.maxReaders {
ms.reqMu.Unlock()
......@@ -316,6 +313,9 @@ func (ms *Server) readRequest(exitIdle bool) (req *request, code Status) {
ms.reqReaders++
ms.reqMu.Unlock()
req = ms.reqPool.Get().(*request)
dest := ms.readPool.Get().([]byte)
var n int
err := handleEINTR(func() error {
var err error
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment