the-benchmarker / web-frameworks

Which is the fastest web framework?
MIT License
6.91k stars 641 forks source link

Add symfony #249

Closed waghanza closed 5 years ago

waghanza commented 5 years ago

Hi,

There is no php frameworks here.

The reason was that in php world, there is not appserver (something bridging between php source and http), so we have to use :

So more works than with the other framework, that's why it take so long.

This PR add symfony as the first php framework

Regards,

aichholzer commented 5 years ago

And you forgot to mention; php is sooo slow. 🐢

OvermindDL1 commented 5 years ago

PHP is not really that slow anymore, especially once the bytecode cache is setup and all (which should be done on any properly set up PHP server).

aichholzer commented 5 years ago

@OvermindDL1 -Yep, still, all of that seems to be too much effort, IMHO. In any case, I'd be curious to see who well it performs against the other contenders.

@waghanza -I did not mean any offense with my previous comment. I apologize if it came across like that.

OvermindDL1 commented 5 years ago

all of that seems to be too much effort

It's less effort than setting up a Ruby project by far at the very least and we have plenty of those here... ^.^;

waghanza commented 5 years ago

@aichholzer not at all :stuck_out_tongue: This framework shows me some weird results

Language (Runtime) Framework (Middleware) Requests / s Latency 99 percentile Throughput
node rayo 82198.33 18325.00 273634.33 42.33 MB
php symfony 40.00 2925631.00 6764337.33 0.14 MB

So I will adjust some params in the implementation

@OvermindDL1 between sinatra, laravel and flask (python, ruby and php) there is no very difference in term of efforts to create an app :stuck_out_tongue: except there is no appserver in php, something like puma or gunicorn

waghanza commented 5 years ago

@OvermindDL1 if you have any tip to optimize this php code, feel free to share

waghanza commented 5 years ago

@OvermindDL1 for example, using a socket connection between nginx and php-fpm (instead of a tcp connection) lead to other results

Language (Runtime) Framework (Middleware) Requests / s Latency 99 percentile Throughput
node rayo 84144.33 14735.67 113253.67 41.51 MB
php symfony 72971.33 146987.00 3547798.00 123.28 MB
waghanza commented 5 years ago

@fabpot @nicolas-grekas I found a huge throughput (php 7.1 and php 7.2) here on a basic symfony implementation on an API returning :

could you checky my code https://github.com/waghanza/which_is_the_fastest/blob/php_symfony/php/symfony/src/Controller/ApplicationController.php ?

nicolas-grekas commented 5 years ago

@waghanza thanks for the ping. Can you create an issue on https://github.com/symfony/symfony/ so that someone from the community could have a look?

stof commented 5 years ago

@waghanza make sure you run this in the prod mode of Symfony, not in the debug mode. The debug mode is much slower (we trade speed in favor of developer experience to provide a lot of debugging tools about what happens)

stof commented 5 years ago

hmm, it seems to be set to prod and no-debug mode though

waghanza commented 5 years ago

@stof production mode is enabled, but no details about debug (if I refer to my knowledge ^^ of symfony, debug is disabled by default)

OvermindDL1 commented 5 years ago

That latency on symfony implies to me that php is spooling up the script each time, no opcode cache set up yet? I can't think of any web hosting provider for PHP that doesn't use an opcode cache as without it php is essentially running in a debug kind of mode itself (reparsing and rerunning scripts each time)...

But yeah, I would expect PHP's latency to be higher each time anyway if using a framework like symfony. To have a low latency version you'd need a framework that is designed to keep running in memory (most aren't in PHP, that's a relatively recent creation in the PHP world).

bonfante commented 5 years ago

Hey, good work. Can I make a suggestion? Maybe changing the directory from 'symfony' to 'symfony_nginx'. This will allow others to add more setups such as httpd, swoole, or phpppm. For more performance other way to go is in config nginx and fpm with opcache.

nicolas-grekas commented 5 years ago

About the throughput, I suppose it depends on the size of the response, headers included? What's the typical response from the current setup and how does it differ from the other tested frameworks?

waghanza commented 5 years ago

@nicolas-grekas the througput is computed with wrk using the definition :

The headers and else are left to the default (php-fpm / nginx). My results are weird, but I think due to what i am using (docker). I'll merge this here, and ask for advice after switching to a real-world usage (cloud or else).

Language (Runtime) Framework (Middleware) Requests / s Latency 99 percentile Throughput
ruby rails 3828.33 16757.67 113968.67 3.68 MB
ruby sinatra 16248.67 3941.67 46547.67 13.70 MB
ruby roda 38744.33 1729.67 28286.67 12.30 MB
ruby rack-routing 31118.00 2080.00 33025.00 5.79 MB
ruby flame 19446.33 3308.33 37345.33 3.62 MB
node express 48666.67 35435.00 620252.67 40.56 MB
node fastify 66903.33 23119.00 367041.67 67.33 MB
node polka 78586.33 16510.67 210428.67 39.21 MB
node rayo 79417.67 20978.33 391976.67 38.50 MB
python sanic 48544.67 19461.67 33328.00 28.16 MB
python japronto 86920.00 11040.33 11565.33 35.31 MB
python flask 19125.33 53313.33 167249.67 15.75 MB
python django 11238.00 83441.67 209351.00 10.62 MB
python tornado 1907.00 541693.00 3961058.33 1.39 MB
php symfony 152.33 1117751.67 4560955.33 0.20 MB
waghanza commented 5 years ago

@Bonfante Your idea is awesome, however I think that having multiple implementations per framework here is counter-productive.

For me this project is a representation of what it COULD be done, but as an average, for a more specific representation, we encourage to use this as a tool (eg : having your own implementations base on this project -> I will create some documentations for this)

doanguyen commented 5 years ago

Now I understand the whole picture from #421, and it's very interesting to me.

So @waghanza switch from tcp socket to unix socket for symfony, there are two things that I just found out:

  1. unix socket is really fast, I tried to tweak the fastcgi_connect_timeout from nginx but it does not seem to work, and it makes Nginx fall down quickly then return 502 error (wrk unfortunately consider a successful request) instead of waiting until handle by PHP-FPM. TCP socket is slower but keeping the connection for a while, Nginx then needs to wait for the socket before accepting another connection. That plus the weird report from wrk makes the req/s from two setups is so different.
  2. The abnormal throughput from symfony due to the fact that the response from successful requests are gzipped while 502 error is not.
chiqui3d commented 3 years ago

Hello @nicolas-grekas,

It doesn't seem right that Symfony should be so badly off in this Benchmark.

And I see that some things are missing:

chiqui3d commented 3 years ago

Here the tests come out more or less better https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=fortune&l=zijzzz-1r

chiqui3d commented 3 years ago

And here other PHP tests for those who say that php is slow https://github.com/chiqui3d/php-faster-than-python-ruby-node

The slowest is Ruby