There is a lot of interesting things going on in the Moodle & PHP worlds recently – Moodle 3.0 has just been released and PHP 7 release is coming soon. Among other things, PHP 7 promises a great performance improvement over PHP 5.6 – PHP 7 is supposedly up to 2 x faster.
We have decided to put that into the test by simulating real-world Moodle 3.0 usage scenario. After a quick Moodle PHP 7 bug fix and hack to ignore Moodle version check, we were able to install Moodle using PHP 7.
The environment used for testing:
- Moodle: 3.0rc4 (Build: 20151113)
- PHP: Version 7.0.1-dev with Zend OPcache v7.0.6-dev vs PHP Version 5.5.9 with Zend OPcache v7.0.3 (Ubuntu 14.04 packaged version)
- OS: 64 bit Ubuntu 14.04
- Mysql server 5.5
- Physical machine with:
- 16GB RAM
- one 2GHz i7-2630QM CPU (4 cores, 8 threads)
- SSD hard drive
The test was performed with jmeter running on the same machine. This has affected the performance of the system but it should be the same overhead for running both PHP versions, so it should not matter for the comparison. We have tested 200 users answering 100 quiz questions each. Each user had a separate account and started his run by login, followed by answering 100 questions and submitting the quiz. Every question was on a separate page, so each user generated over 200 page hits. The test was set up to run 20 threads in parallel. The timings are taken from jmeter statistics and from Moodle performance reporting (MDL_PERF). After switching PHP version we have run & discarded dozens of jmeter tests to warm up all caches. All tests were executed with opcache enabled.
The results are grouped by PHP script that was run and show:
- the times it took to execute each PHP script (with minimum time, maximum, average and standard deviation) measured in seconds
- values like above for CPU time (the time that CPU has spent working on each request) in seconds
- memory used shown in MB
The most relevant values for a comparison like this are CPU time and memory used, so let’s see how well did PHP 7 do compared to PHP 5.
PHP 5.5 results
script | count | min_time | max_time | avg_time | std_time | min_cpu | max_cpu | avg_cpu | std_cpu | mem_min | mem_max | mem_avg | mem_std |
/login/index.php | 200 | 1.09 | 3.21 | 2.01 | 0.40 | 0.94 | 1.05 | 0.98 | 0.02 | 4.71 | 4.71 | 4.71 | 0.00 |
/mod/quiz/attempt.php | 20200 | 0.20 | 1.68 | 0.80 | 0.18 | 0.19 | 0.49 | 0.43 | 0.01 | 10.84 | 11.01 | 10.94 | 0.03 |
/mod/quiz/processattempt.php | 20199 | 0.06 | 2.23 | 0.45 | 0.16 | 0.06 | 0.73 | 0.23 | 0.05 | 10.10 | 11.71 | 10.16 | 0.15 |
/mod/quiz/review.php | 200 | 0.28 | 1.57 | 0.96 | 0.27 | 0.26 | 0.49 | 0.45 | 0.04 | 11.52 | 11.56 | 11.54 | 0.01 |
/mod/quiz/startattempt.php | 200 | 1.80 | 4.42 | 2.80 | 0.55 | 1.18 | 1.30 | 1.24 | 0.02 | 12.04 | 12.07 | 12.06 | 0.01 |
/mod/quiz/view.php | 200 | 0.22 | 1.19 | 0.71 | 0.17 | 0.21 | 0.36 | 0.32 | 0.01 | 12.16 | 12.16 | 12.16 | 0.00 |
PHP 7 results
script | count | min_time | max_time | avg_time | std_time | min_cpu | max_cpu | avg_cpu | std_cpu | mem_min | mem_max | mem_avg | mem_std |
/login/index.php | 200 | 0.96 | 2.33 | 1.29 | 0.23 | 0.87 | 1.01 | 0.94 | 0.02 | 3.23 | 3.23 | 3.23 | 0.00 |
/mod/quiz/attempt.php | 20200 | 0.04 | 0.72 | 0.24 | 0.07 | 0.04 | 0.31 | 0.18 | 0.02 | 7.31 | 7.43 | 7.38 | 0.02 |
/mod/quiz/processattempt.php | 20198 | 0.03 | 1.27 | 0.15 | 0.06 | 0.02 | 0.32 | 0.09 | 0.02 | 6.04 | 7.50 | 6.09 | 0.14 |
/mod/quiz/review.php | 200 | 0.08 | 0.57 | 0.30 | 0.08 | 0.05 | 0.22 | 0.20 | 0.02 | 7.74 | 7.76 | 7.74 | 0.00 |
/mod/quiz/startattempt.php | 200 | 0.18 | 2.71 | 0.94 | 0.42 | 0.13 | 0.56 | 0.50 | 0.04 | 7.44 | 7.50 | 7.45 | 0.01 |
/mod/quiz/view.php | 200 | 0.06 | 1.26 | 0.25 | 0.11 | 0.05 | 0.20 | 0.15 | 0.01 | 7.67 | 7.67 | 7.67 | 0.00 |
PHP 5.5 vs 7
The table below show how much % of time / memory was consumed by PHP 7 compared to PHP 5.5.
script | avg_cpu_time | avg_time | memory_avg |
/login/index.php | 96.03 | 64.22 | 68.55 |
/mod/quiz/attempt.php | 41.96 | 30.57 | 67.45 |
/mod/quiz/processattempt.php | 41.85 | 33.25 | 59.95 |
/mod/quiz/review.php | 43.88 | 31.65 | 67.13 |
/mod/quiz/startattempt.php | 39.92 | 33.57 | 61.75 |
/mod/quiz/view.php | 45.69 | 35.14 | 63.06 |
In summary, PHP 7 performed more than 2 time faster compared to PHP 5.5 while consuming only 60% of the memory that PHP 5.5 did. Statistics from jMeter confirm that – PHP 5.5 was able to process on average 10 requests per second, while PHP 7 20 requests/second.
Keep in mind that the above does not mean that your users will get this kind of performance improvement as soon as you switch to new PHP version. The time measured here is a CPU time on the server side, which is just a fraction of the whole time needed to render the page for end user. Once you add network latency, loading media and rendering the page by the browser – the end result will be much less spectacular. Having said that the results are quite impressive – go PHP 7!