PHP7 vs. Phalcon 3 (Micro app) performance

In the past few days I did some benchmarks between node.js and PHP, so I decided to benchmark again PHP vs Phalcon.

I was quite surprised to find out that these simple synthetic benchmark showed this much of a difference.

  • Plain PHP7 - 10k req/s.
  • Phalcon 3.0.x - 6k req/s

IMHO this is way too much of a difference even for a synthetic benchmark (ab).

If you wanna know how node.js did, well only 3k req/s with exactly same setup/hardware.

In any case nginx was in front of all app servers, while app servers were using UNIX sockets in order to reduce latency.

The good thing is, that more realistic benchmark using siege showed almost no difference between each configuration. Phalcon, PHP7, and node.js resulted in ~1500 trans/sec (we can easily multiply this by 4-5 for a real world use case...).

edited Jan '17

So please provide your benchmarks. I had them all running in exactly same VM config, and CPU speed at 4 GHz.



61.2k

what do you have in plain index.php and what do you have in your phalcon app ?

edited Jan '17

Add symfony or slim here too. To be honest idk what you expect. Phalcon is still working on PHP, zend engne etc. It won't be faster than plain php obviously, it can be and will be only slower. Phalcon or zephir isn't some magic tool which increase php speed.

what do you have in plain index.php and what do you have in your phalcon app ?

Plain HTML + print of visitor IP from $_SERVER superglobal.... and I'm using Micro with Phalcon to do the same (via Request obj).

edited Jan '17

Add symfony or slim here too. To be honest idk what you expect. Phalcon is still working on PHP, zend engne etc. It won't be faster than plain php obviously, it can be and will be only slower. Phalcon or zephir isn't some magic tool which increase php speed.

Tat wasn't my intention.... and I really don't have time to setup other frameworks, I wanted to show difference between node.js and PHP/Phalcon only.

Yeah, it is expected to be slower but not 50%, right? I even have setup with static FPM workers with only 1 fixed FPM worker in order to simulate node.js single threaded cycle.



61.2k

phalcon magic is that it doesnt have to include, read, parse, convert ~100 files. Because all of the classes are bundled together and they are in c. What you tested is practically ... nothing.

Lets make something clear in case someone not very familiar is reading this.

in case you want to make a query and return the results as an json format, do not use a framework, no matter which one. Or if it is something simple if you want performance you have to write your plain php.

You make your plain app to init ( not only reuqire ) 100 files and then benchmark it. and check if there is a difference.

I think the performance benefit of Phalcon only becomes obvious at complex projects. In those cases, either you use a framework (and get overhead there, but more maintainable code), or write it in 1990 style with includes and global functions, but then you'll have unmaintable code and thus a lot of bugs + performance hogs.

I don't really believe in benchmarks results which only prints out Hello World... I'm not bashing your experiment mind you, I just don't think that approach is representative =]

A benchmark run should: - access a db (read+write) - communicate with an external API - have a fairly complex class hierarchy, with a lot of autoloads

I think these are the minimum algos a benchmark should run in order to simulate a real-life app

edited Jan '17

This is totally expected. Function/method calls in PHP is VERY HEAVY operation. This is why there is slowdown. Just check this framework comparsion, someone already did it: https://www.techempower.com/benchmarks/#section=data-r13&hw=ph&test=fortune&l=4fthbz

You can check it here that micro phalcon has around 60-80% of plain php performance which is expected and very good result. For example Slim is 25%, silex(micro fork of symfony) 7.9% symfony 1.3%

Just try to move your php plain code to classes, methods etc. You will get like -2k less requests or even more. Just check this super easy sample: http://sandbox.onlinephpfunctions.com/code/cb029d0f17ecb2995e57598e149b29fadbdad7e3

Add symfony or slim here too. To be honest idk what you expect. Phalcon is still working on PHP, zend engne etc. It won't be faster than plain php obviously, it can be and will be only slower. Phalcon or zephir isn't some magic tool which increase php speed.

Tat wasn't my intention.... and I really don't have time to setup other frameworks, I wanted to show difference between node.js and PHP/Phalcon only.

Yeah, it is expected to be slower but not 50%, right? I even have setup with static FPM workers with only 1 fixed FPM worker in order to simulate node.js single threaded cycle.

Interesting topic,

@stamster thanks for this