kenichi / angelo

Sinatra-like DSL for Reel that supports WebSockets and SSE
Other
303 stars 23 forks source link

Angelo leaking memory? #54

Open mighe opened 9 years ago

mighe commented 9 years ago

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.

kenichi commented 9 years ago

@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?

mighe commented 9 years ago

@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 commented 9 years ago

Here the results of my tests:

digitalextremist commented 9 years ago

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

mighe commented 9 years ago

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: