Pedal to the metal php5.6 vs php5.5 performance (vs php7.0.1)

PHP 5.6 vs 5.5 vs 7.0.1

PHP recently released first PHP7 non-production alpha 1 and as a step towards it i had evaluated the php5.6 version in production environment, trying to squeeze the last bits and bytes of performance with upgrading to latest stable software php stack

Environment

Both instances are used completely the same, under the same load, deployed via puppet (automated deployment)

  1. EC2 c3.xlarge (4 vCPU, 7.5GiB) with Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
  2. EC2 Classic, us-east-1c, default tenancy, non-EBS-optimized, EBS & Paravirtual
  3. Both instances have same production EC2 fine-tuning applied:
    • ulimits
    • sysctl short overview
    • identical nginx,php,fpm configurations (php.ini, nginx.conf, nginx vhosts, pools …) with CPU being the bottleneck
php5.5 box

1st box (originally EC2 ubuntu-precise-12.04-amd64-server-20131003 ami-a73264ce )

  • Magnetic EBS volume
  • 12.04.3 LTS Updated to 12.04.5 LTS (with apt-get updates)
$ php -v
PHP 5.5.25-1+deb.sury.org~precise+2 (cli) (built: May 24 2015 15:49:54)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
$ nginx -v
nginx version: nginx/1.6.2
$ cat /etc/issue
Ubuntu 12.04.5 LTS \n \l
$ uname -rmpio
3.2.0-54-virtual x86_64 x86_64 x86_64 GNU/Linux
php5.6 box

2nd box (generic EC2 ubuntu-precise-12.04-amd64-server-20150615 ami-ef05f684)

  • SSD (gp) EBS volume
$ php -v
PHP 5.6.10-1+deb.sury.org~precise+1 (cli)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
$ nginx -v
nginx version: nginx/1.8.0
$ cat /etc/issue
Ubuntu 12.04.5 LTS \n \l
$ uname -rmpio
3.2.0-86-virtual x86_64 x86_64 x86_64 GNU/Linux
php7.0.1 box

3rd box (generic EC2 ubuntu/images/ebs/ubuntu-trusty-14.04-amd64-server-20151218 ami-b82176d2)

  • SSD (gp) EBS volume
$ php -v
PHP 7.0.1-5+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
$ nginx -v
nginx version: nginx/1.8.0
$ cat /etc/issue
Ubuntu 14.04.3 LTS \n \l
$ uname -rmpio
3.13.0-74-generic x86_64 x86_64 x86_64 GNU/Linux

Load

Evaluating two projects, expecting php5.6 vs php5.5 performance improvement on php level (cpu)

  1. ZF-1 JSON-RPC API
  2. Custom JSON-RPC API

Both running in production for long time, and had been long time optimized to handle high load (up to 1.5k rpm per 1 vCPU).

Both hosts run in EC2 Load balancer which splits load equally between boxes.

The server load generated is organic, coming from clients that use the api’s (its NOT synthetic benchmarks)

ZF-1 API ZF-1,php5.5 vs php5.6

Custom API ZF-1,php5.5 vs php5.6

  • The spikes are the opcache invalidation calls
  • Left side is the php5.5 and the php5.6 on the right side (10:00 php5.6 deployed)
PHP7 (January 2016)

ZF-1 API

ZF-1,php5.6 vs php7.0.1

Custom API (7.0.1) Jan 2016 ZF-1,php5.6 vs php7.0.1

Custom API (7.0.4) Apr 2016 ZF-1,php7.0.4

Custom API (specific call that is 2x faster on 7.0.1) ZF-1,php5.6 vs php7.0.1 50%

php5.6 pros
  1. php://input better memory management, $HTTP_RAW_POST_DATA deprecated reduced POST data memory usage by 200-300%.
  2. always_populate_raw_post_data was already set “-1” in 5.5
  3. MYSQLI_STORE_RESULT_COPY_DATA can reduce the overall memory usage because PHP variables holding results may be released earlie
  4. mysqli_get_links_stats information about open and cached MySQL links.
  5. opcache_is_script_cached
php5.6 cons ?
  1. __debugInfo() added, (maybe affects performance ?)
  2. phpdbg an interactive integrated debugger SAPI, no way to opt-out, (maybe affects performance ?)
EOL
  1. lornajane shows 5.6 faster than 5.5
  2. franontanaya shows 5.6 faster
  3. reddit shows 5.6 faster by 1.63%
  4. zsuraski shows 5.6 faster and here
  5. my own results show me that
    • php5.6 is slower or identical to php5.5 in ZF1 and simple JSON-API (PHP/MYSQL app) projects
    • php5.6 performance is not as consistent as php5.5 and min&max response times varies more
    • php5.6 is sensitive to opcache invalidations opcache_invalidate calls
  6. PHP 7.0.1 brings significant improvements (20% to 50% in certain calls) even with same code (w/o php7 features)

Update Jan 2016