在Apache的Access Log中會(huì)看到很多如下的訪問日志:
127.0.0.1 - - [05/May/2011:10:54:07 +0800] "OPTIONS * HTTP/1.0" 200 -
127.0.0.1 - - [05/May/2011:10:54:08 +0800] "OPTIONS * HTTP/1.0" 200 -
127.0.0.1 - - [05/May/2011:10:54:09 +0800] "OPTIONS * HTTP/1.0" 200 -
127.0.0.1 - - [05/May/2011:10:54:10 +0800] "OPTIONS * HTTP/1.0" 200 -
在Apache Prefork模式下, 啟動(dòng)的時(shí)候,Apache就會(huì)fork出一些worker進(jìn)程, 來準(zhǔn)備接受請(qǐng)求, 這些worker進(jìn)程,在完成準(zhǔn)備工作以后, 就會(huì)進(jìn)入block模式的監(jiān)聽沉睡中, 等待請(qǐng)求到來而被喚醒。另外一方面, 在Prefork模式下, 當(dāng)請(qǐng)求很多, 目前的worker進(jìn)程數(shù)不夠處理的時(shí)候, 就會(huì)額外再fork一些worker進(jìn)程出來, 以滿足當(dāng)前的請(qǐng)求。
而在這些請(qǐng)求高峰過后, 如果額外fork出來的進(jìn)程數(shù)大于了MaxSpareServers, Apache就會(huì)告訴這些worker進(jìn)程退出, 那么問題就來了。
這些進(jìn)程都在沉睡中啊, 怎么告訴他們, 并且讓他們自我退出呢?
Apache會(huì)首先發(fā)送一個(gè)退出狀態(tài)字(GRACEFUL_CHAR !)給這些Work進(jìn)程:
static apr_status_t pod_signal_internal(ap_pod_t *pod)
{
apr_status_t rv;
char char_of_death = '!';
apr_size_t one = 1;
rv = apr_file_write(pod->pod_out, &char_of_death, &one);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
"write pipe_of_death");
}
return rv;
}
但此時(shí), Worker進(jìn)程不會(huì)去讀這些狀態(tài)字, 因?yàn)樗麄冞€在沉睡。
這個(gè)時(shí)候Apache就會(huì)發(fā)送一個(gè)OPTIONS請(qǐng)求給自己, 喚醒這些沉睡的進(jìn)程:
static apr_status_t dummy_connection(ap_pod_t *pod)
{
//...有省略
/* Create the request string. We include a User-Agent so that
* adminstrators can track down the cause of the odd-looking
* requests in their logs.
*/
srequest = apr_pstrcat(p, "OPTIONS * HTTP/1.0/r/nUser-Agent: ",
ap_get_server_banner(),
" (internal dummy connection)/r/n/r/n", NULL);
//...有省略
}