Ubuntu 16 上的 emfile 错误 运行 CouchDB
emfile error running CouchDB on Ubuntu 16
我最近升级到 Ubuntu 16 和 CouchDB 1.6。当我的服务器受到大量连接的冲击时,我会在 couch.log 中收到 emfile
错误。我以前见过这些错误,它们似乎与 https://wiki.apache.org/couchdb/Performance 中提到的系统资源限制有关。我相信我的主要问题是 ERL_MAX_PORTS
。我已经将我的 ulimit 增加到 40000(通过 PAM)并将 export ERL_MAX_PORTS=40000
添加到 /etc/default/couchdb。
Ubuntu 16 使用 systemd,所以我将 Environment="ERL_MAX_PORTS=40000"
添加到 /etc/systemd/system/multi-user.target.wants/couchdb.service 中的 [Service]
部分,但这并不似乎有效。
我什至尝试修改 /usr/bin/couchdb 并将 env ERL_MAX_PORTS=40000
添加到脚本的顶部。
唯一似乎有效的是当我从命令行手动 运行 couchdb 时,例如$ env ERL_MAX_PORTS=40000 && sudo /usr/bin/couchdb
。这不是一个理想的解决方案,我宁愿让它与 systemd 一起工作。
我之前在 Ubuntu14 上 运行ning CouchDB 1.5 并将我的系统资源限制(请参阅 https://wiki.apache.org/couchdb/Performance)增加到大约 40000,它可以毫无问题地处理许多连接。
有没有人有幸在 Ubuntu 16 日解决这个问题?
我只是偶然发现了 ,这是我需要让这个工作正常运行的缺失的金块。
具体来说,我必须修改 /etc/systemd/system.conf 并添加
DefaultLimitNOFILE=40000
所以,总而言之,这是我的配置:
设 100-couchdb.conf 为:
#<domain> <type> <item> <value>
couchdb hard nofile 40000
couchdb soft nofile 40000
* hard nofile 40000
* soft nofile 40000
root hard nofile 40000
root soft nofile 40000
1) 通过 PAM 设置限制:
cp 100-couchdb.conf /etc/security/limits.d/100-couchdb.conf
cp 100-couchdb.conf /etc/security/limits.conf
echo "session required pam_limits.so" >> /etc/pam.d/su
2) 增加systemd允许的文件数量
echo "DefaultLimitNOFILE=40000" >> /etc/systemd/system.conf
3) 增加Erlang通过systemd允许的连接数
sed -i "s/\[Service\]/\[Service\]\nEnvironment=ERL_MAX_PORTS=40000/g" /etc/systemd/system/multi-user.target.wants/couchdb.service
4) 同时增加 Erlang 允许的连接数(我不确定是否需要这样做,因为我们已经通过 systemd 配置了它,但它似乎没有什么坏处)
echo "export ERL_MAX_PORTS=40000" >> /etc/default/couchdb
注意:在运行一些压力测试中,我发现我需要将限制增加到大约 40000 以支持 10,000 个并发连接。我猜这是由于一些开销造成的,每个连接需要多个文件。
我最近升级到 Ubuntu 16 和 CouchDB 1.6。当我的服务器受到大量连接的冲击时,我会在 couch.log 中收到 emfile
错误。我以前见过这些错误,它们似乎与 https://wiki.apache.org/couchdb/Performance 中提到的系统资源限制有关。我相信我的主要问题是 ERL_MAX_PORTS
。我已经将我的 ulimit 增加到 40000(通过 PAM)并将 export ERL_MAX_PORTS=40000
添加到 /etc/default/couchdb。
Ubuntu 16 使用 systemd,所以我将 Environment="ERL_MAX_PORTS=40000"
添加到 /etc/systemd/system/multi-user.target.wants/couchdb.service 中的 [Service]
部分,但这并不似乎有效。
我什至尝试修改 /usr/bin/couchdb 并将 env ERL_MAX_PORTS=40000
添加到脚本的顶部。
唯一似乎有效的是当我从命令行手动 运行 couchdb 时,例如$ env ERL_MAX_PORTS=40000 && sudo /usr/bin/couchdb
。这不是一个理想的解决方案,我宁愿让它与 systemd 一起工作。
我之前在 Ubuntu14 上 运行ning CouchDB 1.5 并将我的系统资源限制(请参阅 https://wiki.apache.org/couchdb/Performance)增加到大约 40000,它可以毫无问题地处理许多连接。
有没有人有幸在 Ubuntu 16 日解决这个问题?
我只是偶然发现了 ,这是我需要让这个工作正常运行的缺失的金块。
具体来说,我必须修改 /etc/systemd/system.conf 并添加
DefaultLimitNOFILE=40000
所以,总而言之,这是我的配置:
设 100-couchdb.conf 为:
#<domain> <type> <item> <value>
couchdb hard nofile 40000
couchdb soft nofile 40000
* hard nofile 40000
* soft nofile 40000
root hard nofile 40000
root soft nofile 40000
1) 通过 PAM 设置限制:
cp 100-couchdb.conf /etc/security/limits.d/100-couchdb.conf
cp 100-couchdb.conf /etc/security/limits.conf
echo "session required pam_limits.so" >> /etc/pam.d/su
2) 增加systemd允许的文件数量
echo "DefaultLimitNOFILE=40000" >> /etc/systemd/system.conf
3) 增加Erlang通过systemd允许的连接数
sed -i "s/\[Service\]/\[Service\]\nEnvironment=ERL_MAX_PORTS=40000/g" /etc/systemd/system/multi-user.target.wants/couchdb.service
4) 同时增加 Erlang 允许的连接数(我不确定是否需要这样做,因为我们已经通过 systemd 配置了它,但它似乎没有什么坏处)
echo "export ERL_MAX_PORTS=40000" >> /etc/default/couchdb
注意:在运行一些压力测试中,我发现我需要将限制增加到大约 40000 以支持 10,000 个并发连接。我猜这是由于一些开销造成的,每个连接需要多个文件。