This Multi-Processing Module is optimized for Windows NT.
winnt模組是最佳化Windows系統所設計的Multi-Processing Module,winnt模組使用一個主行程去建立與控制另一個子行程,在這個子行程當中建立多個執行緒,由這些執行緒負責處理請求。
以下列出winnt模組使用的設定參數與預設值,定義在server/mpm/winnt/mpm_default.h,注意這些預設值是寫在程式碼當中,編譯時就已經確定了。
ThreadsPerChild = 1920
ThreadLimit = 15000
ThreadsPerChild = 64
MaxRequestsPerChild = 0
組態設定範例
# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_winnt_module>
ThreadsPerChild 150
MaxRequestsPerChild 0
</IfModule>
細部運作流程:
主程式執行到將最後時呼叫ap_mpm_run函式,程式控制權轉由MPM模組負責。
mpm_winnt的程式碼是mpm_winnt.c檔案,重要的功能有兩個函式:
AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_event)
ap_mpm_run函式中會呼叫master_main函式建立主處理序(Master Process),在master_main函式會再一次執行httpd主程式,但這一次會建立子處理序(Child Process),呼叫的是child_main函式,程式碼位於child.c檔案之中,重要的函式有:
void child_main(apr_pool_t *pconf)
static unsigned int __stdcall worker_main(void *thread_num_val)
child_main函式中會建立執行worker_main函式的執行緒(Thread),這些執行緒就是Apache HTTP Server處理請求的地方。另外,child_main會另外建立一個執行緒處理socket,由create_listener_thread處理負責accept()的工作。
由於winnt模組涉及Windows API的操作,特別需要熟悉Windows Sockets 2、Processes and Threads與Input and Output (I/O)的操作,請參考:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms740673%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684841%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365198%28v=vs.85%29.aspx
值得注意的是,winnt模組在Windows NT/2000以後的使用I/O Completion Ports模型,處理socket連線將呼叫winnt_accept與winnt_get_connection函式,若是Windows 95/98則是呼叫win9x_accept與win9x_get_connection兩個函式。