看了前兩篇,咱們都是在想辦法節省資源給咱們真正的服務。問題:咱們的服務真的使用了嗎 ? 答案是否認的,由於系統默認會有一些限制,這些限制也致使了咱們應用的限制。這節咱們說說linux下面的資源限制,咱們來看看下面的數據:
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) unlimited2 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
mysql