log: use sync.Pool to reduce allocations #46285
Labels
FeatureRequest
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Investigating a server application with a larger number of active
log.Loggers
(with different prefixes) I've noticed that memory consumption kept growing andpprof
showed memory consumed inlog.Output
. It seems that the reason is the allocated, grow-only buffer in conjunction with extensive logging of e.g. HTTP traffic, seego/src/log/log.go
Line 178 in 2ebe77a
What did you expect to see?
Flat memory consumption for logging, almost flat total.
What did you see instead?
Growing memory consumption as more live objects with expensive loggers are added.
I would like to suggest to make
log.Logger
use a sync pool like this:where
Output
becomes:That way particulary long log lines would no longer cause memory consumption at the cost of additional allocations. Might also chose a higher limit for putting resources back to the pool.
Would be happy to provide a PR.
The text was updated successfully, but these errors were encountered: