我正在玩pgBouncer作为PostgreSQL的连接池系统。 我的系统是一个12核心,运行Debian 8.1的64GB RAM和1Gbpsnetworking接口。 现在我想提高开放套接字连接的限制,比如10.000个并发客户端。 在进行数据库基准testing时, pgbench实用程序会阻止大约950个并发客户端,这似乎达到了1024个开放式的极限,就像以前那样。 我检查了fs.file-max内核参数和pgbench运行用户的资源限制:
# sysctl fs.file-max fs.file-max = 6598264 # su - postgres $ ulimit -Sn 65536 $ fgrep files /proc/self/limits Max open files 65536 65536 files $
但是, proc的限制表明,对于pgBouncer (以用户postgres运行)的最大打开文件的软限制最多只有1024个打开的文件:
$ ps -e | fgrep pgbouncer 9840 ? 00:00:00 pgbouncer $ fgrep files /proc/9840/limits Limit Soft Limit Hard Limit Units Max open files 1024 4096 files $
我试图通过在/etc/default/pgbouncer插入ulimit -S -n 5000 (通过/etc/init.d的开始/停止脚本读入)来提高限制,但是这并不起作用。 然后我尝试了/etc/security/limits.conf nofile设置,并确保它在PAM中启用,但无济于事。
那么, start-stop-daemon nofile降低了守护进程的nofile限制呢? 我偶然发现了Debian的这个旧的bug报告 ,但似乎这个补丁从未被应用。
顺便说一句: fs.file-max真的是许多关于调优的博客文章中提出的替代前系统的nofiles (注意复数)内核variables? 让我想知道它是在fs参数部分。 在我的IRIX系统上,它被称为rlimit_no_files_max在资源部分,这比我把它放在fs部分更fs 。
我在这里做错了什么? Debian 8.1中的守护进程更改此参数的正确位置在哪里?
提前致谢,
斯特凡
您可以在pgbouncer初始化脚本的“开始”部分使用“ulimit”:
/etc/init.d/pgbouncer:
[... snip ...] case "$1" in start) # Check if we are still disabled in /etc/default/pgbouncer [ "${START:-}" = "0" ] && exit 0 log_daemon_msg "Starting PgBouncer" $NAME test -d $PIDDIR || install -d -o postgres -g postgres -m 2775 $PIDDIR ### set whatever limits you want ### ulimit -n 20000 $SSD --start --chuid $RUNASUSER --oknodo -- $OPTS 2> /dev/null log_end_msg $? ;; [... snip ...]
添加这条线后,重新启动后会发生效果:
做到这一点,或者你在以下方面大喊:
# systemctl daemon-reload
然后:
# /etc/init.d/pgbouncer restart
更新:
我的原始答案显示你可以在初始化脚本中添加“ulimit”,可以在Debian 8上运行。尽pipeDeb8是一个systemd发行版,但是默认安装的pgbouncer仍然使用init脚本。
对于使用systemd完全pipe理pgbouncer的Centos7,您希望使用systemd.service文件。
首先,在Centos7上,pgbouncer的默认服务文件中有一个错误,你需要将“Type = forked”设为“Type = simple”。
在pgbouncer.service文件中,您还可以在[Service]部分添加一个“LimitNOFILE = ##”…因此
/etc/systemd/system/pgbouncer.service ## good practice to include the default service file as it may change with future updates .include /lib/systemd/system/pgbouncer.service ## change the Type= per this bug ## http://www.postgresql.org/message-id/[email protected] Type=simple ## Add a service section and set the max number of open files [Service] LimitNOFILE=12345
可能值得validation的是,打开文件的最大数量是瓶颈。 您可以检查您的日志,实质上是“打开的文件太多”错误消息。 在任何情况下,我超过了允许打开文件的最大数量,这个过程抱怨…
/var/log/postgresql/pgbouncer.log
ERROR S: login failed: FATAL: could not open relation mapping file (...): Too many open files in system ERROR S: login failed: FATAL: could not open file (...): Too many open files in system ERROR S: login failed: FATAL: pipe() failed: Too many open files in system WARNING sbuf_connect failed: Too many open files in system
/var/log/postgresql/postgresql-9.4-main.log
LOG: out of file descriptors: Too many open files in system; release and retry PANIC: could not open file (...): Too many open files in system LOG: server process (...) was terminated by signal 6: Aborted DETAIL: Failed process was running: END; LOG: terminating any other active server processes
我们不需要担心pgbench可用的FD,因为如果它们不够用,pgbench将不会运行:
$ ulimit -S -n 100 $ pgbench -h 192.168.122.69 -p 6432 -U postgres -d booktown -c 200 -t 10000 You need at least 202 open files but you are only allowed to use 100. Use limit/ulimit to increase the limit before using pgbench.