sidekiq memory usage reset

泪湿孤枕 提交于 2019-12-18 06:56:46

问题


I have Rails app which uses Sidekiq for background process. To deploy this application I use capistrano, ubuntu server and apache passenger. To start and restart Sidekiq I use capistrano-sidekiq gem. My problem is - when Sidekiq is running, amount of memory (RAM) used by Sidekiq is growing up. And when Sidekiq finished all processes (workers) it keeps holding a large amount of RAM and not reseting it.

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
ubuntu    2035 67.6 45.4 3630724 1838232 ?     Sl   10:03 133:59 sidekiq 3.5.0 my_app [0 of 25 busy]     

How to make Sidekiq to reset used memory after workers finished their work?


回答1:


Sidekiq uses thread to execute jobs. And threads share the same memory as the parent process. So if one job uses a lot of memory the Sidekiq process memory usage will grow up and won't be released by Ruby.

Resque uses another technique it executes every jobs in another process therefore when the job is done, the job's process exits and the memory is released.

One way to prevent your Sidekiq process from using too much memory is to use Resque's forking method.

You could have your job main method executed in another process and wait until that new process exits

ex:

class Job
  include Process

  def perform
    pid = fork do
      # your code
    end
    waitpid(pid)
  end
end


来源:https://stackoverflow.com/questions/32374919/sidekiq-memory-usage-reset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!