|  
  limits.conf的工作原理: 
  limits.conf的后端是這樣工作的:limits.conf是 pam_limits.so的配置文件,然后/etc/pam.d/下的應(yīng)用程序 
調(diào)用pam_***.so模塊。譬如說,當(dāng)用戶訪問服務(wù)器,服務(wù)程序?qū)⒄埱蟀l(fā)送到PAM模塊,PAM模塊根據(jù)服務(wù)名稱在/etc/pam.d目錄下 
選擇一個對應(yīng)的服務(wù)文件,然后根據(jù)服務(wù)文件的內(nèi)容選擇具體的PAM模塊進行處理。[摘抄] 
       相關(guān)的應(yīng)用以及配置, 還得繼續(xù)研究!下面分享一個小實驗! 
  
實驗:limits實驗!關(guān)于能打開的最大文件數(shù)和能并發(fā)的最大進程數(shù): 
[研究背景: nginx 與 php 的連接, 以及對其做壓力測試的時候! 由于php-cgi是單進程的,影響nginx的效率,  然后便使用產(chǎn)蛋程序 spawn. 
                   但是它依然受到限制, 怎么辦? 系統(tǒng)最大并發(fā)進程數(shù)的控制, 也就是下面實驗的目的了! ] 
[注意, 先將系統(tǒng)的默認(rèn)全局參數(shù)調(diào)大 sysctl.conf -->kernel.threads-max = xxxxx .... ] 
  
實驗結(jié)論: 
a. nofile的配置,可以用 * 來通配對所有的用戶的設(shè)置! 
b. noproc的配置,不能用 *  無效, 只能指定特定的用戶! 
溫馨提醒: 最大進程并發(fā)數(shù)的設(shè)置很危險的,如果你的機器性能不是很好的話,用spawn產(chǎn)出5000個cgi進程,然后用ab并發(fā)出上萬個查詢請求進行壓力測試! 
最后你發(fā)現(xiàn),并發(fā)數(shù)小于5000的時候錯誤率為零,再高點兒,就有錯了! 
另外,當(dāng)要killall全殺掉服務(wù)端開啟的cgi進程,你會發(fā)現(xiàn)機器卡了,我的實驗機器性能不怎么好,崩掉啦~ 
  
    - 1> limits.conf:  
 
    - --------------------------->  
 
    - * soft nofile 1000000  
 
    - * hard nofile 1000000  
 
    - root soft nproc  20000  
 
    - root hard nproc  20000  
 
    - * soft nproc  20000  
 
    - * hard nproc  20000  
 
    - ---------------------------->  
 
    - 實驗結(jié)果:  
 
    - [root@lin /]# ulimit -u   //20000  
 
    - [root@lin /]# ulimit -n   //1000000  
 
    - [root@lin /]# su - test  
 
    - [test@lin ~]$ ulimit -u   //1024  
 
    - [test@lin ~]$ ulimit -n   //1000000  
 
    - ####################################  
 
 
 
1> limits.conf:
--------------------------->
* soft nofile 1000000
* hard nofile 1000000
root soft nproc  20000
root hard nproc  20000
* soft nproc  20000
* hard nproc  20000
---------------------------->
實驗結(jié)果:
[root@lin /]# ulimit -u   //20000
[root@lin /]# ulimit -n   //1000000
[root@lin /]# su - test
[test@lin ~]$ ulimit -u   //1024
[test@lin ~]$ ulimit -n   //1000000
#################################### 
    - 2> limits.conf  
 
    - --------------------------->  
 
    - * soft nofile 1000000  
 
    - * hard nofile 1000000  
 
    - root soft nproc  20000  
 
    - root hard nproc  20000  
 
    - * soft nproc  20000  
 
    - * hard nproc  20000  
 
    - test soft nproc  20000  
 
    - test hard nproc  20000  
 
    - ---------------------------->  
 
    - 實驗結(jié)果:  
 
    - [root@lin /]# ulimit -u   //20000  
 
    - [root@lin /]# ulimit -n   //1000000  
 
    - [root@lin /]# su - test  
 
    - [test@lin ~]$ ulimit -u   //20000  
 
    - [test@lin ~]$ ulimit -n   //1000000  
 
    - ######################################  
 
 
 
2> limits.conf
--------------------------->
* soft nofile 1000000
* hard nofile 1000000
root soft nproc  20000
root hard nproc  20000
* soft nproc  20000
* hard nproc  20000
test soft nproc  20000
test hard nproc  20000
---------------------------->
實驗結(jié)果:
[root@lin /]# ulimit -u   //20000
[root@lin /]# ulimit -n   //1000000
[root@lin /]# su - test
[test@lin ~]$ ulimit -u   //20000
[test@lin ~]$ ulimit -n   //1000000
###################################### 
    - 3> limits.conf  
 
    - ---------------------------->  
 
    - * soft nofile 1000000  
 
    - * hard nofile 1000000  
 
    - root soft nproc  30000  
 
    - root hard nproc  30000  
 
    - ----------------------------->  
 
    - 實驗結(jié)果:  
 
    - [root@lin /]# su - root  
 
    - [root@lin ~]# ulimit -u  //30000  
 
    - [root@lin ~]# ulimit -n  //1000000  
 
    - [root@lin /]# su - test  
 
    - [test@lin ~]$ ulimit -u  //1024  
 
    - [test@lin ~]$ ulimit -n  //1000000  
 
    - #######################################  
 
 
 
3> limits.conf
---------------------------->
* soft nofile 1000000
* hard nofile 1000000
root soft nproc  30000
root hard nproc  30000
----------------------------->
實驗結(jié)果:
[root@lin /]# su - root
[root@lin ~]# ulimit -u  //30000
[root@lin ~]# ulimit -n  //1000000
[root@lin /]# su - test
[test@lin ~]$ ulimit -u  //1024
[test@lin ~]$ ulimit -n  //1000000
####################################### 
    - 4> limits.conf  
 
    - ------------------------------>  
 
    - * soft nofile 1000000  
 
    - * hard nofile 1000000  
 
    - * soft nproc  20000  
 
    - * hard nproc  20000  
 
    - ------------------------------->  
 
    - 實驗結(jié)果:  
 
    - [root@lin /]# su - root  
 
    - [root@lin ~]# ulimit -u  //1024  
 
    - [root@lin ~]# ulimit -n  //1000000  
 
    - [root@lin ~]# su - test  
 
    - [test@lin ~]$ ulimit -u  //1024  
 
    - [test@lin ~]$ ulimit -n  //1000000  
 
    - ########################################  
 
 
 
億恩-天使(QQ:530997) 電話 037160135991 服務(wù)器租用,托管歡迎咨詢。 
  本文出自:億恩科技【xuefeilisp.com】 
      
      
		服務(wù)器租用/服務(wù)器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM] 
       |