evaluate using sync.Pool over custom freelists
stapelberg opened this issue · 3 comments
sync.Pool is a per-P (logical processor) data structure (with custom runtime support), which might come with performance wins.
I have do benchmark, no better then now.
Thanks! Let’s close this then. Could you share a link to the code you benchmarked?
I have mount a S3-like storage service in local.
Step:
ReadOp -> Fasthttp -> StorageServer's UnixSock
I test a file with 8GB size in memory bucket with dd
.
dd if=/path/to/fs/8G.mp4 of=/dev/null bs=128k
Before:
9324265472 bytes (9.3 GB, 8.7 GiB) copied, 12.2228 s, 763 MB/s
After:
9324265472 bytes (9.3 GB, 8.7 GiB) copied, 12.345 s, 755 MB/s
This my change, removed lock:
`
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) getInMessage() *buffer.InMessage {
x := c.inMessages.Get().(*buffer.InMessage)
if x == nil {
x = &buffer.InMessage{}
}
return x
}
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) putInMessage(x *buffer.InMessage) {
c.inMessages.Put(x)
}
////////////////////////////////////////////////////////////////////////
// buffer.OutMessage
////////////////////////////////////////////////////////////////////////
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) getOutMessage() *buffer.OutMessage {
x := c.outMessages.Get().(*buffer.OutMessage)
if x == nil {
x = &buffer.OutMessage{}
}
x.Reset()
return x
}
// LOCKS_EXCLUDED(c.mu)
func (c *Connection) putOutMessage(x *buffer.OutMessage) {
c.outMessages.Put(x)
}
`
May have any trick for best perf?