ãªãWindowsã Windowsã®äŒæ¥éšéã§ã¯ããµãŒããŒäžããã³ã¯ãŒã¯ã¹ããŒã·ã§ã³äžã§ç°¡åã§ããå€ãã®å Žåãå¿ èŠãªããã°ã©ã ã§ãã ãŸãããã©ãããã©ãŒã ã®ãããã®èŠä»¶ãããããšãã°ãã¯ã©ã€ã¢ã³ãããè¡šæãããæçµéåã®åœ¢åŒã§ã¯ãã©ãã«ãã¢ã¯ã»ã¹ã§ããŸããã
Windowsã
ãããã®å¶éããã£ãŠããnginxã¯ãå®å®æ§ãã¡ã¢ãªæ¶è²»ããããŠæãéèŠãªããã©ãŒãã³ã¹ãå«ãå€ãã®èŠå ã«ã€ããŠãWindowsã®äžã®ã»ãšãã©ãã¹ãŠã®WebãµãŒããŒã«ãªããºãäžããããšã«æ³šæããå¿ èŠããããŸãã
ç§ã¯ããã«è¯ããã¥ãŒã¹ãå ±æããããšãæ¥ãã§ããŸã-é«æ§èœã®ããã«éèŠãªå¶éãããã«ãããŸããçªã®äžã§ngiâânxã䜿çšããå Žåãå®éã«ã¯ãããŸãããéèŠãªãã®ã®æåŸã¯ãé«ã確çã§ããã«æ¶ããŸãã ããããé çªã«...
ããã§ã¯ ãnginx 4ãŠã£ã³ããŠã®æ¢ç¥ã®åé¡ã«ã€ããŠèª¬æããŸã ã
- ã¯ãŒã¯ãããŒã¯ãæ倧1024ã®åææ¥ç¶ãåŠçã§ããŸãã
- ãããã®ããŒãžã§ã³ã®Windowsã§ã¯ã¢ãã¬ã¹ç©ºéã®ã©ã³ãã åãæå¹ã«ãªã£ãŠãããããå ±æã¡ã¢ãªã®ãµããŒããå¿ èŠãšãããã£ãã·ã¥ããã³ãã®ä»ã®ã¢ãžã¥ãŒã«ã¯Windows Vista以éã§ã¯æ©èœããŸããã
- è€æ°ã®ã¯ãŒã¯ãããŒãå®è¡ããããšã¯å¯èœã§ãããå®éã«æ©èœããã®ã¯ãã®ãã¡ã®1ã€ã ãã§ãã
ç§ã¯æ³šæãå°ãå€ããŸãã ãããã®å¶éãç解ããã®ã¯ããã®é åºã§ãæŽå²çã«ãåé¡ãããŠããŸãã
1024ã®åææ¥ç¶
å®éãããã¯çå®ã§ã¯ãªãããããçå®ã§ã¯ãããŸãã-倪å€ãããnginxã¯ãã®å¶éãªãã§Windowsã§æ§ç¯ã§ããŸãã-æ§ç¯æ®µéã§å¿ èŠãªæ¥ç¶ã®æ°ã«çãã
FD_SETSIZE
ã決å®ããå¿ èŠããããŸããã
ããšãã°ãVSã®å Žåããã£ã¬ã¯ãã£ã
--with-cc-opt=-DFD_SETSIZE=10240
è¿œå ãããšãæ§æã§
worker_connections 10240;
ãæå®ãããšãnginxã¯ãŒã«ãŒã¯10Kã®åææ¥ç¶ã管çã§ããŸã
worker_connections 10240;
ã
å ±æã¡ã¢ãªã®ãµããŒããå¿ èŠãšãããã£ãã·ã¥ããã³ãã®ä»ã®ã¢ãžã¥ãŒã«
æè¿ãŸã§ããããã®ãã¹ãŠã®æ©èœãšã¢ãžã¥ãŒã«ã¯ãx64ããŒãžã§ã³ããããŸãã¯ããã©ã«ãã§ã·ã¹ãã å šäœãASLRããªã³ã«ããŠåäœããWindowsã§å®éã«åäœããŸããã§ããã
ããã«ãnginxã®ASLRãç¡å¹ã«ããŠãäœãå€ãããŸããã å ±æã¡ã¢ãªãæäœããããã®é¢æ°ã¯ãã«ãŒãã«ã®å¥¥æ·±ãã«é ç·ãããŠããŸãã ASLRïŒããã³ããããDEPãäœããã®çç±ã§åäœããŸããã§ããïŒã¯ãã·ã¹ãã å šäœã§ç¡å¹ã«ããå¿ èŠããããŸãã
ããã¯å®éã«ã¯ãæ©èœã®å°ããªãªã¹ãã§ã¯ãããŸããïŒãã£ãã·ã¥ããŸãŒã³ããããããlimit_reqãªã©ã ãªã© ã¡ãªã¿ã«ãå ±æã¡ã¢ãªã®ãµããŒããªãã§ã¯ã3çªç®ã®å¶éãã€ãŸãã Windowsã§è€æ°ã®ã¯ãŒã«ãŒã®ãµããŒããå®è£ ããŸãã
ç§ã¯ããã«èŠåŽããã®ã§èªè ãéå±ãããã€ããã¯ãããŸããããMaxïŒ mdouninã«æè¬ïŒãšäžç·ã«ãªãªãŒã¹ããŒãžã§ã³ãŸã§ãããŸããã ããã«ã€ããŠã¯ãèå³ã®ããæ¹ã¯ããã¿ãã¬ãhg.nginx.orgãŸãã¯githubã®ãœãŒã¹ãåç §ããŠãã ãã...
ã¡ãã£ãšããçè«...
å
±æã¡ã¢ãªèªäœããã¢ãã¬ã¹ç©ºéã®ã©ã³ãã åã§äœ¿çšã§ããŸãã ASLRãæå¹ã«ãããšãå¥ã®ã¢ãã¬ã¹ã®å¥ã®ããã»ã¹ã®ãåãã¡ã¢ãªããžã®ãã€ã³ã¿ãã»ãŒç¢ºå®ã«ååŸã§ããããã«ãªããŸãã ããã¯ããã®ã¹ããŒã¹èªäœã®ã³ã³ãã³ãã«çŽæ¥ãã€ã³ã¿ãŒïŒå¥åãã€ã³ã¿ãŒïŒãå«ãŸããŠããªãéããããã»ã©éèŠã§ã¯ãããŸããã ã€ãŸã shmemã®éå§ã¢ãã¬ã¹ããã®ãªãã»ãããã€ã³ã¿ãŒã¯æå¹ã§ãããçŽæ¥ãã€ã³ã¿ãŒã¯ãã®ãŸãŸã§ã¯ãããŸããã
ãããã£ãŠãnginxã®å ±æmemå ã®ãã€ã³ã¿ãŒã§æ©èœãããã¹ãŠã®æ©èœãæžãæããããšãªãããã¹ãŠã®ã¯ãŒã¯ããã»ã¹ã®äžå®ã®ã¢ãã¬ã¹ã§shmemãžã®ãªã³ã¯ããŠã£ã³ããŠã«åŒ·å¶çã«çºè¡ãããããšã欺ããªãã·ã§ã³ã¯1ã€ã ãã§ãã ãŸããå®éã«ã¯ãã¹ãŠãããã»ã©é£ãããããŸããã
ããã«ã€ããŠã®è°è«ã®å§ãŸãã¯ããã§èªãããšãã§ããŸã ã ãšããã§ãããã·ã ã¯ãç§ãèŠéããåé¡ïŒãªãããã³ã°ïŒãä¿®æ£ããŸãããããã¯ãã¯ãŒã«ãŒãåèµ·åããåŸã«çºçããããšããããŸãïŒãã®å Žã§ãªããŒãããŸãïŒã
VivaãªãŒãã³ãœãŒã¹ïŒ
ãããã£ãŠãnginxã®å ±æmemå ã®ãã€ã³ã¿ãŒã§æ©èœãããã¹ãŠã®æ©èœãæžãæããããšãªãããã¹ãŠã®ã¯ãŒã¯ããã»ã¹ã®äžå®ã®ã¢ãã¬ã¹ã§shmemãžã®ãªã³ã¯ããŠã£ã³ããŠã«åŒ·å¶çã«çºè¡ãããããšã
ããã«ã€ããŠã®è°è«ã®å§ãŸãã¯ããã§èªãããšãã§ããŸã ã ãšããã§ãããã·ã ã¯ãç§ãèŠéããåé¡ïŒãªãããã³ã°ïŒãä¿®æ£ããŸãããããã¯ãã¯ãŒã«ãŒãåèµ·åããåŸã«çºçããããšããããŸãïŒãã®å Žã§ãªããŒãããŸãïŒã
VivaãªãŒãã³ãœãŒã¹ïŒ
ã€ãŸã å ¬åŒã«ã¯ããã®å¶éã¯2015幎4æ28æ¥ä»ãã®ãªãªãŒã¹1.9.0ã§ã¯ç¡å¹ã«ãªããŸããã
Feature: shared memory can now be used on Windows versions with address space layout randomization.
å®éã«æ©èœããã¯ãŒã¯ãããŒã¯1ã€ã ãã§ãã
Nginxã«ã¯ããã¹ã¿ãŒããã»ã¹ãšãã¯ãŒã«ãŒãŸãã¯ã¯ãŒã«ãŒãšåŒã°ããåããã»ã¹ããããŸãã
Windowsã§ã¯ãnginxã¯ããã€ãã®ã¯ãŒã¯ãããŒãå®è¡ã§ããŸãã æ§æã§ã
worker_processes 4;
ããæå®ãããšããŠã£ã¶ãŒãã¯4ã€ã®åã¯ãŒã¯ãããŒãéå§ããŸãã åé¡ã¯ããã®ãã¡ã®1ã€ã ããïŒSO_REUSEADDRã䜿çšããŠïŒãã¹ã¿ãŒãããªã¹ããŒæ¥ç¶ããçããããšã§ãå®éã«ãã®ãœã±ããããªãã¹ã³ããããšã§ãã çä¿¡æ¥ç¶ãåãå ¥ããŸãã ãã®çµæãä»ã®ã¯ãŒã«ãŒ-çä¿¡æ¥ç¶ãªã-äœæ¥ãªãã
ãã®å¶éã¯winsockã®æè¡çãªå®è£ ã«é¢é£ããŠãããWindowsäžã®ãã¹ãŠã®ã¯ãŒã¯ããã»ã¹ã«å¯ŸããŠåæ£ãªã¹ããŒæ¥ç¶ãååŸããå¯äžã®æ¹æ³ã¯ããã¹ã¿ãŒããã»ã¹ãããœã±ãããè€è£œããããšã§ãã ãœã±ããããç¶æ¿ããããã³ãã«ã䜿çšããŸãã
å®è£ ã®è©³çŽ°ã«èå³ã®ãã人ã¯ããããŸã§ã®githubã§ã®ã¿ããã¿ãã¬ããœãŒã¹ã§ããããèŠãããšãã§ããŸãã
詳现
ããããã
ã䜿çšããŠåããã»ã¹ïŒ
ïŒãéå§ãããœã±ããã®äœææã«
ãTRUEã«èšå®ããŠããã»ãšãã©ã®å ŽåæåããŸããã ãã®ãã³ãã«ã䜿çšããã¯ãŒã¯ãããŒã§ã¯ãã倱æïŒ10022ïŒç¡å¹ãªåŒæ°ãæå®ãããŸããïŒãã衚瀺ãããŸãã ãŸãã
ã䜿çšããŠãã®ãœã±ããããæ£åžžã«ãè€è£œãããšãè€è£œããããã³ãã«ã¯ããœã±ããã§æ©èœããé¢æ°ãåãå ¥ããŸããïŒãããããšã©ãŒ10038-WSAENOTSOCKã§ïŒã
ãªããããèµ·ããã®ãã MSDNããã®åŒçšãéããŸã-DuplicateHandle ïŒ
ãã®çµæãã¯ãŒã¯ãããŒã§ã¯ããŒã³ãœã±ãããäœæããããã«å¿ èŠãªWSADuplicateSocketãããŠã£ã¶ãŒããåä¿¡ããæ å ±ãåããã»ã¹ã«éç¥ããããã«ã MSDNã§èª¬æãããŠããããã«IPCãªã©ã®äœãã䜿çšããããå ±æã¡ã¢ãªãä»ããŠè»¢éãã2ã€ã®ãªãã·ã§ã³ããããŸãïŒå¹žããªããšã«ããã§ã«ä¿®æ£æžã¿ã§ãïŒã
2çªç®ã®ãªãã·ã§ã³ã䜿çšããããšã«ããŸããã ããã¯2ã€ã®æ¹æ³ã®äžã§æãæéãããããæ¥ç¶ç¶æ¿ãå®è£ ããæãéãæ¹æ³ã ãšæããŸãã
以äžã¯ããŠã£ã³ããŠã®äžã§ã¯ãŒã¯ãããŒãéå§ããããã®ã¢ã«ãŽãªãºã ã®å€æŽã§ãïŒ
ããŒã¯ãããŠã
ïŒã
å¿ èŠã«å¿ããŠãä¿®æ£ã«é¢ããè°è«ãžã®ãªã³ã¯ããããŸãã
bInheritHandle=TRUE
ã䜿çšããŠåããã»ã¹ïŒ
CreateProcess
ïŒãéå§ãããœã±ããã®äœææã«
SECURITY_ATTRIBUTES::bInheritHandle
ãTRUEã«èšå®ããŠããã»ãšãã©ã®å ŽåæåããŸããã ãã®ãã³ãã«ã䜿çšããã¯ãŒã¯ãããŒã§ã¯ãã倱æïŒ10022ïŒç¡å¹ãªåŒæ°ãæå®ãããŸããïŒãã衚瀺ãããŸãã ãŸãã
DuplicateHandle
ã䜿çšããŠãã®ãœã±ããããæ£åžžã«ãè€è£œãããšãè€è£œããããã³ãã«ã¯ããœã±ããã§æ©èœããé¢æ°ãåãå ¥ããŸããïŒãããããšã©ãŒ10038-WSAENOTSOCKã§ïŒã
ãªããããèµ·ããã®ãã MSDNããã®åŒçšãéããŸã-DuplicateHandle ïŒ
ãœã±ããã ãšã©ãŒã¯è¿ãããŸããããéè€ãããã³ãã«ã¯ã¿ãŒã²ããããã»ã¹ã§Winsockã«ãã£ãŠèªèãããªãå ŽåããããŸãã ãŸããDuplicateHandleã䜿çšãããšãåºç€ãšãªããªããžã§ã¯ãã®å éšåç §ã«ãŠã³ãã劚ããããŸãã ãœã±ãããã³ãã«ãè€è£œããã«ã¯ãWSADuplicateSocketé¢æ°ã䜿çšããŸããåé¡ã¯ãWSADuplicateSocketã䜿çšããŠãã³ãã«ãè€è£œããã«ã¯ãäºåã«ããã»ã¹ã®PIDãç¥ãå¿ èŠãããããšã§ãã ããã»ã¹ãéå§ããåã«ãããè¡ãããšã¯ã§ããŸããã
ãã®çµæãã¯ãŒã¯ãããŒã§ã¯ããŒã³ãœã±ãããäœæããããã«å¿ èŠãªWSADuplicateSocketãããŠã£ã¶ãŒããåä¿¡ããæ å ±ãåããã»ã¹ã«éç¥ããããã«ã MSDNã§èª¬æãããŠããããã«IPCãªã©ã®äœãã䜿çšããããå ±æã¡ã¢ãªãä»ããŠè»¢éãã2ã€ã®ãªãã·ã§ã³ããããŸãïŒå¹žããªããšã«ããã§ã«ä¿®æ£æžã¿ã§ãïŒã
2çªç®ã®ãªãã·ã§ã³ã䜿çšããããšã«ããŸããã ããã¯2ã€ã®æ¹æ³ã®äžã§æãæéãããããæ¥ç¶ç¶æ¿ãå®è£ ããæãéãæ¹æ³ã ãšæããŸãã
以äžã¯ããŠã£ã³ããŠã®äžã§ã¯ãŒã¯ãããŒãéå§ããããã®ã¢ã«ãŽãªãºã ã®å€æŽã§ãïŒ
*
ããŒã¯ãããŠã
*
ïŒã
- ãã¹ã¿ãŒããã»ã¹ã¯ãã¹ãŠã®ãªã¹ããŒãœã±ãããäœæããŸãã
- [ãµã€ã¯ã«]ãã¹ã¿ãŒããã»ã¹ã¯ã¯ãŒã¯ãããŒãäœæããŸãã
-
*
[win32]ãŠã£ã¶ãŒãã¯æ°ããé¢æ°ngx_share_listening_sockets
åŒã³åºããŸããåãªã¹ããŒãœã±ããã«ã€ããŠããã®æ°ããã¯ãŒã«ãŒå°çšã®æ å ±ãïŒç¶æ¿çšã«ïŒngx_share_listening_sockets
ïŒpidã®WSADuplicateSocketãä»ããŠãè€è£œãïŒãshinfoïŒãããã³ã«æ§é ïŒ - ãã¹ã¿ãŒããã»ã¹ã¯ãã¯ãŒã«ãŒãæºåå®äºã€ãã³ãïŒã€ãã³ã "worker_nnn"ïŒãèšå®ãããŸã§åŸ æ©ããŸãã
-
*
[win32]ã¯ãŒã¯ãããŒã¯ãæ°ããé¢æ°ngx_get_listening_share_info
ãå®è¡ããŠshinfoç¶æ¿æ å ±ãååŸããŸããããã¯ããã¹ã¿ãŒããã»ã¹ã®å ±æãªã¹ããŒãœã±ããã®æ°ãããœã±ããèšè¿°åãäœæããããã«äœ¿çšãããŸãã -
*
[win32]ã¯ãŒã¯ãããŒã¯ããã¹ã¿ãŒããã»ã¹ããã®shinfoæ å ±ã䜿çšããŠãã¹ãŠã®ãªã¹ããŒãœã±ãããäœæããŸãã - ã¯ãŒã«ãŒããã»ã¹ã¯ã€ãã³ããèšå®ããŸã-ã€ãã³ã "worker_nnn";
- ãã¹ã¿ãŒããã»ã¹ã¯åŸ æ©ãåæ¢ãã[cycle]ãç¹°ãè¿ããŠæ¬¡ã®ã¯ãŒã¯ãããŒãäœæããŸãã
å¿ èŠã«å¿ããŠãä¿®æ£ã«é¢ããè°è«ãžã®ãªã³ã¯ããããŸãã
ãã®çµæãwindowsã§ã®nginxã¯ãããªãã¹ã³ãã®èŠ³ç¹ããNãéå§ããæãéèŠãªããšã«ã¯ãæ¥ç¶ã確ç«ããçä¿¡æ¥ç¶ãå®éã«äžŠè¡ããŠåŠçããã¯ãŒã¯ãããŒãéå§ããŸãã
ãã®ä¿®æ£ã¯å®éã«ã¯ãããŒã«ãªã¯ãšã¹ããã«ãããŸãïŒå€æŽã»ãããnginx-devã«éä¿¡ããŸããïŒããããšãã°githubããããŠã³ããŒãããŠã Windowsã§èªåã§ãã«ãããããšã§ãæ¢ã«è©Šãããšãã§ããŸãã åžæãã人ãããã°ãã©ããã«ãã€ããªãæçš¿ããŸãã
ç§ã¯ããªãé·ãéããŒããŠã§ã¢ãæ·åãããã¹ããšè² è·ã®ãããã¹ã¯ãªãããã®äžã§ãããè¿œããããŸãã-ãã®çµæããã¹ãŠã®ã¯ãŒã«ãŒã¯ã»ãŒåçã«ããŒããããå®éã«äžŠè¡ããŠåäœããŸãã ãŸããnginxãåèµ·åããããã«ãªã³ã¶ãã©ã€ïŒãªããŒãïŒãè©Šã¿ãåŸè ã®ãã¯ã©ãã·ã¥ããã·ãã¥ã¬ãŒãããŠäžéšã®ã¯ãŒã«ãŒãã©ã³ãã ã«ã殺ãããŸããã
ãããŸã§ã®ãšãããå¯äžã®ãæ¬ é¥ããçŸããŸãããç§èŠ-ããªããå®è¡ããå Žå
ããªã¹ããŒãã®ãªã¹ãã«ã¯ãã¹ã¿ãŒããã»ã¹ã®ã¿ã衚瀺ãããŸãããå®éã«ã¯æ¥ç¶ã確ç«ããããšã¯ãªããåã¯ãŒã¯ãããŒã®ã¿ã確ç«ããŸããnetstat /abo | grep LISTEN
ã¡ãªã¿ã«ããããŸã§ã®ç§ã®çµéšã§ã¯ãWindowsãã©ãããã©ãŒã ã®
accept_mutex
ã¯ããããã
accept_mutex off;
ããç¡å¹ã«ããå¿ èŠããããš
accept_mutex off;
å°ãªããšãç§ã®ãã¹ãã·ã¹ãã ã§ã¯ã
accept_mutex
æå¹
accept_mutex
ãããšãç¡å¹ã«ããå Žåãããå€§å¹ ã«é ããªããŸããã ããããç§ã¯èª°ãããããå®éšçã«ãã§ãã¯ãã¹ãã ãšæããŸãïŒã³ã¢ã®æ°ãã¯ãŒã«ãŒãããŒãã¢ã©ã€ãæ¥ç¶ãªã©ã®ãã©ã¡ãŒã¿ãŒã®æã«äŸåããããïŒã
ããŠãããã©ãŒãã³ã¹æ¯èŒ
ãã¹ãã¯Windows7ã§è¡ãããŸã-i5-2400 CPU @ 3.10GHzïŒ4ã³ã¢ïŒã
ãªã¯ãšã¹ãïŒéçã452ãã€ãïŒ+ããããŒïŒ-å°ããªgifã¢ã€ã³ã³ã
åŽåè xåæã | 1 x 5 ** NF | 2Ã5 | 4 x 5 | 4 x 15 |
---|---|---|---|---|
ååŒ | 5624ããã | 11048ããã | 16319ããã | 16732ããã |
åšåº«ç¶æ³ | 100.00ïŒ | 100.00ïŒ | 100.00ïŒ | 100.00ïŒ |
çµéæé | 2.97ç§ | 2.97ç§ | 2.97ç§ | 2.96ç§ |
転éãããããŒã¿ | 2.42 MB | 4.76 MB | 7.03 MB | 7.21 MB |
å¿çæé | 0.00ç§ | 0.00ç§ | 0.00ç§ | 0.00ç§ |
ååŒã¬ãŒã | 1893.60ãã©ã³ã¹/ç§ | 3719.87ãã©ã³ã¹/ç§ | 5496.46ãã©ã³ã¹/ç§ | 5645.07ãã©ã³ã¹/ç§ |
ã¹ã«ãŒããã | 0.82 MB /ç§ | 1.60 MB /ç§ | 2.37 MB /ç§ | 2.43 MB /ç§ |
䞊è¡æ§ | 4.99 | 4.99 | 4.99 | 14.92 |
æåãããã©ã³ã¶ã¯ã·ã§ã³ | 5624 | 11048 | 16319 | 16732 |
倱æãããã©ã³ã¶ã¯ã·ã§ã³ | 0 | 0 | 0 | 0 |
æé·ãã©ã³ã¶ã¯ã·ã§ã³ | 0.11 | 0.11 | 0.11 | 0.11 |
æçååŒ | 0.00 | 0.00 | 0.00 | 0.00 |
ãŸããnginxãWindowsã®äžã«ããããŸãã