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

memory leak with timers #770

Open
kostya opened this issue Dec 9, 2017 · 2 comments
Open

memory leak with timers #770

kostya opened this issue Dec 9, 2017 · 2 comments

Comments

@kostya
Copy link

kostya commented Dec 9, 2017

this program eats 2Gb in 10 hours. i think this related somehow to gem timers (also there was a leak in it before #455). ruby 2.4.1p111, celluloid: "0.17.3", timers: "4.1.2", Ubuntu 12.04.1 LTS

require 'celluloid'

class A
  include Celluloid

  def initialize
    @timer = every(0.5) {}
  end

  def stop
    @timer.cancel
    terminate
  end
end

p Celluloid::VERSION
p Timers::VERSION

loop do
  actors = Array.new(50) { A.new }
  sleep 10.0
  actors.each &:stop
end
@kostya
Copy link
Author

kostya commented Dec 9, 2017

actually seems this is not about timers, this leak also (1Gb in 5 hours):

require 'bundler/setup'
require 'celluloid'

class A
  include Celluloid

  def initialize
  end

  def stop
    terminate
  end
end

p Celluloid::VERSION
p Timers::VERSION

loop do
  actors = Array.new(50) { A.new }
  sleep 10.0
  actors.each &:stop
end

@perlun
Copy link
Contributor

perlun commented Jul 2, 2018

FWIW, I am also seeing similar but not entirely identical behavior with Celluloid Notifications. Only on JRuby, works fine on MRI.

The script below will use up about 4 GiB in 5 minutes. Some of this will be reclaimed on GC, but even so, there is still an unreasonably large amount of memory being retained.

require 'bundler/setup'
require 'celluloid'
require 'celluloid/autostart'

class Subscriber
  include Celluloid
  include Celluloid::Notifications

  def initialize
    subscribe('errors', :error)
    puts 'Subscriber initialized'
  end

  def error(topic, data)
    #puts 'got it'
  end
end

class Publisher
  extend Celluloid::Notifications

  def self.publish_message(error)
    publish(
      'errors',
      error: error
    )
  end
end

p Celluloid::VERSION

subscriber = Subscriber.new

loop do
  Publisher.publish_message('dummy error')
end

Are we using Celluloid Notifications in the completely wrong way or is there indeed a bug in Celluloid/JRuby here?

(A longer writeup about how I landed here: http://perlun.eu.org/en/2018/06/28/jruby-memory-leak-in-production)

@tarcieri tarcieri reopened this Jan 15, 2019
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

No branches or pull requests

3 participants