angelo icon indicating copy to clipboard operation
angelo copied to clipboard

Angelo leaking memory?

Open mighe opened this issue 9 years ago • 5 comments

Last night my server was killed by the OS because it was using too much memory. Try this simple code watching the memory usage.

require 'angelo'

class AngeloStressTest < Angelo::Base

  get '/' do
    'hello ' * 10E5
  end

  get '/gc/' do
    GC.start
    'gc started'
  end


end

s = AngeloStressTest.run!

After every request the memory usage increases and even invoking the garbage collector it never returns to the initial (more or less 33 MB on my system) or the previous value.

mighe avatar Apr 14 '15 16:04 mighe

@mighe i fire this up and see it at around 43mb, then hit the route a few times and it peaks at around 105mb, but drops back to 51mb every time i hit /gc. i tried the same things with pure reel, and pure sinatra; sinatra/puma definitely uses less mem, but the pure reel is only slightly less mem and i see pretty much the same behavior with each. not that angelo isn't leaking, it very well may be... i'm wondering if piping those large "event" messages through celluloid's mailbox system could be a problem?

kenichi avatar Apr 14 '15 17:04 kenichi

@kenichi which angelo/reel version have you used for this test? I'm using angelo 0.4.1 with reel 0.5.0 under MacOs

mighe avatar Apr 14 '15 17:04 mighe

Here the results of my tests:

  • after start: 34mb
  • after 2 requests: 82mb
  • gc: 56 mb
  • 4 other reqs: 124mb
  • gc: 64 mb

mighe avatar Apr 14 '15 17:04 mighe

I wonder if this relates to celluloid/celluloid#463 ... shot in the dark.

digitalextremist avatar Apr 15 '15 01:04 digitalextremist

I found another serious issue in dependecy angelo stack. I was trying to understand whether nio4r could impact that memory leak (since it is one of the c ext), but if I try to set ENV['NIO4R_PURE] = 'true' before requiring angelo, I get

ThreadError: deadlock; recursive locking
    /xxx/nio4r-1.1.0/lib/nio/selector.rb:40:in `synchronize'
    /xxx/nio4r-1.1.0/lib/nio/selector.rb:40:in `deregister'
    /xxx/nio4r-1.1.0/lib/nio/monitor.rb:40:in `close'
    /xxx/celluloid-io-0.16.2/lib/celluloid/io/reactor.rb:52:in `wait'
    /xxx/celluloid-io-0.16.2/lib/celluloid/io/reactor.rb:21:in `wait_readable'
    /xxx/celluloid-io-0.16.2/lib/celluloid/io.rb:53:in `wait_readable'
    /xxx/celluloid-io-0.16.2/lib/celluloid/io/tcp_server.rb:19:in `accept'
    /xxx/reel-0.5.0/lib/reel/server.rb:38:in `block in run'
    /xxx/reel-0.5.0/lib/reel/server.rb:38:in `loop'
    /xxx/reel-0.5.0/lib/reel/server.rb:38:in `run'
    /xxx/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
    /xxx/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
    /xxx/celluloid-0.16.0/lib/celluloid/calls.rb:122:in `dispatch'
    /xxx/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'
    /xxx/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'
    /xxx/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'
    /xxx/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'
    /xxx/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'

:crying_cat_face:

mighe avatar Apr 18 '15 16:04 mighe