在Apache2.0中新加入了ServerLimit指令,使得無須重編譯Apache就可以加大MaxClients。下面是筆者的prefork配置段。
<IfModule prefork.c>
StartServers 10
MinSpareServers 10
MaxSpareServers 15
ServerLimit 2000
MaxClients 1500
MaxRequestsPerChild 10000
</IfModule>
BTW: ServerLimit的最大值是20000,這對於大多數站點是足夠了,但如果你一定要再加大的話,那麼這個值位於源代碼樹下的server/mpm/prefork/prefork.c中。裡面的
#define DEFAULT_SERVER_LIMIT 256
#define MAX_SERVER_LIMIT 20000
這兩行就對應著MaxClients和ServerLimit的限制值。但我相信很少有人可以用到20000的並發連接數。
如果你有耐性看完了我這篇文檔,我相信您對Apache2.0 缺省的prefork的工作原理有所熟悉了,理解了它的工作過程後,就可以根據您的實際情況在FreeBSD下來配置Apache相關的核心參數以獲得最大的性能。
其實用apache2的話,./configure中應該用--with-mpm=worker參數,這樣才能發揮apache2的多線程機制。
vi ~apache_install_path/conf/httpd.conf
<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
MaxClients x ThreadsPerChild =響應的請求數,可以根據自己的實際情況,更改threadsperchild數目。
對於linux下,其實不能實現多線程模式,要加大MaxClients 的數目,solaris下,就非常優秀了。。
wangmingda 說的也很正確,他是apache2編譯的時候採用了默認的 --with-mpm=prefork模式,這種模式是兼容舊的軟件版本的,不能更好的發揮apache2的線成特性。
引用:
Compile-Time Configuration Issues
Choosing an MPM
Apache 2.x supports pluggable concurrency models, called Multi-Processing Modules (MPMs). When building Apache, you must choose an MPM to use. There are platform-specific MPMs for some platforms: beos, mpm_netware, mpmt_os2, and mpm_winnt. For general Unix-type systems, there are several MPMs from which to choose. The choice of MPM can affect the speed and scalability of the httpd:
The worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.
The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but it uses more memory. Prefork's threadless design has advantages over worker in some situations: it can be used with non-thread-safe third-party modules, and it is easier to debug on platforms with poor thread debugging support.
For more information on these and other MPMs, please see the MPM documentation.
訪客無法瀏覽此圖片或連結,請先 註冊 或 登入會員 。
因為在設置的時候出現錯誤,所以把我的想法說說看。
設置
ServerLimit 8
StartServers 2
MinSpareThreads 15
MaxSpareThreads 25
ThreadsPerChild 25
MaxRequestsPerChild 1000
MaxClients 250
錯誤:
WARNING: MaxClients of 250 would require 10 servers,
and would exceed the ServerLimit value of 8.
Automatically lowering MaxClients to 200. To increase,
please see the ServerLimit directive.
經過多次計算測試,我覺得應該是
MaxClients <= ServerLimit * ThreadsPerChild
官方有教
訪客無法瀏覽此圖片或連結,請先 註冊 或 登入會員 。