java 句柄数 设置_修改操作系统句柄数和用户进程数
對于一般的應(yīng)用來說(像Apache、系統(tǒng)進(jìn)程)1024完全足夠使用。但是像squid、mysql、java等單進(jìn)程處理大量請求的應(yīng)用來說就有點(diǎn)捉襟見肘了。如果單個(gè)進(jìn)程打開的文件句柄數(shù)量超過了系統(tǒng)定義的值,就會提到“too many files open”的錯誤提示。怎么查看當(dāng)前進(jìn)程打開了多少個(gè)文件句柄呢?
lsof -n |awk '{print $2}'|sort|uniq -c |sort -nr|more
在系統(tǒng)訪問高峰時(shí)間以root用戶執(zhí)行上面的腳本,可能出現(xiàn)的結(jié)果如下:
# lsof -n|awk '{print $2}'|sort|uniq -c |sort -nr|more
131 24204
57 24244
57 24231
56 24264
其中第一行是打開的文件句柄數(shù)量,第二行是進(jìn)程號;得到進(jìn)程號后,通過ps命令得到進(jìn)程的詳細(xì)內(nèi)容。
ps -aef|grep 24204
mysql 24204 24162 99 16:15 ? 00:24:25 /usr/sbin/mysqld
原來是mysql進(jìn)程打開最多文件句柄數(shù)量。但是他目前只打開了131個(gè)文件句柄數(shù)量,遠(yuǎn)遠(yuǎn)底于系統(tǒng)默認(rèn)值1024;
//使用ulimit查看系統(tǒng)當(dāng)前參數(shù)設(shè)置
[root@localdomain ~]# ulimit ?-a
core file size ? ? ? ? ?(blocks, -c) 0 core文件的最大值為100 blocks
data seg size ? ? ? ? ? (kbytes, -d) unlimited 進(jìn)程的數(shù)據(jù)段可以任意大
scheduling priority ? ? ? ? ? ? (-e) 0
file size ? ? ? ? ? ? ? (blocks, -f) unlimited 文件可以任意大
pending signals ? ? ? ? ? ? ? ? (-i) 7424
max locked memory ? ? ? (kbytes, -l) 64 個(gè)任務(wù)鎖住的物理內(nèi)存的最大值為32kB
max memory size ? ? ? ? (kbytes, -m) unlimited 一個(gè)任務(wù)的常駐物理內(nèi)存的最大值
open files ? ? ? ? ? ? ? ? ? ? ?(-n) 1024 一個(gè)任務(wù)最多可以同時(shí)打開1024的文件
pipe size ? ? ? ? ? ?(512 bytes, -p) 8
POSIX message queues ? ? (bytes, -q) 819200
real-time priority ? ? ? ? ? ? ?(-r) 0
stack size ? ? ? ? ? ? ?(kbytes, -s) 10240
cpu time ? ? ? ? ? ? ? (seconds, -t) unlimited
max user processes ? ? ? ? ? ? ?(-u) 1024 當(dāng)前用戶同時(shí)打開的進(jìn)程(包括線程)的最大個(gè)數(shù)
virtual memory ? ? ? ? ?(kbytes, -v) unlimited
file locks ? ? ? ? ? ? ? ? ? ? ?(-x) unlimited
1.修改用戶句柄數(shù):
vi /etc/security/limits.conf在文件末尾增加
# add open files
* soft core unlimited
* hard core unlimited
* soft fsize unlimited
* hard fsize unlimited
* soft data unlimited
* hard data unlimited
* soft nproc 65535
* hard nproc 63535
* soft stack unlimited
* hard stack unlimited
* soft nofile 65535
* hard nofile 65535
2.修改用戶進(jìn)程數(shù):
vim /etc/security/limits.d/90-nproc.conf
把1024修改成65535,默認(rèn)情況下普通用戶是1024,root沒有限制;
* soft nproc 65536
root soft nproc unlimited
3.通常/etc/sysctl.conf 不需要修改,配置內(nèi)存在使用到95%時(shí)啟用swap具體如下:
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536
# Controls the maximum size of a message, in bytes
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736
# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
vm.swappiness=5
最是執(zhí)行文件生效命令:sysctl -p
總結(jié)
以上是生活随笔為你收集整理的java 句柄数 设置_修改操作系统句柄数和用户进程数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Android Studio调试系统
- 下一篇: AAC-LC