ÈÃÄãµÄPHP7¸ü¿ìÖ®HugepageÓ÷¨·ÖÎö

5年以前  |  阅读数:696 次  |  编程语言:PHP 

±¾ÎÄʵÀý½²Ê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¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例