看了前两篇,我们都是在想办法节省资源给我们真正的服务。问题:我们的服务真的使用了吗 ? 答案是否定的,因为系统默认会有一些限制,这些限制也导致了我们应用的限制。这节我们说说linux下面的资源限制,我们来看看下面的数据:
[root@localhost Desktop]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15311
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 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
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
这些是系统默认对一些资源或者行为的限制,/etc/security/limits.conf 文件中也有,linux下是使用文件描述符(也称为句柄)来进行操作的,一个进程能够打开文件的次数会影响到应用的并发度,像一些库文件。这个我写过简单 的C程序证明过。像apache,mysql,oracle这样对并发要求高的应用,(oracle在安装时便有这样的建议值)对这些一定要改变默认的限 制:
修改/etc/security/limits.conf
#
* soft nofile NNNNN
* hard nofile NNNNN
#
上面仅仅是例子,也可以使用ulimit添加自定义的限制(很多选项系统默认还开启),可以对一些不同用户进行限制
#
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open files
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit (KB)
# - maxlogins - max number of logins for this user
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-20, 19]
# - rtprio - max realtime priority
#
建议阅读:http://www.ibm.com/developerworks/cn/linux/l-cn-ulimit/
http://blog.sina.com.cn/s/blog_59b6af6901011ekd.html
[root@localhost Desktop]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15311
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 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
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
这些是系统默认对一些资源或者行为的限制,/etc/security/limits.conf 文件中也有,linux下是使用文件描述符(也称为句柄)来进行操作的,一个进程能够打开文件的次数会影响到应用的并发度,像一些库文件。这个我写过简单 的C程序证明过。像apache,mysql,oracle这样对并发要求高的应用,(oracle在安装时便有这样的建议值)对这些一定要改变默认的限 制:
修改/etc/security/limits.conf
#
* soft nofile NNNNN
* hard nofile NNNNN
#
上面仅仅是例子,也可以使用ulimit添加自定义的限制(很多选项系统默认还开启),可以对一些不同用户进行限制
#
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open files
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit (KB)
# - maxlogins - max number of logins for this user
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-20, 19]
# - rtprio - max realtime priority
#
建议阅读:http://www.ibm.com/developerworks/cn/linux/l-cn-ulimit/
http://blog.sina.com.cn/s/blog_59b6af6901011ekd.html
来源:oschina
链接:https://my.oschina.net/u/817537/blog/144818