Hello! Can anyone explain why my Unicorn installation (for RoR site) have so many worker threads? * screenshot: http://i.stack.imgur.com/U9TFR.png * unicorn.rb: https://gist.github.com/907th/4995323 Thanks!
Alexey Chernenkov <laise at pisem.net> wrote:> Hello! > > Can anyone explain why my Unicorn installation (for RoR site) have so > many worker threads? > > * screenshot: http://i.stack.imgur.com/U9TFR.png > * unicorn.rb: https://gist.github.com/907th/4995323It''s probably some gem/library you''re using which spawns threads behind your back. Ruby 1.9/2.0 only has one extra thread per-process for accepting signals.
> * screenshot: http://i.stack.imgur.com/U9TFR.pngwhich command did you run to show that list?
2013/3/1 Alejandro Riera <ariera at gmail.com>:> which command do you run to show that list? > > On 1 March 2013 18:41, Eric Wong <normalperson at yhbt.net> wrote: >> >> Alexey Chernenkov <laise at pisem.net> wrote: >> > Can anyone explain why my Unicorn installation (for RoR site) have so >> > many worker threads? >> > >> > * screenshot: http://i.stack.imgur.com/U9TFR.png >> > * unicorn.rb: https://gist.github.com/907th/4995323 >> >> It''s probably some gem/library you''re using which spawns threads behind >> your back. Ruby 1.9/2.0 only has one extra thread per-process for >> accepting signals.Screenshot? Its `htop` command with tree (F5) view.
2013/3/1 Eric Wong <normalperson at yhbt.net>:> Alexey Chernenkov <laise at pisem.net> wrote: >> >> Can anyone explain why my Unicorn installation (for RoR site) have so >> many worker threads? >> * screenshot: http://i.stack.imgur.com/U9TFR.png >> * unicorn.rb: https://gist.github.com/907th/4995323 >> > > It''s probably some gem/library you''re using which spawns threads behind > your back. Ruby 1.9/2.0 only has one extra thread per-process for > accepting signals. >Could you advise me how I can determine which gem causes the problem?
>>> > * screenshot: http://i.stack.imgur.com/U9TFR.png >>> > * unicorn.rb: https://gist.github.com/907th/4995323 >> which command do you run to show that list? > > Screenshot? Its `htop` command with tree (F5) view.I have just one worker. If I run top I just see one master and one worker. But with htop there are 3 masters and 3 workers, each of them with a different pid. This is a surprise to me too. I''m runnnig ruby 1.9.2.
NewRelic and Airbrake are popular gems which spawns threads. Unfortunately I don''t think there is a silver bullet to detect which gems are doing that. You have to investigate it step by step. For example, you can create a new Rails app with the Gemfile(assuming you use bundler), config and initializers. If you succeeded to reproduce the problem with the small app, the rest of research would not be difficult. You remove a gem one by one and restart app and you may want to make some requests, then check the number of threads. If the number of threads is reduced, that''s would be it. Or maybe you can grep your gem library directory with some keywords like "Thread" or "Proc"? If you install gem library to specific path (--path option on Bundler) for the application, you can avoid look at other gems installed by other ruby application. http://gembundler.com/v1.2/bundle_install.html I don''t think that the problem is related to Unicorn though. Good luck :-) On 1 March 2013 19:14, Alejandro Riera <ariera at gmail.com> wrote:> > >>> > * screenshot: http://i.stack.imgur.com/U9TFR.png > >>> > * unicorn.rb: https://gist.github.com/907th/4995323 > >> which command do you run to show that list? > > > > Screenshot? Its `htop` command with tree (F5) view. > > > I have just one worker. If I run top I just see one master and one > worker. But with htop there are 3 masters and 3 workers, each of them > with a different pid. This is a surprise to me too. I''m runnnig ruby > 1.9.2. > _______________________________________________ > Unicorn mailing list - mongrel-unicorn at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-unicorn > Do not quote signatures (like this one) or top post when replying
Alexey Chernenkov <laise at pisem.net> wrote:> 2013/3/1 Eric Wong <normalperson at yhbt.net>: > > Alexey Chernenkov <laise at pisem.net> wrote: > >> > >> Can anyone explain why my Unicorn installation (for RoR site) have so > >> many worker threads? > >> * screenshot: http://i.stack.imgur.com/U9TFR.png > >> * unicorn.rb: https://gist.github.com/907th/4995323 > >> > > > > It''s probably some gem/library you''re using which spawns threads behind > > your back. Ruby 1.9/2.0 only has one extra thread per-process for > > accepting signals. > > > Could you advise me how I can determine which gem causes the problem?What Tatsuya said. Really, you should never hesitate to grep/scan/read the source of _everything_ you''re running. For C extensions, check for the pthread_create() function, too. Also, any existing libraries your C/FFI extensions might link to... If you''re on Linux, you can probably track it down a little faster via "strace -f -e clone" (clone() is the underlying syscall used for both fork() and pthread_create()).