±¾ÎÄʵÀý½²ÊoÁËÈÃÄaµÄPHP7¸u¿iÖ®HugepageÓè¡£ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
PHP7¸Õ¸Õ*¢²¼ÁËRC4, °uº¬Ò»Ð(C)bugÐÞ¸´ºÍÒ»¸oÎÒÃÇ×iеÄÐÔÄÜÌaÉý³É¹u£¨NEWS£(C)£¬ ÄǾÍÊÇ¡±HugePageFy PHP TEXT segment¡±£¬ ͨ¹ýÆoÓÃÕa¸oÌØÐÔ£¬PHP7»a°Ñ×ÔÉiµÄTEXT¶Î£¨Ö´ÐÐÌa£(C)¡±Å²¡°µ½HuagepageÉÏ£¬Ö®Ç°µÄ²aÊÔ£¬ÎÒÃÇÄÜÎȶ¨µÄÔÚWordpressÉÏ¿´µ½2%~3%µÄQPSÌaÉý¡£
¹ØÓÚHugepageÊÇɶ£¬¼oµ¥µÄ˵ϾÍÊÇĬÈϵÄÄÚ´aeÊÇÒÔ4KBÖÒ³µÄ£¬¶øÐeÄaµØÖºÍÄÚ´aeµØÖ*ÊÇÐeҪת»»µÄ£¬ ¶øÕa¸oת»»ÊÇÒª²e±iµÄ£¬CPUΪÁ˼ÓËÙÕa¸o²e±i¹ý³Ì¶¼»aÄÚ½¨TLB£¨Translation Lookaside Buffer£(C)£¬ ÏÔ¶øÒ×¼uÈç¹uÐeÄaҳԽС£¬±iÀiµÄÌoÄ¿ÊýÒ²¾ÍÔ½¶a£¬¶øTLB´oСÊÇÓÐÏ޵ģ¬ÌoÄ¿ÊýÔ½¶aTLBµÄCache MissÒ²¾Í»aÔ½¸ß£¬ ËuÒÔÈç¹uÎÒÃÇÄÜÆoÓôoÄÚ´aeÒ³¾ÍÄܼa½Ó½µµÍÕa¸oTLB Cache Miss£¬ÖÁÓÚÏeϸµÄ½eÉÜ£¬GoogleÒ»ËÑÒ»´o¶ÑÎҾͲ»×¸ÊoÁË£¬ÕaÀiÖ÷Ҫ˵Ã÷ÏÂÈçºÎÆoÓÃÕa¸oÐÂÌØÐÔ£¬ ´Ó¶ø´øÀ´Ã÷ÏÔµÄÐÔÄÜÌaÉý¡£
еÄKernelÆoÓÃHugepageÒѾ±aµÃdz£ÈÝÒ×ÁË£¬ÒÔÎҵĿª¢ÐeÄa»uΪÀý(Ubuntu Server 14.04£¬Kernel 3.13.0-45), Èç¹uÎÒÃDze¿´ÄÚ´aeÐÅÏ¢£º
$ cat /proc/meminfo | grep Huge
AnonHugePages: 444416 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
¿É¼uÒ»¸oHugepageµÄsizeÊÇ2MB, ¶øµ±Ç°²¢Ã»ÓÐÆoÓÃHugePages. ÏÖÔÚÈÃÎÒÃÇÏȱaÒePHP RC4, ¼ÇµÃÒ»¶¨²»Òª¼Ó£º ¨Cdisable-huge-code-pages £¨Õa¸oÐÂÌØÐÔÊÇĬÈÏÆoÓõģ¬ Äa¼ÓÁËÕa¸o¾Í¹ØÁË£(C)
È»ºoÅaÖÃopcache, ´ÓPHP5.5¿ªÊ¼OpcacheÒѾÊÇĬÈÏÆoÓñaÒeµÄ£¬µ«ÊÇÊDZaÒe¶¯Ì¬¿aµÄ£¬ ËuÒÔÎÒÃÇ»¹ÊÇÒªÔÚphp.iniÖÐÅaÖüÓÔØÏ¡£
zend_extension=opcache.so
Õa¸oÐÂÌØÐÔÊÇ×oÔÚOpcacheÀiµÄ£¬ËuÒÔҲҪͨ¹ýOpcacheÆoÓÃÕa¸oÌØÐÔ£¨Í¨¹ýÉeÖÃopcache.huge_code_pages=1£(C)£¬ ¾ßÌaµÄÅaÖãº
opcache.huge_code_pages=1
ÏÖÔÚÈÃÎÒÃÇÅaÖÃOS£¬ *ÖÅaÒ»Ð(C)Hugepages£º
$ sudo sysctl vm.nr_hugepages=128
vm.nr_hugepages = 128
ÏÖÔÚÈÃÎÒÃÇÔٴμi²eÄÚ´aeÐÅÏ¢:
$ cat /proc/meminfo | grep Huge
AnonHugePages: 444416 kB
HugePages_Total: 128
HugePages_Free: 128
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
¿ÉÒÔ¿´µ½ÎÒÃÇ*ÖÅaµÄ128¸oHugepagesÒѾ¾ÍÐ÷ÁË£¬ È»ºoÎÒÃÇÀ´Æo¶¯php-fpm:
$ /home/huixinchen/local/php7/sbin/php-fpm
[01-Oct-2015 09:33:27] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[01-Oct-2015 09:33:27] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
ÏÖÔÚ£¬ Ôٴμi²eÄÚ´aeÐÅÏ¢:
$ cat /proc/meminfo | grep Huge
AnonHugePages: 411648 kB
HugePages_Total: 128
HugePages_Free: 113
HugePages_Rsvd: 27
HugePages_Surp: 0
Hugepagesize: 2048 kB
˵µ½ÕaÀi£¬Èç¹uHugepages¿ÉÓ㬠ÆaʵOpcacheÒ²»aÓÃHugepagesÀ´´ae´¢opcodes»º´ae£¬ ËuÒÔΪÁËÑeÖ¤opcache.huge_code_pagesÈʵÉuЧ£¬ ÎÒÃDz»Á¹Ø±Õopcache.huge_code_pages, È»ºoÔÙÆo¶¯Ò»´Îºo¿´ÄÚ´aeÐÅÏ¢£º
$ cat /proc/meminfo | grep Huge
AnonHugePages: 436224 kB
HugePages_Total: 128
HugePages_Free: 117
HugePages_Rsvd: 27
HugePages_Surp: 0
Hugepagesize: 2048 kB
¿É¼u¿ªÆoÁËhuge_code_pagesÒÔºo£¬ fpmÆo¶¯ºo¶aÓÃÁË4¸opages, ÏÖÔÚÎÒÃǼi²eÏÂphp-fpmµÄtext´oС£º
$ size /home/huixinchen/local/php7/sbin/php-fpm
text data bss dec hex filename
10114565 695200 131528 10941293 a6f36d /home/huixinchen/local/php7/sbin/php-fpm
¿É¼utext¶ÎÓÐ10114565¸o×Ö½Ú´oС£¬ ×ܹ²ÐeÒªÕ¼ÓÃ4.8¸o×oÓÒµÄ2MµÄpages£¬ ¿¼Âǵ½¶ÔÆeÒÔºo£¨Î²²¿²»×a2M Page²¿Ö²»Å²¶¯£(C)£¬ ÉeÇe4¸opages£¬ ÕýºÃºÍÎÒÃÇ¿´µ½µÄÏau¡£
˵Ã÷ÅaÖóɹ¦£¡ Enjoy £¡
µ«ÊÇÓÐÑÔÔÚÏÈ£¬ ÆoÓôËÌØÐÔÒÔºo£¬ »aÔi³ÉÒ»¸oÎÊÌa¾ÍÊÇÄaÈç¹u³¢ÊÔͨ¹ýPerf report/anno È¥profilingµÄʱºo£¬ »a¢ÏÖuºÅ¶ªÊ§(valgrind, gdb²»ÊÜÓ°Ïi), Õa¸oÖ÷ÒªÔÒoÊÇPerfµÄÉe¼Æ²ÉÓüaÌýÁËmmap£¬È»ºo¼Ç¼µØÖ*¶Î§£¬ ×oIPµ½uºÅµÄת»»£¬ µ«ÊÇÄ¿Ç°HugeTLBÖ»Ö§³ÖMAP_ANON£¬ ËuÒÔµ¼ÖÂPerfÈÏΪÕa²¿ÖµØÖûÓÐ*uºÅÐÅÏ¢£¬Ï£ÍuÒÔºo°ae±¾µÄKernel¿ÉÒÔÐÞ¸´Õa¸oÏÞÖÆ°É..
×iºo: ÐÔÄܶԱȲaÊÔµÄÈÎÎñ¾ÍÁo¸ø´o¼ÒÀ´ÊÔÊÔÁË£¬ »¶ÓÆÀÂÛÄaÃÇ¿´µ½µÄ±a»¯£¡
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼Òphp³ÌÐoÉe¼ÆÓÐËu°iÖu¡£
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8