Search code examples
ruby-on-railsrubyunicornsidekiq

Explanation for output of pstree with unicorn and sidekiq running


Below is the output of my pstree command. I have 2 unicorn workers, Sidekiq running concurrency set at 25.

Examining the pids in my app directory, I know that 10366 is sidekiq and 974 is unicorn master

Questions:

  1. Why does sidekiq spawn that many workers?
  2. What is 978 and 17699 doing there?
  3. If 17698 is the worker, why is there 17702 and 17703? (Same goes for 26146)

Some context:

I'm using cap unicorn:add_worker/remove_worker pretty frequently, because I am noticing that the memory is growing continuously. Could this be the issue where the workers are not removed cleanly?

Thank you!

  ├─ruby,974
  │   ├─ruby,17698
  │   │   ├─{ruby},17702
  │   │   └─{ruby},17703
  │   ├─ruby,26146
  │   │   ├─{ruby},26150
  │   │   └─{ruby},26151
  │   ├─{ruby},978
  │   └─{ruby},17699
  ├─ruby,10366
  │   ├─{ruby},10407
  │   ├─{ruby},10408
  │   ├─{ruby},10409
  │   ├─{ruby},10410
  │   ├─{ruby},10454
  │   ├─{ruby},10455
  │   ├─{ruby},10545
  │   ├─{ruby},10806
  │   ├─{ruby},10807
  │   ├─{ruby},10809
  │   ├─{ruby},10810
  │   ├─{ruby},10811
  │   ├─{ruby},10812
  │   ├─{ruby},10813
  │   ├─{ruby},10814
  │   ├─{ruby},10817
  │   ├─{ruby},10818
  │   ├─{ruby},10819
  │   ├─{ruby},10821
  │   ├─{ruby},10824
  │   ├─{ruby},10825
  │   ├─{ruby},10828
  │   ├─{ruby},10829
  │   ├─{ruby},10830
  │   ├─{ruby},10833
  │   ├─{ruby},10836
  │   ├─{ruby},10838
  │   ├─{ruby},10839
  │   ├─{ruby},10840
  │   ├─{ruby},10843
  │   ├─{ruby},10844
  │   ├─{ruby},10860
  │   ├─{ruby},10862
  │   ├─{ruby},10863
  │   ├─{ruby},10864
  │   ├─{ruby},10866
  │   ├─{ruby},10867
  │   ├─{ruby},10872
  │   ├─{ruby},10874
  │   ├─{ruby},10878
  │   ├─{ruby},10879
  │   ├─{ruby},10881
  │   ├─{ruby},10882
  │   ├─{ruby},16646
  │   ├─{ruby},16647
  │   ├─{ruby},16648
  │   ├─{ruby},16649
  │   ├─{ruby},16650
  │   ├─{ruby},16658
  │   ├─{ruby},16659
  │   └─{ruby},16660

Solution

  • This tree is showing you both processes (with no braces) and threads (in {curly braces}).

    A sidekiq worker has one process, but 20 threads (by default).

    A unicorn server has a master process with several threads and forks 2 background worker processes, each having several threads.

    If your unicorn workers are leaking memory, it's most likely due to a memory leak in your code.