Skip to content
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

remove jmx_enabled option that causes memory leak #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicobrevin
Copy link

I've noticed that using the jmx_enabled option causes a memory leak. Each request creates a new JmxReporter, which is registered with the MetricsRegistry and never removed.

This commit takes away the jmx_enabled option in exchange for helper methods that let you set up a default jmx reporter during rack up or however you initialise your application.

@nicobrevin
Copy link
Author

I've got a manual test case to reproduce, just in case you're interested:

# memory-leak.rb
require 'rubygems'
require 'rack'

require 'slf4j-api'
require 'metrics-core'
require 'metrics-annotation'

require 'jruby-rack-metrics'

leaky = true

if ! leaky
  com.yammer.metrics.reporting.JmxReporter.startDefault(com.yammer.metrics.Metrics.defaultRegistry)
end

app = Rack::Builder.new do
  use JrubyRackMetrics::Monitor, :jmx_enabled => leaky
  run (proc do |env|
      # the more possible statuses, the more metrics in each jmxreporter, so                                                                                                                                                       
      # the quicker this will die                                                                                                                                                                                                  
      possibles = [200, 302, 404, 503]
      status = possibles[rand(possibles.length)]
      [status, {"Content-Type" => "text/html"}, "Hello Rack!"]
  end)
end

Rack::Handler.get('webrick').run(app)

Run this like so:

jruby -J-Xmx64m -Ilib -Ipath/to/jars memory-leak.rb

And in another window, run apache bench:

ab -n 100000 -c 10 http://localhost:8080/

Once it is running, hook up jconsole and watch memory usage increase, response times go down and eventually it will ground to a halt. Switch leaky to false and memory usage stays steady.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant