- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
这里基本上有3个问题:
1) Unicorn 似乎在稳定地填满所有 RAM,导致我手动移除 worker 。
2) Unicorn 似乎出于某种原因正在产生更多的 worker ,尽管我指定了固定数量的 worker (其中 7 个)。这在一定程度上导致了 RAM 堆积,这也导致我手动删除工作人员。
3) 零停机部署在我的案例中是不可靠的。有时它会接受更改,有时我会收到网关超时。每次部署都会成为压力很大的情况。
我不太喜欢使用 Monit,因为它会在不等待工作人员完成请求处理的情况下杀死工作人员。
那么,这正常吗?其他使用 Unicorn 部署的人是否有同样的问题,即 RAM 不受控制地增长?
还有,生成的 worker 数量与定义的 worker 数量不匹配的地方?
另一种选择是 unicorn worker killer ,我会在阅读后尝试一下 Unicorn Eating Memory .
小更新:
所以到了 New Relic 告诉我内存几乎 95% 的地步。所以我不得不杀了一个 worker 。有趣的是,杀掉那个 worker 会使内存减少很多,如下图所示。
这是怎么回事?
作为引用,这是我的 unicorn.rb
和 unicorn_init.sh
。很想有人告诉我哪里有错误。
unicorn.rb
root = "/home/deployer/apps/myapp/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.stderr.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.myapp.sock"
worker_processes 7
timeout 30
preload_app true
before_exec do |_|
ENV["BUNDLE_GEMFILE"] = '/home/deployer/apps/myapp/current/Gemfile'
end
before_fork do |server, worker|
# Disconnect since the database connection will not carry over
if defined? ActiveRecord::Base
ActiveRecord::Base.connection.disconnect!
end
old_pid = "#{root}/tmp/pids/unicorn.pid.oldbin`"
if old_pid != server.pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
sleep 1
end
after_fork do |server, worker|
# Start up the database connection again in the worker
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
Redis.current.quit
Rails.cache.reconnect
end
unicorn_init.sh
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deployer/apps/myapp/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; BUNDLE_GEMFILE=/home/deployer/apps/myapp/current/Gemfile bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=deployer
set -u
OLD_PIN="$PID.oldbin"
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}
run () {
if [ "$(id -un)" = "$AS_USER" ]; then
eval $1
else
su -c "$1" - $AS_USER
fi
}
case "$1" in
start)
sig 0 && echo >&2 "Already running" && exit 0
run "$CMD"
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload)
sig USR2 && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
run "$CMD"
;;
upgrade)
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
then
n=$TIMEOUT
while test -s $OLD_PIN && test $n -ge 0
do
printf '.' && sleep 1 && n=$(( $n - 1 ))
done
echo
if test $n -lt 0 && test -s $OLD_PIN
then
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
exit 1
fi
exit 0
fi
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
run "$CMD"
;;
reopen-logs)
sig USR1
;;
*)
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
exit 1
;;
esac
最佳答案
你似乎有两个问题:1)你在优雅重启的协调上有错误导致老 unicorn worker 和老主人坚持; 2) 您的应用程序(不是 unicorn )正在泄漏内存。
对于前者,查看您的 before_fork
代码,您似乎正在使用来自 the example config 的内存限制方法。但是,您在 .oldbin
文件名中有一个拼写错误(末尾有一个无关的反引号),这意味着您永远不会向旧进程发出信号,因为您无法从不存在的进程中读取 pid文件。
对于后者,您将不得不进行调查和演练。在您的应用程序中查找随时间累积数据的缓存语义;仔细检查全局变量、类变量和类实例变量的所有使用,它们可以保留请求之间的数据引用。运行一些内存配置文件来描述您的内存使用情况。您可以通过在工作人员增长超过某个上限时将其杀死来减轻内存泄漏; unicorn-worker-killer让这一切变得简单。
关于ruby-on-rails - Unicorn 内存使用几乎填满了所有 RAM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18158496/
如果我们想访问数组的元素 i,我们会这样做:i *(每个元素的大小)+ 数组的起始地址 = 我们需要访问的元素的内存位置。然后 CPU 直接访问 RAM 中的该位置。这是怎么发生的? 假设我要定位的内
考虑以下 python 代码 with open(sys.argv[2], 'r') as fin, \ open(sys.argv[3], 'w') as fout:
基本上我在 Centos 6.2 16GB 系统上运行我的世界服务器 我通过 rtoolkit 引导来启动我的服务器,现在我分配它使用 12GB,但它使用的 muc 比这多,我不知道为什么。我运行此命
我正在开发一个小型 x86 内核。我正在访问并尝试读取 GRUB 在多重引导 header 中提供的内存映射。我有一个 Intel i3 cpu 和 4 GiB 的 RAM。在这台机器上运行时,我正在
我有 3 GB 内存。有没有办法只为 C++ 应用程序分配 512MB 的 RAM? 否则 有没有办法暂时将我的 RAM 减少到 512MB 以进行测试? 谢谢,阿肖克 最佳答案 使用SetProce
我的一个 friend 告诉我,在 x86 架构上,DMA Controller 无法在两个不同的 RAM 位置之间传输。它只能在RAM和外设(如PCI总线)之间传输。 这是真的吗? 因为 AFAIK
做一些分析(内存和速度) 我一直被 win7 似乎分配的 RAM 正好是我要求的两倍这一事实所困扰...注意这是我第一次在 win7 上进行这样的主动分析,所以我真的不知道会发生什么。 我在 win7
我经常玩 retrofit 版的 Minecraft。这样做的一个缺点是,每当我启动 Minecraft 时,编译所有模组都需要花费大量时间。这可能需要大约 15 分钟左右的时间,在我看来,这太长了。
我想编写一个内核模块,可以通过 DMA 将数据从 RAM 传输到 RAM。有一些帖子讨论这个,但我真的不明白。有人说可能,也有人说不可能。 如果我对 ldd3 的理解是正确的,RAM 到 RAM 的复
我正在寻找一种方法来查找总内存和正在使用的内存的单个熟值输出。 gwmi Win32_OperatingSystem | select TotalVisibleMemorySize, FreePhys
我在 Heroku 上有一个网络应用程序,我试图了解添加具有 1GB RAM 的 Memcached 实例与向我的 Postgres 服务器添加 1GB RAM 之间的区别/权衡。 如果我添加一个 M
在我的例子中,我有一个包含大约 6000 个实例化类的字典,其中每个类都有 1000 个属性变量,所有类型都是字符串或字符串列表。当我建立这本字典时,我的 RAM 变得非常高。有没有一种方法可以在将字
我的问题是:如果您用完了所有可用的视频内存,并尝试创建新纹理 (SDL),是否会自动使用普通内存而不是视频内存?或者,您是否必须尝试使用使用普通 ram 的表面 (SDL)?如果您出于任何原因无法
我在从 ram 地址获取值时遇到问题。 我有一些限制,即它必须是 C 代码,并且存储信息的地址由 u32 值给出,例如 0x001c0080。 环境是ARM的,我用的是eclipse sdk。我怎样才
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我正在尝试使用 GCC 编译器(标准 C)编译裸机应用程序。我使用 Cyclone V SoC 和 Cortex-A9 处理器。 eclipse DS-5。我收到这些错误 - “Region ram
如果 RAM 不是问题(我的服务器上有接近 200GB),是逐行读取更快还是将所有内容读入 RAM 并访问它?每行将是大约 200-500 个 unicode 字符的字符串。每个文件有近 200 万行
我在我的两台机器上运行以下命令: import os, sqlite3 import pandas as pd from feat_transform import filter_anevexp db
我正在尝试在我的一个项目中引入一些 CUDA 优化。但我认为我在这里做错了什么。我想实现一个简单的矩阵 vector 乘法 (result = matrix * vector)。但是当我想将结果复制回
#include #include #include #include #include #include using namespace std; char randomLetter()
我是一名优秀的程序员,十分优秀!