我在 unicorn 中寻找但没有找到类似于 gunicorn 的 max_requests 或 apache 的 MaxRequestsPerChild 的 max-requests-per-worker 选项。
它存在吗?
如果没有,有没有人实现过?
我正在考虑将它放在我有 oobgc 的文件中,因为无论如何它都会在每个请求之后得到控制。那个听起来是对的吗?
问题是我的 unicorn worker 越来越大越来越胖,垃圾收集占用了越来越多的 CPU。
最佳答案
我刚刚发布了' unicorn-worker-killer ' gem 。这使您能够根据 1) 最大请求数和 2) 进程内存大小 (RSS) 杀死 Unicorn 工作线程,而不会影响请求。它真的很容易使用。首先,请将此行添加到您的 Gemfile
.
gem 'unicorn-worker-killer'
然后,请将以下几行添加到您的
config.ru
.# Unicorn self-process killer
require 'unicorn/worker_killer'
# Max requests per worker
use Unicorn::WorkerKiller::MaxRequests, 3072, 4096
# Max memory size (RSS) per worker
use Unicorn::WorkerKiller::Oom, (256*(1024**2)), (384*(1024**2))
强烈建议随机设置阈值以避免一次杀死所有 worker 。
关于ruby-on-rails - unicorn 中每个 worker 的最大请求数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7771294/