Ïà±ÈÓÚApache 1.3 £¬2.0°æ±¾×÷ÁË´óÁ¿µÄÓÅ»¯À´ÌáÉý´¦ÀíÄÜÁ¦ºÍ¿ÉÉìËõÐÔ£¬¶øÇÒ´ó¶àÊýµÄ¸Ä½øÔÚĬÈÏ״̬ϾͿÉÒÔÉúЧ¡£µ«ÊÇ£¬ÔÚ±àÒëʱºÍÔËÐÐʱ£¬¶¼ÓÐÐí¶à¿ÉÒÔÏÔÖøÌá¸ßÐÔÄܵÄÑ¡Ôñ¡£±¾ÎIJûÊöÔÚ°²×°Apache2.0ʱ£¬·þÎñÆ÷¹ÜÀíÔ±¿ÉÒÔ¸ÄÉÆÐÔÄܵĸ÷ÖÖ·½·¨¡£ÆäÖУ¬²¿·ÖÅäÖÃÑ¡Ôñ¿ÉÒÔʹhttpd¸üºÃµØÀûÓÃÓ²¼þºÍ²Ù×÷ϵͳµÄ¼æÈÝÐÔ£¬ÆäËûÔòÊÇÒÔ¹¦ÄÜ»»È¡Ëٶȡ£
top
Ó²¼þºÍ²Ù×÷ϵͳ
Ó°Ïìweb·þÎñÆ÷ÐÔÄܵÄ×î´óµÄÒòËØÊÇÄÚ´æ¡£Ò»¸öweb·þÎñÆ÷Ó¦¸Ã´Ó²»Ê¹Óý»»»»úÖÆ£¬ÒòΪ½»»»²úÉúµÄÖͺóʹÓû§×ܸоõ"²»¹»¿ì"£¬ËùÒÔÓû§¾Í¿ÉÄÜÈ¥°´"Í£Ö¹"ºÍ"Ë¢ÐÂ"£¬´Ó¶ø´øÀ´¸ü´óµÄ¸ºÔØ¡£Äã¿ÉÒÔ£¬Ò²Ó¦¸Ã£¬¿ØÖÆMaxClientsµÄÉèÖã¬ÒÔ±ÜÃâ·þÎñÆ÷²úÉúÌ«¶àµÄ×Ó½ø³Ì¶ø·¢Éú½»»»¡£Õâ¸ö¹ý³ÌºÜ¼òµ¥£ºÍ¨¹ýtopÃüÁî¼ÆËã³öÿ¸öApache½ø³Ìƽ¾ùÏûºÄµÄÄڴ棬ȻºóÔÙΪÆäËü½ø³ÌÁô³ö×ã¹»¶àµÄÄÚ´æ¡£
ÆäËûÒòËؾͺÜÆÕͨÁË£¬×°Ò»¸ö×ã¹»¿ìµÄCPU£¬Ò»¸ö×ã¹»¿ìµÄÍø¿¨£¬¼¸¸ö×ã¹»¿ìµÄÓ²ÅÌ£¬ÕâÀï˵µÄ"×ã¹»¿ì"ÊÇÖ¸ÄÜÂú×ãʵ¼ÊÓ¦ÓõÄÐèÇó¡£
²Ù×÷ϵͳÊǺÜÖµµÃ¹Ø×¢µÄÓÖÒ»¸öÒòËØ£¬ÒѾ±»Ö¤ÊµµÄºÜÓÐÓõľÑéÓУº
*
Ñ¡ÔñÄܹ»µÃµ½µÄ×îÐÂ×îÎȶ¨µÄ°æ±¾²¢´òºÃ²¹¶¡¡£½üÄêÀ´£¬Ðí¶à²Ù×÷ϵͳ³§É̶¼ÌṩÁË¿ÉÒÔÏÔÖø¸ÄÉÆÐÔÄܵÄTCPÐÒéÕ»ºÍÏ߳̿⡣
*
Èç¹ûÄãµÄ²Ù×÷ϵͳ֧³Ösendfile()ϵͳµ÷Óã¬ÔòÎñ±Ø°²×°´øÓд˹¦Äܵİ汾»ò²¹¶¡(¶ÔLinuxÀ´Ëµ£¬¾ÍÊÇʹÓÃLinux2.4»ò¸ü¸ß°æ±¾£¬¶ÔSolaris8µÄÔçÆÚ°æ±¾£¬ÔòÐèÒª°²×°²¹¶¡)¡£ÔÚÖ§³ÖsendfileµÄϵͳÖУ¬Apache2¿ÉÒÔ¸ü¿ìµØ·¢Ë;²Ì¬ÄÚÈݶøÇÒÕ¼ÓýÏÉÙµÄCPUʱ¼ä¡£
top
ÔËÐÐʱµÄÅäÖÃ
Ïà¹ØÄ£¿é Ïà¹ØÖ¸Áî
* mod_dir
* mpm_common
* mod_status
* AllowOverride
* DirectoryIndex
* HostnameLookups
* EnableMMAP
* EnableSendfile
* KeepAliveTimeout
* MaxSpareServers
* MinSpareServers
* Options
* StartServers
HostnameLookups ºÍÆäËûDNS¿¼ÂÇ
ÔÚApache1.3ÒÔÇ°µÄ°æ±¾ÖУ¬HostnameLookupsĬÈϱ»ÉèΪ On ¡£Ëü»á´øÀ´ÑÓ³Ù£¬ÒòΪ¶Ôÿһ¸öÇëÇó¶¼ÐèÒª×÷Ò»´ÎDNS²éѯ¡£ÔÚApache1.3ÖУ¬Ëü±»Ä¬ÈϵØÉèÖÃΪ Off ¡£Èç¹ûÐèÒªÈÕÖ¾ÎļþÌṩÖ÷»úÃûÐÅÏ¢ÒÔÉú³É·ÖÎö±¨¸æ£¬Ôò¿ÉÒÔʹÓÃÈÕÖ¾ºó´¦Àí³ÌÐòlogresolve £¬ÒÔÍê³ÉDNS²éѯ£¬¶ø¿Í»§¶ËÎÞÐëµÈ´ý¡£
ÍƼöÄã×îºÃÊÇÔÚÆäËû»úÆ÷ÉÏ£¬¶ø²»ÊÇÔÚweb·þÎñÆ÷ÉÏÖ´Ðкó´¦ÀíºÍÆäËûÈÕ־ͳ¼Æ²Ù×÷£¬ÒÔÃâÓ°Ïì·þÎñÆ÷µÄÐÔÄÜ¡£
Èç¹ûÄãʹÓÃÁËÈκÎ"Allow from domain"»ò"Deny from domain"Ö¸Áî(Ò²¾ÍÊÇdomainʹÓõÄÊÇÖ÷»úÃû¶ø²»ÊÇIPµØÖ·)£¬Ôò´ú¼ÛÊÇÒª½øÐÐÁ½´ÎDNS²éѯ(Ò»´ÎÕýÏòºÍÒ»´Î·´Ïò£¬ÒÔÈ·ÈÏûÓÐ×÷¼Ù)¡£ËùÒÔ£¬ÎªÁ˵õ½×î¸ßµÄÐÔÄÜ£¬Ó¦¸Ã±ÜÃâʹÓÃÕâЩָÁî(²»ÓÃÓòÃû¶øÓÃIPµØÖ·Ò²ÊÇ¿ÉÒÔµÄ)¡£
×¢Ò⣬¿ÉÒÔ°ÑÕâЩָÁî°üº¬ÔÚ
HostnameLookups off
HostnameLookups on
Èç¹ûÔÚijЩCGIÖÐż¶ûÐèÒªDNSÃû³Æ£¬Ôò¿ÉÒÔµ÷ÓÃgethostbynameÀ´½â¾ö¡£
FollowSymLinks ºÍ SymLinksIfOwnerMatch
Èç¹ûÍøÕ¾¿Õ¼äÖÐûÓÐʹÓà Options FollowSymLinks £¬»òʹÓÃÁË Options SymLinksIfOwnerMatch £¬Apache¾Í±ØÐëÖ´ÐжîÍâµÄϵͳµ÷ÓÃÒÔÑéÖ¤·ûºÅÁ¬½Ó¡£ÎļþÃûµÄÿһ¸ö×é³É²¿·Ö¶¼ÐèÒªÒ»¸ö¶îÍâµÄµ÷Óá£ÀýÈ磬Èç¹ûÉèÖÃÁË£º
DocumentRoot /www/htdocs
Options SymLinksIfOwnerMatch
ÔÚÇëÇó"/index.html"ʱ£¬Apache½«¶Ô"/www"¡¢"/www/htdocs"¡¢"/www/htdocs/index.html"Ö´ÐÐlstat()µ÷Ó᣶øÇÒlstat()µÄÖ´Ðнá¹û²»±»»º´æ£¬Òò´Ë¶Ôÿһ¸öÇëÇó¶¼ÒªÖ´ÐÐÒ»´Î¡£Èç¹ûȷʵÐèÒªÑéÖ¤·ûºÅÁ¬½ÓµÄ°²È«ÐÔ£¬Ôò¿ÉÒÔÕâÑù£º
DocumentRoot /www/htdocs
Options FollowSymLinks
Options -FollowSymLinks +SymLinksIfOwnerMatch
ÕâÑù£¬ÖÁÉÙ¿ÉÒÔ±ÜÃâ¶ÔDocumentRoot·¾¶µÄ¶àÓàµÄÑéÖ¤¡£×¢Ò⣬Èç¹ûAlias»òRewriteRuleÖк¬ÓÐDocumentRootÒÔÍâµÄ·¾¶£¬ÄÇôͬÑùÐèÒªÔö¼ÓÕâÑùµÄ¶Î¡£ÎªÁ˵õ½×î¼ÑÐÔÄÜ£¬Ó¦µ±·ÅÆú¶Ô·ûºÅÁ¬½ÓµÄ±£»¤£¬ÔÚËùÓеط½¶¼ÉèÖÃFollowSymLinks £¬²¢·ÅÆúʹÓÃSymLinksIfOwnerMatch ¡£
AllowOverride
Èç¹ûÍøÕ¾¿Õ¼äÔÊÐí¸²¸Ç(ͨ³£ÊÇÓÃ.htaccessÎļþ)£¬ÔòApache»áÊÔͼ¶ÔÎļþÃûµÄÿһ¸ö×é³É²¿·Ö¶¼´ò¿ª.htaccess £¬ÀýÈ磺
DocumentRoot /www/htdocs
AllowOverride all
Èç¹ûÇëÇó"/index.html"£¬ÔòApache»áÊÔͼ´ò¿ª"/.htaccess"¡¢"/www/.htaccess"¡¢"/www/htdocs/.htaccess"¡£Æä½â¾ö·½·¨ºÍÇ°ÃæËùÊöµÄ Options FollowSymLinks ÀàËÆ¡£ÎªÁ˵õ½×î¼ÑÐÔÄÜ£¬Ó¦µ±¶ÔÎļþϵͳÖÐËùÓеĵط½¶¼Ê¹Óà AllowOverride None ¡£
ÄÚÈÝÐÉÌ
ʵ¼ùÖУ¬ÄÚÈÝÐÉ̵ĺô¦´óÓÚÐÔÄܵÄËðʧ£¬Èç¹ûÄãºÜÔÚÒâÄÇÒ»µãµãµÄÐÔÄÜËðʧ£¬Ôò¿ÉÒÔ½ûֹʹÓÃÄÚÈÝÐÉÌ¡£µ«ÊÇÈÔÈ»Óиö·½·¨¿ÉÒÔÌá¸ß·þÎñÆ÷µÄËٶȣ¬¾ÍÊDz»ÒªÊ¹ÓÃͨÅä·û£¬È磺
DirectoryIndex index
¶øʹÓÃÍêÕûµÄÁÐ±í£¬È磺
DirectoryIndex index.cgi index.pl index.shtml index.html
ÆäÖÐ×î³£ÓõÄÓ¦¸Ã·ÅÔÚÇ°Ãæ¡£
»¹ÓУ¬½¨Á¢Ò»¸öÃ÷È·µÄtype-mapÎļþÔÚÐÔÄÜÉÏÓÅÓÚʹÓÃ"Options MultiViews"£¬ÒòΪËùÓÐÐèÒªµÄÐÅÏ¢¶¼ÔÚÒ»¸öµ¥¶ÀµÄÎļþÖУ¬¶øÎÞÐëËÑË÷Ŀ¼¡£Çë²Î¿¼ÄÚÈÝÐÉÌÎĵµÒÔ»ñµÃ¸üÏêϸµÄÐÉÌ·½·¨ºÍ´´½¨type-mapÎļþµÄÖ¸µ¼¡£
ÄÚ´æÓ³Éä
ÔÚApache2.0ÐèÒªËÑË÷±»·¢ËÍÎļþµÄÄÚÈÝʱ£¬±ÈÈç´¦Àí·þÎñÆ÷¶Ë°üº¬Ê±£¬Èç¹û²Ù×÷ϵͳ֧³ÖijÖÖÐÎʽµÄmmap() £¬Ôò»á¶Ô´ËÎļþÖ´ÐÐÄÚ´æÓ³Éä¡£
ÔÚijЩƽ̨ÉÏ£¬ÄÚ´æÓ³Éä¿ÉÒÔÌá¸ßÐÔÄÜ£¬µ«ÊÇÔÚijЩÇé¿öÏ£¬ÄÚ´æÓ³Éä»á½µµÍÐÔÄÜÉõÖÁÓ°Ïìµ½httpdµÄÎȶ¨ÐÔ£º
*
ÔÚijЩ²Ù×÷ϵͳÖУ¬Èç¹ûÔö¼ÓÁËCPU£¬mmap»¹²»Èçread()ѸËÙ¡£±ÈÈ磬ÔڶദÀíÆ÷µÄSolaris·þÎñÆ÷ÉÏ£¬¹Ø±ÕÁËmmap £¬Apache2.0´«ËÍ·þÎñ¶Ë½âÎöÎļþÓÐʱºò·´¶ø¸ü¿ì¡£
*
Èç¹ûÄã¶Ô×÷ΪNFS×°ÔصÄÎļþϵͳÖеÄÒ»¸öÎļþ½øÐÐÁËÄÚ´æÓ³É䣬¶øÁíÒ»¸öNFS¿Í»§¶ËµÄ½ø³Ìɾ³ý»òÕ߽ضÏÁËÕâ¸öÎļþ£¬ÄÇôÄãµÄ½ø³ÌÔÚÏÂÒ»´Î·ÃÎÊÒѾ±»Ó³ÉäµÄÎļþÄÚÈÝʱ£¬»á²úÉúÒ»¸ö×ÜÏß´íÎó¡£
Èç¹ûÓÐÉÏÊöÇé¿ö·¢Éú£¬ÔòÓ¦¸ÃʹÓà EnableMMAP off ¹Ø±Õ¶Ô·¢ËÍÎļþµÄÄÚ´æÓ³Éä¡£×¢Ò⣺´ËÖ¸Áî¿ÉÒÔ±»Õë¶ÔĿ¼µÄÉèÖø²¸Ç¡£
Sendfile
ÔÚApache2.0Äܹ»ºöÂÔ½«Òª±»·¢Ë͵ÄÎļþµÄÄÚÈݵÄʱºò(±ÈÈç·¢Ë;²Ì¬ÄÚÈÝ)£¬Èç¹û²Ù×÷ϵͳ֧³Ösendfile() £¬ÔòApache½«Ê¹ÓÃÄÚºËÌṩµÄsendfile()À´·¢ËÍÎļþ¡£
ÔÚ´ó¶àÊýƽ̨ÉÏ£¬Ê¹ÓÃsendfile¿ÉÒÔͨ¹ýÃâ³ý·ÖÀëµÄ¶ÁºÍд²Ù×÷À´ÌáÉýÐÔÄÜ¡£È»¶øÔÚijЩÇé¿öÏ£¬Ê¹ÓÃsendfile»áΣº¦µ½httpdµÄÎȶ¨ÐÔ
*
һЩƽ̨¿ÉÄÜ»áÓÐApache±àÒëϵͳ¼ì²â²»µ½µÄÓÐȱÏݵÄsendfileÖ§³Ö£¬ÌرðÊǽ«ÔÚÆäËûƽ̨ÉÏʹÓý»²æ±àÒëµÃµ½µÄ¶þ½øÖÆÎļþÔËÐÐÓÚµ±Ç°¶ÔsendfileÖ§³ÖÓÐȱÏݵÄƽ̨ʱ¡£
*
¶ÔÓÚÒ»¸ö¹ÒÔØÁËNFSÎļþϵͳµÄÄںˣ¬Ëü¿ÉÄÜÎÞ·¨¿É¿¿µÄͨ¹ý×Ô¼ºµÄcache·þÎñÓÚÍøÂçÎļþ¡£
Èç¹û³öÏÖÒÔÉÏÇé¿ö£¬ÄãÓ¦µ±Ê¹ÓÃ"EnableSendfile off"À´½ûÓÃsendfile ¡£×¢Ò⣬Õâ¸öÖ¸Áî¿ÉÒÔ±»Õë¶ÔĿ¼µÄÉèÖø²¸Ç¡£
½ø³ÌµÄ½¨Á¢
ÔÚApache1.3ÒÔÇ°£¬MinSpareServers, MaxSpareServers, StartServersµÄÉèÖöÔÐÔÄܶ¼ÓкܴóµÄÓ°Ïì¡£ÓÈÆäÊÇΪÁËÓ¦¶Ô¸ºÔضø½¨Á¢×ã¹»µÄ×Ó½ø³Ìʱ£¬ApacheÐèÒªÓÐÒ»¸ö"½¥½ø"µÄ¹ý³Ì¡£ÔÚ×î³õ½¨Á¢StartServersÊýÁ¿µÄ×Ó½ø³Ìºó£¬ÎªÁËÂú×ãMinSpareServersÉèÖõÄÐèÒª£¬Ã¿Ò»ÃëÖÓÖ»Äܽ¨Á¢Ò»¸ö×Ó½ø³Ì¡£ËùÒÔ£¬¶ÔÒ»¸öÐèҪͬʱ´¦Àí100¸ö¿Í»§¶ËµÄ·þÎñÆ÷£¬Èç¹ûStartServersʹÓÃĬÈϵÄÉèÖÃ5£¬ÔòΪÁËÓ¦¶Ô¸ºÔضø½¨Á¢×ã¹»¶àµÄ×Ó½ø³ÌÐèÒª95Ãë¡£ÔÚʵ¼ÊÓ¦ÓÃÖУ¬Èç¹û²»Æµ·±ÖØÐÂÆô¶¯·þÎñÆ÷£¬ÕâÑù»¹¿ÉÒÔ£¬µ«ÊÇÈç¹û½ö½öΪÁËÌṩ10·ÖÖӵķþÎñ£¬ÕâÑù¾ÍºÜÔã¸âÁË¡£
" Ò»ÃëÖÓÒ»¸ö"µÄ¹æ¶¨ÊÇΪÁ˱ÜÃâÔÚ´´½¨×Ó½ø³Ì¹ý³ÌÖзþÎñÆ÷¶ÔÇëÇóµÄÏìӦͣ¶Ù£¬µ«ÊÇËü¶Ô·þÎñÆ÷ÐÔÄܵÄÓ°ÏìÌ«´óÁË£¬±ØÐëÓèÒԸı䡣ÔÚApache1.3ÖУ¬Õâ¸ö "Ò»ÃëÖÓÒ»¸ö"µÄ¹æ¶¨±äµÃ¿íËÉÁË£¬´´½¨Ò»¸ö½ø³Ì£¬µÈ´ýÒ»ÃëÖÓ£¬¼ÌÐø´´½¨µÚ¶þ¸ö£¬ÔٵȴýÒ»ÃëÖÓ£¬¼Ì¶ø´´½¨Ëĸö£¬Èç´Ë°´Ö¸Êý¼¶Ôö¼Ó´´½¨µÄ½ø³ÌÊý£¬×î¶à´ïµ½Ã¿Ãë 32¸ö£¬Ö±µ½Âú×ãMinSpareServersÉèÖõÄֵΪֹ¡£
´Ó¶àÊý·´Ó³¿´À´£¬ËƺõûÓбØÒªµ÷ÕûMinSpareServers, MaxSpareServers, StartServers ¡£Èç¹ûÿÃëÖÓ´´½¨µÄ½ø³ÌÊý³¬¹ý4¸ö£¬Ôò»áÔÚErrorLogÖвúÉúÒ»ÌõÏûÏ¢£¬Èç¹û²úÉú´óÁ¿´ËÏûÏ¢£¬Ôò¿ÉÒÔ¿¼ÂÇÐÞ¸ÄÕâЩÉèÖ᣿ÉÒÔʹÓÃmod_statusµÄÊä³ö×÷Ϊ²Î¿¼¡£
Óë½ø³Ì´´½¨Ïà¹ØµÄÊÇÓÉMaxRequestsPerChildÒý·¢µÄ½ø³ÌµÄÏú»Ù¡£ÆäĬÈÏÖµÊÇ"0"£¬Òâζ×Åÿ¸ö½ø³ÌËù´¦ÀíµÄÇëÇóÊýÊDz»ÊÜÏÞÖƵġ£Èç¹û´ËÖµÉèÖõúÜС£¬±ÈÈç30£¬Ôò¿ÉÄÜÐèÒª´ó·ùÔö¼Ó¡£ÔÚSunOS»òÕßSolarisµÄÔçÆÚ°æ±¾ÉÏ£¬Æä×î´óֵΪ10000ÒÔÃâÄÚ´æй©¡£
Èç¹ûÆôÓÃÁ˳־ÃÁ´½Ó£¬×Ó½ø³Ì½«±£³Öæµ״̬ÒԵȴý±»´ò¿ªÁ¬½ÓÉϵÄÐÂÇëÇó¡£ÎªÁË×îС»¯Æ为ÃæÓ°Ï죬KeepAliveTimeoutµÄĬÈÏÖµ±»ÉèÖÃΪ5Ã룬ÒÔıÇóÍøÂç´ø¿íºÍ·þÎñÆ÷×ÊÔ´Ö®¼äµÄƽºâ¡£ÔÚÈκÎÇé¿öÏ´ËÖµ¶¼²»Ó¦µ±´óÓÚ60Ã룬²Î¼ûmost of the benefits are lost¡£
top
±àÒëʱµÄÅäÖÃ
Ñ¡ÔñÒ»¸öMPM
Apache 2.x Ö§³Ö²åÈëʽ²¢Ðд¦ÀíÄ£¿é£¬³ÆΪ¶à·´¦ÀíÄ£¿é(MPM)¡£ÔÚ±àÒëApacheʱÄã±ØÐëÑ¡ÔñÒ²Ö»ÄÜÑ¡ÔñÒ»¸öMPM£¬ÕâÀïÓм¸¸öÕë¶Ô·ÇUNIXϵͳµÄMPM£ºbeos, mpm_netware, mpmt_os2, mpm_winnt¡£¶ÔÀàUNIXϵͳ£¬Óм¸¸ö²»Í¬µÄMPM¿É¹©Ñ¡Ôñ£¬ËûÃǶ¼»áÓ°Ïìµ½httpdµÄËٶȺͿÉÉìËõÐÔ£º
* workerMPMʹÓöà¸ö×Ó½ø³Ì£¬Ã¿¸ö×Ó½ø³ÌÖÐÓÖÓжà¸öÏ̡߳£Ã¿¸öÏ̴߳¦ÀíÒ»¸öÇëÇ󡣸ÃMPMͨ³£¶Ô¸ßÁ÷Á¿µÄ·þÎñÆ÷ÊÇÒ»¸ö²»´íµÄÑ¡Ôñ¡£ÒòΪËü±ÈpreforkMPMÐèÒª¸üÉÙµÄÄÚ´æÇÒ¸ü¾ßÓÐÉìËõÐÔ¡£
* preforkMPMʹÓöà¸ö×Ó½ø³Ì£¬µ«Ã¿¸ö×Ó½ø³Ì²¢²»°üº¬¶àÏ̡߳£Ã¿¸ö½ø³ÌÖ»´¦ÀíÒ»¸öÁ´½Ó¡£ÔÚÐí¶àϵͳÉÏËüµÄËٶȺÍworkerMPMÒ»Ñù¿ì£¬µ«ÊÇÐèÒª¸ü¶àµÄÄÚ´æ¡£ÕâÖÖÎÞÏ̵߳ÄÉè¼ÆÔÚijЩÇé¿öÏÂÓÅÓÚworkerMPM£ºËü¿ÉÒÔÓ¦ÓÃÓÚ²»¾ß±¸Ḭ̈߳²È«µÄµÚÈý·½Ä£¿é(±ÈÈçphp3/4/5)£¬ÇÒÔÚ²»Ö§³ÖÏ̵߳÷ÊÔµÄƽ̨ÉÏÒ×ÓÚµ÷ÊÔ£¬¶øÇÒ»¹¾ßÓбÈworkerMPM¸ü¸ßµÄÎȶ¨ÐÔ¡£
¹ØÓÚMPMµÄ¸ü¶àÄÚÈÝ£¬Çë²Î¿¼ÆäÎĵµ¡£
Ä£¿é
¼ÈÈ»ÄÚ´æÓÃÁ¿ÊÇÓ°ÏìÐÔÄܵÄÖØÒªÒòËØ£¬Äã¾ÍÓ¦µ±¾¡Á¿È¥³ýÄã²»ÐèÒªµÄÄ£¿é¡£Èç¹ûÄ㽫ģ¿é±àÒë³ÉDSO £¬È¡Ïû²»±ØÒªµÄÄ£¿é¾ÍÊÇÒ»¼þ·Ç³£¼òµ¥µÄÊÂÇ飺עÊ͵ôLoadModuleÖ¸ÁîÖв»ÐèÒªµÄÄ£¿é¡£
Èç¹ûÄãÒѾ½«Ä£¿é¾²Ì¬Á´½Ó½øApache¶þ½øÖƺËÐÄ£¬Äã¾Í±ØÐëÖØбàÒëApache²¢È¥µôÄã²»ÏëÒªµÄÄ£¿é¡£
Ôö¼õÄ£¿éÇ£Éæµ½µÄÒ»¸öÎÊÌâÊÇ£º¾¿¾¹ÐèÒªÄÄЩģ¿é¡¢²»ÐèÒªÄÄЩģ¿é£¿ÕâÈ¡¾öÓÚ·þÎñÆ÷µÄ¾ßÌåÇé¿ö¡£Ò»°ã˵À´£¬ÖÁÉÙÒª°üº¬ÏÂÁÐÄ£¿é£ºmod_mime, mod_dir, mod_log_config ¡£ÄãÒ²¿ÉÒÔ²»Òªmod_log_config £¬µ«ÊÇÒ»°ã²»ÍƼöÕâÑù×ö¡£
Ô×Ó²Ù×÷
һЩģ¿é£¬±ÈÈçmod_cacheºÍworkerʹÓÃAPR(Apache¿ÉÒÆÖ²ÔËÐÐʱ)µÄÔ×ÓAPI¡£ÕâЩAPIÌṩÁËÄܹ»ÓÃÓÚÇáÁ¿¼¶Ïß³Ìͬ²½µÄÔ×Ó²Ù×÷¡£
ĬÈÏÇé¿öÏ£¬APRÔÚÿ¸öÄ¿±êOS/CPUÉÏʹÓÃÆä×îÓÐЧµÄÌØÐÔÖ´ÐÐÕâЩ²Ù×÷¡£±ÈÈçÐí¶àÏÖ´úCPUµÄÖ¸ÁÖÐÓÐÒ»¸öÔ×ӵıȽϽ»»»(compare-and -swap, CAS)²Ù×÷Ö¸Áî¡£ÔÚһЩÀÏʽƽ̨ÉÏ£¬APRĬÈÏʹÓÃÒ»ÖÖ»ºÂýµÄ¡¢»ùÓÚ»¥³âÖ´ÐеÄÔ×ÓAPIÒÔ±£³Ö¶ÔûÓÐCASÖ¸ÁîµÄÀÏʽCPUµÄ¼æÈÝ¡£Èç¹ûÄãÖ»´òËãÔÚÐÂʽµÄCPUÉÏÔËÐÐApache£¬Äã¿ÉÒÔÔÚ±àÒëʱʹÓà --enable-nonportable-atomics Ñ¡Ï
./buildconf
./configure --with-mpm=worker --enable-nonportable-atomics=yes
--enable-nonportable-atomics Ñ¡ÏîÖ»ºÍÏÂÁÐƽ̨Ïà¹Ø£º
* SPARCÉϵÄSolaris
ĬÈÏÇé¿öÏ£¬APRʹÓûùÓÚ»¥³âÖ´ÐеÄÔ×Ó²Ù×÷¡£Èç¹ûÄãʹÓà --enable-nonportable-atomics Ñ¡ÏAPR½«Ê¹ÓÃSPARC v8plus²Ù×÷ÂëÀ´¼Ó¿ì»ùÓÚÓ²¼þµÄCAS²Ù×÷¡£×¢Ò⣬Õâ½ö¶ÔUltraSPARC CPUÓÐЧ¡£
* x86ÉϵÄLinux
ĬÈÏÇé¿öÏ£¬APRÔÚLinuxÉÏʹÓûùÓÚ»¥³âÖ´ÐеÄÔ×Ó²Ù×÷¡£Èç¹ûÄãʹÓà --enable-nonportable-atomics Ñ¡ÏAPR½«Ê¹ÓÃ486²Ù×÷ÂëÀ´¼Ó¿ì»ùÓÚÓ²¼þµÄCAS²Ù×÷¡£×¢Ò⣬Õâ½ö¶Ô486ÒÔÉϵÄCPUÓÐЧ¡£
mod_status ºÍ "ExtendedStatus On"
Èç¹ûApacheÔÚ±àÒëʱ°üº¬ÁËmod_status £¬¶øÇÒÔÚÔËÐÐʱÉèÖÃÁË"ExtendedStatus On"£¬ÄÇôApache»á¶Ôÿ¸öÇëÇóµ÷ÓÃÁ½´Îgettimeofday()(»òÕ߸ù¾Ý²Ù×÷ϵͳµÄ²»Í¬£¬µ÷ÓÃtimes())ÒÔ¼°(1.3°æ֮ǰ)¼¸¸ö¶îÍâµÄtime()µ÷Óã¬Ê¹×´Ì¬¼Ç¼´øÓÐʱ¼ä±êÖ¾¡£ÎªÁ˵õ½×î¼ÑÐÔÄÜ£¬¿ÉÒÔÉèÖÃ"ExtendedStatus off"(ÕâÒ²ÊÇĬÈÏÖµ)¡£
¶àsocketÇé¿öϵĴ®ÐÐaccept
¾¯¸æ
Õⲿ·ÖÄÚÈÝÉÐδÍêÈ«¸ù¾ÝApache2.0Öеı仯½øÐиüР¡£Ò»Ð©ÐÅÏ¢ÒÀÈ»ÓÐЧ£¬Ê¹ÓÃÖÐÇë×¢Òâ¡£
ÕâÀïҪ˵µÄÊÇ Unix socket API µÄÒ»¸öȱµã¡£¼ÙÉèweb·þÎñÆ÷ʹÓÃÁ˶à¸öListenÓï¾ä¼àÌý¶à¸ö¶Ë¿Ú»òÕ߶à¸öµØÖ·£¬Apache»áʹÓÃselect()ÒÔ¼ì²âÿ¸ösocketÊÇ·ñ¾ÍÐ÷¡£select()»á±íÃ÷Ò»¸ösocketÓÐÁã»òÖÁÉÙÒ»¸öÁ¬½ÓÕýµÈºò´¦Àí¡£ÓÉÓÚApacheµÄÄ£ÐÍÊǶà×Ó½ø³ÌµÄ£¬ËùÓпÕÏнø³Ì»áͬʱ¼ì²âеÄÁ¬½Ó¡£Ò»¸öºÜÌìÕæµÄʵÏÖ·½·¨ÊÇÕâÑùµÄ(ÕâЩÀý×Ó²¢²»ÊÇÔ´´úÂ룬ֻÊÇΪÁË˵Ã÷ÎÊÌâ¶øÒÑ)£º
for (;;) {
for (;;) {
fd_set accept_fds;
FD_ZERO (&accept_fds);
for (i = first_socket; i <= last_socket; ++i) {
FD_SET (i, &accept_fds);
}
rc = select (last_socket+1, &accept_fds, NULL, NULL, NULL);
if (rc < 1) continue;
new_connection = -1;
for (i = first_socket; i <= last_socket; ++i) {
if (FD_ISSET (i, &accept_fds)) {
new_connection = accept (i, NULL, NULL);
if (new_connection != -1) break;
}
}
if (new_connection != -1) break;
}
process the new_connection;
}
ÕâÖÖÌìÕæµÄʵÏÖ·½·¨ÓÐÒ»¸öÑÏÖصÄ"¼¢¶ö"ÎÊÌâ¡£Èç¹û¶à¸ö×Ó½ø³ÌͬʱִÐÐÕâ¸öÑ»·£¬ÔòÔÚ¶à¸öÇëÇóÖ®¼ä£¬½ø³Ì»á±»×èÈûÔÚselect £¬Ëæ¼´½øÈëÑ»·²¢ÊÔͼaccept´ËÁ¬½Ó£¬µ«ÊÇÖ»ÓÐÒ»¸ö½ø³Ì¿ÉÒԳɹ¦Ö´ÐÐ(¼ÙÉ軹ÓÐÒ»¸öÁ¬½Ó¾ÍÐ÷)£¬¶øÆäÓàµÄÔò»á±»×èÈûÔÚaccept ¡£ÕâÑù£¬Ö»ÓÐÄÇÒ»¸ösocket¿ÉÒÔ´¦ÀíÇëÇ󣬶øÆäËû¶¼±»ËøסÁË£¬Ö±µ½ÓÐ×ã¹»¶àµÄÇëÇó½«ËüÃÇ»½ÐÑ¡£´Ë"¼¢¶ö"ÎÊÌâÔÚPR#467ÖÐÓÐרÃŵĽ²Êö¡£Ä¿Ç°ÖÁÉÙÓÐÁ½ÖÖ½â¾ö·½°¸¡£
Ò»ÖÖ·½°¸ÊÇʹÓ÷Ç×èÈûÐÍsocket £¬²»×èÈû×Ó½ø³Ì²¢ÔÊÐíËüÃÇÁ¢¼´¼ÌÐøÖ´ÐС£µ«ÊÇÕâÑù»áÀË·ÑCPUʱ¼ä¡£ÉèÏëһϣ¬selectÓÐ10¸ö×Ó½ø³Ì£¬µ±Ò»¸öÇëÇóµ½´ïµÄʱºò£¬ÆäÖÐ9¸ö±»»½ÐÑ£¬²¢ÊÔͼaccept´ËÁ¬½Ó£¬¼Ì¶ø½øÈëselectÑ»·£¬ÎÞËùÊÂÊ£¬²¢ÇÒÆä¼äûÓÐÒ»¸ö×Ó½ø³ÌÄܹ»ÏìÓ¦³öÏÖÔÚÆäËûsocketÉϵÄÇëÇó£¬Ö±µ½Í˳öselectÑ»·¡£×ÜÖ®£¬Õâ¸ö·½°¸Ð§Âʲ¢²»Ôõô¸ß£¬³ý·ÇÄãÓкܶàµÄCPU£¬¶øÇÒ¿ªÁ˺ܶà×Ó½ø³Ì¡£
ÁíÒ»ÖÖÒ²ÊÇApacheËùʹÓõķ½°¸ÊÇ£¬Ê¹ÄÚ²ãÑ»·µÄÈë¿Ú´®Ðл¯£¬ÐÎÈç(²»Í¬Ö®´¦ÒÔ¸ßÁÁÏÔʾ)£º
for (;;) {
accept_mutex_on ();
for (;;) {
fd_set accept_fds;
FD_ZERO (&accept_fds);
for (i = first_socket; i <= last_socket; ++i) {
FD_SET (i, &accept_fds);
}
rc = select (last_socket+1, &accept_fds, NULL, NULL, NULL);
if (rc < 1) continue;
new_connection = -1;
for (i = first_socket; i <= last_socket; ++i) {
if (FD_ISSET (i, &accept_fds)) {
new_connection = accept (i, NULL, NULL);
if (new_connection != -1) break;
}
}
if (new_connection != -1) break;
}
accept_mutex_off ();
process the new_connection;
}
º¯Êýaccept_mutex_onºÍaccept_mutex_offʵÏÖÁËÒ»¸ö»¥³âÐźŵƣ¬ÔÚÈκÎʱ¿ÌÖ»±»ÎªÒ»¸ö×Ó½ø³ÌËùÓµÓС£ÊµÏÖ»¥³âµÄ·½·¨ÓжàÖÖ£¬Æ䶨ÒåλÓÚsrc/conf.h(1.3ÒÔÇ°µÄ°æ±¾)»òsrc/include/ap_config.h(1.3»òÒÔºóµÄ°æ±¾)ÖС£ÔÚһЩ¸ù±¾Ã»ÓÐËø¶¨»úÖƵÄÌåϵÖУ¬Ê¹Óöà¸öListenÖ¸Áî¾ÍÊDz»°²È«µÄ¡£
AcceptMutexÖ¸Áî±»ÓÃÀ´¸Ä±äÔÚÔËÐÐʱʹÓõĻ¥³â·½°¸¡£
AcceptMutex flock
ÕâÖÖ·½·¨µ÷ÓÃϵͳº¯Êýflock()À´Ëø¶¨Ò»¸ö¼ÓËøÎļþ(ÆäλÖÃÈ¡¾öÓÚLockFileÖ¸Áî)¡£
AcceptMutex fcntl
ÕâÖÖ·½·¨µ÷ÓÃϵͳº¯Êýfcntl()À´Ëø¶¨Ò»¸ö¼ÓËøÎļþ(ÆäλÖÃÈ¡¾öÓÚLockFileÖ¸Áî)¡£
AcceptMutex sysvsem
(1.3¼°¸üа汾)ÕâÖÖ·½°¸Ê¹ÓÃSysV·ç¸ñµÄÐźŵÆÒÔʵÏÖ»¥³â¡£²»ÐÒµÄÊÇ£¬SysV·ç¸ñµÄÐźŵÆÓÐһЩ¸±×÷Óã¬ÆäÒ»ÊÇ£¬ApacheÓпÉÄܲ»ÄÜÔÚ½áÊøÒÔÇ°ÊÍ·ÅÕâÖÖÐźŵÆ(¼ûipcs()µÄman page)£¬ÁíÍ⣬ÕâÖÖÐźŵÆAPI¸øÓëÍøÂç·þÎñÆ÷ÓÐÏàͬuidµÄCGIÌṩÁ˾ܾø·þÎñ¹¥»÷µÄ»ú»á(ËùÓÐCGI£¬³ý·ÇÓÃÁËÀàËÆsuexec»òcgiwrapper)¡£¼øÓÚ´Ë£¬ÔÚ¶àÊýÌåϵÖж¼²»ÓÃÕâÖÖ·½·¨£¬³ýÁËIRIX(ÒòΪǰÁ½ÖÖ·½·¨ÔÚIRIXÖдú¼ÛÌ«¸ß)¡£
AcceptMutex pthread
(1.3 ¼°¸üа汾)ÕâÖÖ·½·¨Ê¹ÓÃÁËPOSIX»¥³â£¬°´ÀíÓ¦¸Ã¿ÉÒÔÓÃÓÚËùÓÐÍêÕûʵÏÖÁËPOSIXÏ̹߳淶µÄÌåϵÖУ¬µ«ÊÇËƺõÖ»ÄÜÓÃÔÚSolaris2.5¼°¸üа汾ÖУ¬ÉõÖÁÖ»ÄÜÔÚijÖÖÅäÖÃϲÅÕý³£ÔË×÷¡£Èç¹ûÓöµ½ÕâÖÖÇé¿ö£¬ÔòÓ¦¸ÃÌá·À·þÎñÆ÷µÄ¹ÒÆðºÍʧȥÏìÓ¦¡£Ö»Ìṩ¾²Ì¬ÄÚÈݵķþÎñÆ÷¿ÉÄܲ»ÊÜÓ°Ïì¡£
AcceptMutex posixsem
(2.0¼°¸üа汾)ÕâÖÖ·½·¨Ê¹ÓÃÁËPOSIXÐźŵơ£Èç¹ûÒ»¸öÔËÐÐÖеÄÏß³ÌÕ¼ÓÐÁË»¥³âsegfault £¬ÔòÐźŵƵÄËùÓÐÕß½«²»»á±»»Ö¸´£¬´Ó¶øµ¼Ö·þÎñÆ÷µÄ¹ÒÆðºÍʧȥÏìÓ¦¡£
Èç¹ûÄãµÄϵͳÌṩÁËÉÏÊö·½·¨ÒÔÍâµÄ´®ÐлúÖÆ£¬ÄǾͿÉÄÜÐèҪΪAPRÔö¼Ó´úÂë(»òÕßÌá½»Ò»¸ö²¹¶¡¸øApache)¡£
»¹ÓÐÒ»ÖÖÔø¾¿¼Âǹýµ«´ÓδÓèÒÔʵʩµÄ·½°¸ÊÇʹѻ·²¿·ÖµØ´®Ðл¯£¬¼´Ö»ÔÊÐíÒ»¶¨ÊýÁ¿µÄ½ø³Ì½øÈëÑ»·¡£ÕâÖÖ·½·¨½öÔÚ¶à¸ö½ø³Ì¿ÉÒÔͬʱ½øÐеĶദÀíÆ÷µÄϵͳÖвÅÊÇÓмÛÖµµÄ£¬¶øÇÒÕâÑùµÄ´®Ðз½·¨²¢Ã»ÓÐÕ¼ÓÃÕû¸ö´ø¿í¡£ËüÒ²ÐíÊǽ«À´Ñо¿µÄÒ»¸öÁìÓò£¬µ«ÊÇÓÉÓڸ߶Ȳ¢ÐеÄÍøÂç·þÎñÆ÷²¢²»·ûºÏ¹æ·¶£¬ËùÒÔÆä±»ÓÅÏÈ¿¼Âǵij̶Ȼá±È½ÏµÍ¡£
µ±È»£¬ÎªÁ˵õ½×î¼ÑÐÔÄÜ£¬×îºó¾Í¸ù±¾²»Ê¹Óöà¸öListenÓï¾ä¡£µ«ÊÇÉÏÊöÄÚÈÝ»¹ÊÇÖµµÃ¶ÁÒ»¶Á¡£
µ¥socketÇé¿öϵĴ®ÐÐaccept
ÉÏÊö¶Ô¶àsocketµÄ·þÎñÆ÷½øÐÐÁËÒ»Á÷µÄ½²Êö£¬ÄÇô¶Ôµ¥socketµÄ·þÎñÆ÷ÓÖÔõÑùÄØ£¿ÀíÂÛÉÏËƺõÓ¦¸ÃûÓÐʲôÎÊÌ⣬ÒòΪËùÓнø³ÌÔÚÁ¬½Óµ½À´µÄʱºò¿ÉÒÔÓÉaccept()×èÈû£¬¶ø²»»á²úÉú½ø³Ì"¼¢¶ö"µÄÎÊÌ⣬µ«ÊÇÔÚʵ¼ÊÓ¦ÓÃÖУ¬ËüÑÚ¸ÇÁËÓëÉÏÊö·Ç×èÈû·½°¸¼¸ºõÏàͬµÄÎÊÌâ¡£°´´ó¶àÊýTCPÕ»µÄʵÏÖ·½·¨£¬ÔÚµ¥¸öÁ¬½Óµ½À´Ê±£¬ÄÚºËʵ¼ÊÉÏ»½ÐÑÁËËùÓÐ×èÈûÔÚacceptµÄ½ø³Ì£¬µ«Ö»ÓÐÒ»¸öÄܵõ½´ËÁ¬½Ó²¢·µ»Øµ½Óû§¿Õ¼ä£¬¶øÆäÓàµÄÓÉÓڵò»µ½Á¬½Ó¶øÔÚÄÚºËÖд¦ÓÚÐÝÃß״̬¡£ÕâÖÖÐÝÃß״̬Ϊ´úÂëËùÑڸǣ¬µ«µÄÈ·´æÔÚ£¬²¢²úÉúÓë¶àsocketÖвÉÓ÷Ç×èÈû·½°¸ÏàͬµÄ¸ºÔؼâ·åµÄÀË·Ñ¡£
ͬʱ£¬ÎÒÃÇ·¢ÏÖÔÚÐí¶àÌåϵ½á¹¹ÖУ¬¼´Ê¹ÔÚµ¥socketµÄÇé¿öÏ£¬ÊµÊ©´®Ðл¯µÄЧ¹ûÒ²²»´í£¬Òò´ËÔÚ¼¸ºõËùÓеÄÇé¿öÏ£¬ÊÂʵÉϾͶ¼ÕâÑù´¦ÀíÁË¡£ÔÚLinux (2.0.30£¬Ë«Pentium pro 166/128M RAM)ϵIJâÊÔÏÔʾ£¬¶Ôµ¥socket£¬´®Ðл¯±È²»´®Ðл¯Ã¿ÃëÖÓ¿ÉÒÔ´¦ÀíµÄÇëÇóÉÙÁ˲»µ½3%£¬µ«ÊÇ£¬²»´®Ðл¯¶Ôÿһ¸öÇëÇó¶àÁ˶îÍâµÄ100msµÄÑÓ³Ù£¬´ËÑÓ³Ù¿ÉÄÜÊÇÒòΪ³¤¾àÀëµÄÍøÂçÏß·ËùÖ£¬²¢ÇÒ½ö·¢ÉúÔÚLANÖС£Èç¹ûÐèÒª¸Ä±ä¶Ôµ¥socketµÄ´®Ðл¯£¬¿ÉÒÔ¶¨ÒåSINGLE_LISTEN_UNSERIALIZED_ACCEPT £¬Ê¹µ¥socketµÄ·þÎñÆ÷³¹µ×·ÅÆú´®Ðл¯¡£
ÑӳٵĹرÕ
ÕýÈçdraft-ietf-http-connection-00.txt section 8ËùÊö£¬HTTP·þÎñÆ÷ΪÁË¿É¿¿µØʵÏÖ´ËÐÒ飬ÐèÒªµ¥¶ÀµØÔÚÿ¸ö·½ÏòÉϹرÕͨѶ(ÖØÉêһϣ¬Ò»¸öTCPÁ¬½ÓÊÇË«ÏòµÄ£¬Á½¸ö·½ÏòÖ®¼äÊǶÀÁ¢µÄ)¡£ÔÚÕâÒ»µãÉÏ£¬ÆäËû·þÎñÆ÷¾³£·óÑÜÁËÊ£¬µ«´Ó1.2°æ±¾¿ªÊ¼±»ApacheÕýȷʵÏÖÁË¡£
µ«ÊÇÔö¼ÓÁ˴˹¦ÄÜÒÔºó£¬ÓÉÓÚһЩUnix°æ±¾µÄ¶Ì¼û£¬ËæÖ®Ò²³öÏÖÁËÐí¶àÎÊÌâ¡£TCP¹æ·¶²¢Ã»Óй涨FIN_WAIT_2±ØÐëÓÐÒ»¸ö³¬Ê±£¬µ«Ò²Ã»ÓÐÃ÷È·½ûÖ¹¡£ÔÚûÓг¬Ê±µÄϵͳÖУ¬Apache1.2¾³£»áÏÝÓÚFIN_WAIT_2״̬ÖС£¶àÊýÇé¿öÏ£¬Õâ¸öÎÊÌâ¿ÉÒÔÓù©Ó¦ÉÌÌṩµÄTCP/IP²¹¶¡ÓèÒÔ½â¾ö¡£¶øÈç¹û¹©Ó¦É̲»Ìṩ²¹¶¡(Ö¸SunOS4 -- ¾¡¹ÜÓû§ÃdzÖÓÐÔÊÐí×Ô¼ºÐÞ²¹´úÂëµÄÐí¿ÉÖ¤)£¬ÄÇôֻÄܹرմ˹¦ÄÜ¡£
ʵÏֵķ½·¨ÓÐÁ½ÖÖ£¬ÆäÒ»ÊÇsocketÑ¡ÏîSO_LINGER £¬µ«ÊÇËƺõÃüÖÐ×¢¶¨£¬´ó¶àÊýTCP/IPÕ»¶¼´ÓδÓèÒÔÕýȷʵÏÖ¡£¼´Ê¹ÔÚÕýȷʵÏÖµÄÕ»ÖÐ(Ö¸Linux2.0.31)£¬´Ë·½·¨Ò²±»Ö¤Ã÷Æä´ú¼Û±ÈÏÂÒ»ÖÖ·½·¨¸ß°º¡£
Apache¶Ô´ËµÄʵÏÖ´úÂë´ó¶àλÓÚº¯Êýlingering_close(λÓÚhttp_main.c)ÖС£´Ëº¯Êý´óÖÂÐÎÈ磺
void lingering_close (int s)
{
char junk_buffer[2048];
/* shutdown the sending side */
shutdown (s, 1);
signal (SIGALRM, lingering_death);
alarm (30);
for (;;) {
select (s for reading, 2 second timeout);
if (error) break;
if (s is ready for reading) {
if (read (s, junk_buffer, sizeof (junk_buffer)) <= 0) {
break;
}
/* just toss away whatever is here */
}
}
close (s);
}
´Ë´úÂëÔÚÁ¬½Ó½áÊøʱ¶àÁËһЩ¿ªÏú£¬µ«ÕâÊÇ¿É¿¿ÊµÏÖËù±ØÐëµÄ¡£ÓÉÓÚHTTP/1.1Ô½À´Ô½Á÷ÐУ¬¶øÇÒËùÓÐÁ¬½Ó¶¼ÊÇÎȶ¨µÄ£¬´Ë¿ªÏú½«Óɸü¶àµÄÇëÇó¹²Í¬·Öµ£¡£Èç¹ûÄãÒªÍæ»ðÈ¥¹Ø±ÕÕâ¸ö¹¦ÄÜ£¬¿ÉÒÔ¶¨ÒåNO_LINGCLOSE £¬µ«¾ø²»ÍƼöÕâÑù×ö¡£ÓÈÆäÊÇ£¬Ëæ×ÅHTTP/1.1ÖйܵÀ»¯Îȶ¨Á¬½ÓµÄÆôÓã¬lingering_closeÒѾ³ÉΪ¾ø¶Ô±ØÐë¡£¶øÇÒ£¬¹ÜµÀ»¯Á¬½ÓËٶȸü¿ì£¬Ó¦¸Ã¿¼ÂÇÓèÒÔÖ§³Ö¡£
Scoreboard Îļþ
Apache¸¸½ø³ÌºÍ×Ó½ø³Ìͨ¹ýscoreboard½øÐÐͨѶ¡£Í¨¹ý¹²ÏíÄÚ´æÀ´ÊµÏÖµ±È»ÊÇ×îÀíÏëµÄ¡£ÔÚÎÒÃÇÔø¾Êµ¼ù¹ý»òÕßÌṩÁËÍêÕûÒÆÖ²µÄ²Ù×÷ϵͳÖУ¬¶¼Ê¹Óù²ÏíÄڴ棬ÆäÓàµÄÔòʹÓôÅÅÌÎļþ¡£´ÅÅÌÎļþ²»½öËÙ¶ÈÂý£¬¶øÇÒ²»¿É¿¿(¹¦ÄÜÒ²ÉÙ)¡£×ÐϸÔĶÁÄãµÄÌåϵËù¶ÔÓ¦µÄsrc/main/conf.hÎļþ£¬²¢²éÕÒUSE_MMAP_SCOREBOARD»òUSE_SHMGET_SCOREBOARD ¡£¶¨ÒåÆäÖÐÖ®Ò»(»òÕß·Ö±ðÀàËÆHAVE_MMAPºÍHAVE_SHMGET)£¬¿ÉÒÔʹ¹²ÏíÄÚÈݵÄÏà¹Ø´úÂëÉúЧ¡£Èç¹ûÄãµÄϵͳÌṩÆäËûÀàÐ͵Ĺ²ÏíÄÚÈÝ£¬ÔòÐèÒªÐÞ¸Äsrc/main/http_main.cÎļþ£¬²¢°Ñ±ØÐèµÄ¹Ò¹³Ìí¼Óµ½·þÎñÆ÷ÖС£(Ò²Çë·¢ËÍÒ»¸ö²¹¶¡¸øÎÒÃÇ)
×¢Ò⣺ÔÚ¶ÔLinuxµÄApache1.2ÒÆÖ²°æ±¾Ö®Ç°£¬Ã»ÓÐʹÓÃÄÚ´æ¹²Ïí£¬´ËʧÎóʹApacheµÄÔçÆÚ°æ±¾ÔÚLinuxÖбíÏֺܲ
DYNAMIC_MODULE_LIMIT
Èç¹ûÄã²»ÏëʹÓö¯Ì¬¼ÓÔØÄ£¿é(»òÕßÊÇÒòΪ¿´¼ûÁËÕâ¶Î»°£¬»òÕßÊÇΪÁË»ñµÃ×îºóÒ»µãµãÐÔÄÜÉϵÄÌá¸ß)£¬¿ÉÒÔÔÚ±àÒë·þÎñÆ÷ʱ¶¨Òå -DDYNAMIC_MODULE_LIMIT=0 £¬ÕâÑù¿ÉÒÔ½ÚʡΪ֧³Ö¶¯Ì¬¼ÓÔØÄ£¿é¶ø·ÖÅäµÄÄÚ´æ¡£
top
¸½Â¼£º×Ù¼£µÄÏêϸ·ÖÎö
ÔÚSolaris8µÄMPMÖУ¬Apache2.0.38ʹÓÃÒ»¸öϵͳµ÷ÓÃÒÔÊÕ¼¯×Ù¼££º
truss -l -p httpd_child_pid.
-l ²ÎÊýʹtruss¼Ç¼ÿ¸öÖ´ÐÐϵͳµ÷ÓõÄLWP(lightweight process--SolarisºËÐļ¶Ïß³Ì)µÄID¡£
ÆäËûϵͳ¿ÉÄÜʹÓò»Í¬µÄϵͳµ÷ÓÃ×·×Ù¹¤¾ß£¬ÖîÈçstrace, ktrace, par £¬ÆäÊä³ö¶¼ÊÇÏàËƵġ£
ÏÂÀýÖУ¬Ò»¸ö¿Í»§¶ËÏòhttpdÇëÇóÁËÒ»¸ö10KBµÄ¾²Ì¬Îļþ¡£¶Ô·Ç¾²Ì¬»òÄÚÈÝÐÉÌÇëÇóµÄ¼Ç¼»áÓкܴó²»Í¬(ÓÐʱҲºÜÄÑ¿´Ã÷°×)¡£
/67: accept(3, 0x00200BEC, 0x00200C0C, 1) (sleeping...)
/67: accept(3, 0x00200BEC, 0x00200C0C, 1) = 9
ÏÂÀýÖУ¬¼àÌýÏß³ÌÊÇ LWP #67 ¡£
×¢Òâ¶Ôaccept()´®Ðл¯Ö§³ÖµÄØÑ·¦¡£ÓëÕâ¸öÌØÊâƽ̨¶ÔÓ¦µÄMPMÔÚĬÈÏÇé¿öÏÂʹÓ÷Ǵ®ÐеÄaccept £¬³ýÁËÔÚ¼àÌý¶à¸ö¶Ë¿ÚµÄʱºò¡£
/65: lwp_park(0x00000000, 0) = 0
/67: lwp_unpark(65, 1) = 0
½ÓÊÜÁËÒ»¸öÁ¬½Óºó£¬¼àÌýÏ̻߳½ÐÑÒ»¸ö¹¤×÷Ïß³ÌÒÔ´¦Àí´ËÇëÇó¡£ÏÂÀýÖУ¬´¦ÀíÇëÇóµÄÄǸö¹¤×÷Ïß³ÌÊÇ LWP #65 ¡£
/65: getsockname(9, 0x00200BA4, 0x00200BC4, 1) = 0
ΪÁËʵÏÖÐéÄâÖ÷»ú£¬ApacheÐèÒªÖªµÀ½ÓÊÜÁ¬½ÓµÄ±¾µØsocketµØÖ·¡£ÔÚÐí¶àÇé¿öÏ£¬ÓпÉÄÜÎÞÐëÖ´Ðд˵÷ÓÃ(±ÈÈçûÓÐÐéÄâÖ÷»ú£¬»òÕßListenÖ¸ÁîÖÐûÓÐʹÓÃͨÅäµØÖ·)£¬µ«ÊÇÄ¿Ç°²¢Ã»ÓжԴË×÷ÓÅ»¯´¦Àí¡£
/65: brk(0x002170E8) = 0
/65: brk(0x002190E8) = 0
´Ëbrk()µ÷ÓÃÊÇ´Ó¶ÑÖзÖÅäÄÚ´æµÄ£¬ËüÔÚϵͳµ÷ÓüǼÖв¢²»¶à¼û£¬ÒòΪhttpdÔÚ¶àÊýÇëÇó´¦ÀíÖÐʹÓÃÁË×Ô¼ºµÄÄÚ´æ·ÖÅäÆ÷(apr_poolºÍapr_bucket_alloc)¡£ÏÂÀýÖУ¬httpd¸Õ¸ÕÆô¶¯£¬ËùÒÔËü±ØÐëµ÷ÓÃmalloc()ÒÔ·ÖÅäÔʼÄÚ´æ¿éÓÃÓÚ×Ô¼ºµÄÄÚ´æ·ÖÅäÆ÷¡£
/65: fcntl(9, F_GETFL, 0x00000000) = 2
/65: fstat64(9, 0xFAF7B818) = 0
/65: getsockopt(9, 65535, 8192, 0xFAF7B918, 0xFAF7B910, 2190656) = 0
/65: fstat64(9, 0xFAF7B818) = 0
/65: getsockopt(9, 65535, 8192, 0xFAF7B918, 0xFAF7B914, 2190656) = 0
/65: setsockopt(9, 65535, 8192, 0xFAF7B918, 4, 2190656) = 0
/65: fcntl(9, F_SETFL, 0x00000082) = 0
½Ó×Å£¬¹¤×÷Ïß³Ìʹ¿Í»§¶ËÁ¬½Ó´¦ÓÚ·Ç×èÈûģʽ¡£setsockopt()ºÍgetsockopt()µ÷ÓÃÊÇSolarisµÄlibc¶ÔsocketÖ´ÐÐfcntl()Ëù±ØÐëµÄ¡£
/65: read(9, " G E T / 1 0 k . h t m".., 8000) = 97
¹¤×÷Ï̴߳ӿͻ§¶Ë¶ÁÈ¡ÇëÇó¡£
/65: stat("/var/httpd/apache/httpd-8999/htdocs/10k.html", 0xFAF7B978) = 0
/65: open("/var/httpd/apache/httpd-8999/htdocs/10k.html", O_RDONLY) = 10
ÕâÀhttpd±»ÅäÖÃΪ"Options FollowSymLinks"ºÍ"AllowOverride None"¡£ËùÒÔ£¬ÎÞÐë¶Ôÿ¸ö±»ÇëÇóÎļþ·¾¶ÖеÄĿ¼ִÐÐlstat()£¬Ò²²»ÐèÒª¼ì²é.htaccessÎļþ£¬Ëü¼òµ¥µØµ÷ÓÃstat()ÒÔ¼ì²é´ËÎļþÊÇ·ñ´æÔÚ£¬ÒÔ¼°ÊÇÒ»¸öÆÕͨµÄÎļþ»¹ÊÇÒ»¸öĿ¼¡£
/65: sendfilev(0, 9, 0x00200F90, 2, 0xFAF7B53C) = 10269
´ËÀýÖУ¬httpd¿ÉÒÔͨ¹ýµ¥¸öϵͳµ÷ÓÃsendfilev()·¢ËÍHTTPÏìӦͷºÍ±»ÇëÇóµÄÎļþ¡£SendfileÒò²Ù×÷ϵͳ»áÓÐËù²»Í¬£¬ÓÐЩϵͳÖУ¬ÔÚµ÷ÓÃsendfile()ÒÔÇ°£¬ÐèÒªµ÷ÓÃwrite()»òwritev()ÒÔ·¢ËÍÏìӦͷ¡£
/65: write(4, " 1 2 7 . 0 . 0 . 1 - ".., 78) = 78
´Ëwrite()µ÷ÓÃÔÚ·ÃÎÊÈÕÖ¾ÖжÔÇëÇó×÷Á˼Ǽ¡£×¢Ò⣬ÆäÖÐûÓжÔtime()µÄµ÷ÓõļǼ¡£ÓëApache1.3²»Í¬£¬Apache2.0ʹÓÃgettimeofday()ÒÔ²éѯʱ¼ä¡£ÔÚÓÐЩ²Ù×÷ϵͳÖУ¬±ÈÈçLinuxºÍSolaris£¬gettimeofdayÓÐÒ»¸öÓÅ»¯µÄ°æ±¾£¬Æ俪Ïú±ÈÒ»¸öÆÕͨµÄϵͳµ÷ÓÃҪСһµã¡£
/65: shutdown(9, 1, 1) = 0
/65: poll(0xFAF7B980, 1, 2000) = 1
/65: read(9, 0xFAF7BC20, 512) = 0
/65: close(9) = 0
¹¤×÷Ï̶߳ÔÁ¬½Ó×÷ÑӳٵĹرա£
/65: close(10) = 0
/65: lwp_park(0x00000000, 0) (sleeping...)
×îºó£¬¹¤×÷Ï̹߳رշ¢ËÍÍêµÄÎļþºÍ¿é£¬Ö±µ½¼àÌý½ø³Ì°ÑËüÖ¸ÅɸøÁíÒ»¸öÁ¬½Ó¡£
/67: accept(3, 0x001FEB74, 0x001FEB94, 1) (sleeping...)
Æä¼ä£¬¼àÌý½ø³Ì¿ÉÒÔÔÚ°ÑÒ»¸öÁ¬½ÓÖ¸ÅɸøÒ»¸ö¹¤×÷½ø³ÌºóÁ¢¼´½ÓÊÜÁíÒ»¸öÁ¬½Ó(µ«ÊÇÈç¹ûËùÓй¤×÷½ø³Ì¶¼´¦ÓÚæµ״̬£¬Ôò»áÊÜMPMÖеÄһЩÒç³ö¿ØÖÆÂß¼µÄÖÆÔ¼)¡£ËäÈ»ÔÚ´ËÀýÖв¢²»Ã÷ÏÔ£¬ÔÚ¹¤×÷Ï̸߳սÓÊÜÁËÒ»¸öÁ¬½ÓÖ®ºó£¬ÏÂÒ»¸öaccept()»á(Ôڸ߸ººÉµÄÇé¿öϸü»á)Á¢¼´²¢ÐвúÉú¡£