Make your PHP 7 faster Hugepage

Source: Internet
Author: User

Make your PHP 7 faster Hugepage

PHP7 has just released RC4, which includes some bug fixes and our latest performance improvement (NEWS), which is "HugePageFy php text segment". By enabling this feature, PHP7 moves its TEXT segment (execution body) to the Huagepage. In the previous test, we can see 2% ~ 3% QPS increase.

What is Hugepage, simply put, the default memory is 4 kb paging, and the virtual address and memory address need to be converted, and the conversion is to look up the table, the CPU has built-in TLB (Translation Lookaside Buffer) to accelerate this lookup process. Obviously, the smaller the virtual page, the more entries in the table, and the smaller the TLB, the higher the number of entries, the higher the TLB Cache Miss. Therefore, if we can enable a large memory page, we can indirectly reduce the TLB Cache Miss. For details, I will not go into details when Google searches a lot. Here I will mainly explain how to enable this new feature to bring about significant performance improvements.

The new Kernel has become very easy to enable Hugepage. Take my Development Virtual Machine as an example (Ubuntu Server 14.04, Kernel 3.20.- 45). If we view the memory information:

  1. $ Cat/proc/meminfo | grep Huge
  2. AnonHugePages: 444416 kB
  3. HugePages_Total: 0
  4. HugePages_Free: 0
  5. HugePages_Rsvd: 0
  6. HugePages_Surp: 0
  7. Hugepagesize: 2048 kB

The size of a Hugepage is 2 MB, but HugePages is not enabled currently. now let's compile PHP RC4 first. Remember not to add:-disable-huge-code-pages. (This new feature is enabled by default. If you add this feature, it will be disabled)

Then configure opcache. Opcache has enabled compilation by default since PHP5.5, but it is used to compile the dynamic library. Therefore, we need to configure and load it in php. ini.

  1. Zend_extension = opcache. so

This new feature is implemented in Opcache, so you must also enable this feature through Opcache (by setting opcache. huge_code_pages = 1). The specific configuration is as follows:

  1. Opcache. huge_code_pages = 1

Now let's configure the OS and allocate some Hugepages:

  1. $ Sudo sysctl vm. nr_hugepages = 128
  2. Vm. nr_hugepages = 128

Now let's check the memory information again:

  1. $ Cat/proc/meminfo | grep Huge
  2. AnonHugePages: 444416 kB
  3. HugePages_Total: 128
  4. HugePages_Free: 128
  5. HugePages_Rsvd: 0
  6. HugePages_Surp: 0
  7. Hugepagesize: 2048 kB

We can see that the allocated 128 Hugepages are ready, and then we can start php-fpm:

  1. $/Home/huixinchen/local/php7/sbin/php-fpm
  2. [01---2015 09:33:27] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
  3. [01---2015 09:33:27] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root

Now, check the memory again:

  1. $ Cat/proc/meminfo | grep Huge
  2. AnonHugePages: 444416 kB
  3. HugePages_Total: 128
  4. HugePages_Free: 117
  5. HugePages_Rsvd: 27
  6. HugePages_Surp: 0
  7. Hugepagesize: 2048 kB

Bingo, configuration successful! Enjoy

However, if you try to use Perf report/anno to profiling, you will find that the symbols are lost (valgrind, gdb is not affected ), this is mainly because Perf is designed to listen to mmap, record the address range, and convert the IP address to the symbol. However, HugeTLB currently only supports MAP_ANON, therefore, Perf considers that this part of the address has no symbolic information. We hope that later versions of Kernel can fix this restriction ..

Finally: Why? Why don't you send a performance comparison test? Hey, let's try it for yourself. You are welcome to comment on the changes you have seen.

PHP 7 innovation and Performance Optimization

PHP 7, you deserve it

Experience PHP 7.0 on CentOS 7.x/Fedora 21

Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)

Nginx startup failure occurs during LNMP deployment.

Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)

Detailed php hd scanning PDF + CD source code + full set of teaching videos

Configure the php lnmp development environment in CentOS 6

PHP details: click here
PHP: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.