我运行一个红宝石上的rails网站,处理电子邮件-电子邮件是直接转储到网络应用程序通过一个帖子从后缀。
有时,我会收到大量的电子邮件,导致CPU使用量的长时间激增,这让我的VPS提供商对我不满是可以理解的。这些电子邮件不需要及时处理--它们只需要(最终)被处理。
显然,我不能简单地处理这个过程,因为它只考虑我的VPS上的cpu使用情况,而不能考虑其他VPS上的cpu使用情况。
我已经找到了一个名为cpulimit的实用程序,您将对特定进程的cpu使用设置硬限制。(如20%)。对于这个目的来说,这似乎是理想的,但我无法实现与apache/奎的集成。
乘客为每个服务器启动一个红宝石进程,并定期重新启动它们。每次pid都会改变。需要给出一个pid值才能起作用。
有人知道我如何让乘客在启动这个特定的虚拟主机时发出这个命令吗?
发布于 2012-04-14 03:59:49
我不确定这是否是理想的解决方案,但由于没有任何更好的想法,我编写了一个简短的脚本来监控这个问题,并为我调用cpulimit。
我已经把它写在下面,以防对其他人有用。
#!/home/dgs/.rvm/rubies/ruby-1.9.3-p125-perf/bin/ruby
# script to check for mail server processes and enforce a cpulimit on them
# cmd to get the pid of the process you want to limit.
YOU WOULD NEED TO MAKE THIS RELEVANT TO YOU
CMD='ps -ef | grep mailserver | grep Rack | grep -v grep | awk "{print \$2}"'
# how often to check
PERIOD = 60
#array to hold list of the currently limitied processes
limiting = []
while true
processes = `#{CMD}`.split("\n")
# iterate thru the newly found processes, limiting any that
# aren't already being limited
processes.each do |p|
if ! limiting.include? p
system "cpulimit -p #{p} -l 10 -z &"
limiting << p
end
end
# check if any old processes have been killed
limiting.each do |p|
begin
Process.getpgid( p.to_i )
rescue Errno::ESRCH
limiting.delete p
end
end
sleep PERIOD
endhttps://serverfault.com/questions/379302
复制相似问题