-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metrics library leaks memory #897
Comments
The metrics library does not indicate that we need to do anything to clean up unused meters, so I would expect the go garbage-collector to take care of them eventually, once the broker itself is GCed or re-opened. @slaunay perhaps you can shed some light? |
The meter abstraction relies on a single goroutine for computing rates instead of one per meter. This means that each meter is referenced by a global This would lead to memory leaks:
It does not seem possible in Looks like this needs to be fixed in |
Before go-metircs solving this leak problem, i think disable metrics collection |
Me too. When frequence Call Client.GetOffset and Client.Close, Cause Memory Leak. Because Client.GetOffset will call Broker.Open. |
@lday0321 You can also workaround that memory leak without requiring changes upstream. Disabling the metrics by default to re-enable them later on sounds confusing to me against the end user. @soar-zhengjian I believe that would be the case if you were to "reopen" a |
@slaunay according to my test, after "reopen" Broker 778827 times, the pprof shows that the memory leak will be 939.05MB (almost 1k/time)
|
Thanks for providing those statistics @lday0321. Are you allocating a new |
Yes, i use a new client each time. Actually, i use the sarama-cluster's NewConsumer method |
You should be able to mostly avoid the memory leak by reusing either your own Using a single Hopefully the memory leak can be fixed in the metrics library soon as the maintainer recently shown interest in rcrowley/go-metrics#197 😀. |
@slaunay thanks for your suggestion! Is it still a good practice of using single |
@lday0321 I think reusing That being if you have that much topics in a single cluster then Apache Kafka might not be the best technology, an AMQP broker like RabbitMQ could be a better fit depending on your use case. |
(the PR for being able to stop unused meters/counters has been merged rcrowley/go-metrics#206) |
Fixed (or enough, anyway) by #991. |
Versions
Please specify real version numbers or git SHAs, not just "Latest" since that changes fairly regularly.
Sarama Version:46dabe0f34a162d428640a0e9714eea9079e7ee2
Kafka Version: kafka_2.11-0.10.1.0.tgz
Go Version:1.8
Configuration
What configuration values are you using for Sarama and Kafka?
Logs
When filing an issue please provide logs from Sarama and Kafka if at all
possible. You can set
sarama.Logger
to alog.Logger
to capture Sarama debugoutput.
Problem Description
the Problem is metrics lib. the function is below.
When call Broker.Open cause new StandardMeter,but when Broker.Close does't destory it.
func NewMeter() Meter {
if UseNilMetrics {
return NilMeter{}
}
m := newStandardMeter()
arbiter.Lock()
defer arbiter.Unlock()
arbiter.meters = append(arbiter.meters, m)
if !arbiter.started {
arbiter.started = true
go arbiter.tick()
}
return m
}
The text was updated successfully, but these errors were encountered: