Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React PHP vs Swoole PHP #389

Closed
aftabnaveed opened this Issue Jun 4, 2018 · 12 comments

Comments

Projects
None yet
7 participants
@aftabnaveed
Copy link

aftabnaveed commented Jun 4, 2018

I was playing a little bit with Swoole PHP https://github.com/swoole/swoole-src The fact that this a PHP C extension it is really fast. I also see it being actively developed as compared to ReactPHP.

I actually did some benchmarking today against and here are some interesting results of my laravel application with both PHP-PM and Swool:

Workers: 4
RAM: 8GB
CPU Core i7 Quad Core
Env: Docker
OS: Ubuntu 18.04

PHP-PM

ab -c 4 -n 1000 http://site.local/outdoor/outdoor-chairs.htm
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Server Software:        openresty/1.13.6.2
Server Hostname:      site.local
Server Port:            80

Document Path:          /outdoor/outdoor-chairs.htm
Document Length:        129850 bytes

Concurrency Level:      4
Time taken for tests:   128.300 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      131536296 bytes
HTML transferred:       129850000 bytes
Requests per second:    7.79 [#/sec] (mean)
Time per request:       513.200 [ms] (mean)
Time per request:       128.300 [ms] (mean, across all concurrent requests)
Transfer rate:          1001.20 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   398  512  97.9    494    1674
Waiting:      398  512  97.9    494    1674
Total:        399  513  97.9    494    1675

Swool PHP

Benchmarks (Swoole)
Server Software:        openresty/1.13.6.2
Server Hostname:        site.local
Server Port:            80

Document Path:          /outdoor/outdoor-chairs.htm
Document Length:        129850 bytes

Concurrency Level:      4
Time taken for tests:   88.201 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      130806248 bytes
HTML transferred:       129850000 bytes
Requests per second:    11.34 [#/sec] (mean)
Time per request:       352.803 [ms] (mean)
Time per request:       88.201 [ms] (mean, across all concurrent requests)
Transfer rate:          1448.29 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   238  352 111.5    318    1719
Waiting:      237  352 111.5    317    1719
Total:        238  353 111.5    318    1719

Its clearly visible that Swool PHP is outperforming ReactPHP here by almost 30% and the interesting fact is that there are no memory leaks.

I am wondering if you guys would ever think of moving away from React PHP and adapt something which is actively maintained and better in performance?

@marcj

This comment has been minimized.

Copy link
Member

marcj commented Jun 4, 2018

I guess @clue dissents here and actually https://github.com/reactphp/http/commits/master doesn't look like its not maintained? I agree, having better performance is good, but not at all costs. If the cost is to co-maintain C-code, which most PHP-Devs don't know, then I'm against it.

I find that benchmark a bit weird. Your app has so slow request times that it actually shouldn't matter if react or c delivers that response.

@aftabnaveed

This comment has been minimized.

Copy link
Author

aftabnaveed commented Jun 4, 2018

Sorry I was benchmarking it against a real application which has an LUA Mysql call on nginx side, and then the response has a network call for Server Side Rendering Javascript affecting the performance.

While I agree with you on the C aspect but not many people would want to even modify the ReactPHP core, I myself would think twice before doing that. :-) Other interesting factor is Swool also has Co-routines something which almost all modern languages have but PHP is missing it.

As for as maintenance is concerned Swoole PHP has more contributors than ReactPHP, I think some of the Core PHP developers are also contributing to it. I am not sure how much this matters but php.net has manual for it http://php.net/manual/en/book.swoole.php

I would rather abstract the HTTP part of PHP-PM and let people come up with their own implementations. Not sure if it's even possible in the current design of PHP-PM.

Moreover, Swoole PHP also supports interprocess communication which could be helpful in scenarios like cache invalidation and notifying the workers.

Last but not the least my intention is not to critisize ReactPHP here. Its a great library and I am already using it. The idea is to jus to compare it with other libraries out there.

@marcj

This comment has been minimized.

Copy link
Member

marcj commented Jun 4, 2018

I see, good feedback, thanks. That IPC is interesting. So swoole is a full featured HTTP server? Never heard of it actually. Maybe we should think about how the architecture and practical side could look when PHP-PM uses it.

@aftabnaveed

This comment has been minimized.

Copy link
Author

aftabnaveed commented Jun 4, 2018

I am not sure if it implements all Http 1.1 RFC specs (I will find out some more details about it) but it does include standard get, post, files requests. As for as IPC is concerned it can be found here.

https://www.swoole.co.uk/docs/modules/swoole-process

and list of methods for HTTP Server here

http://php.net/manual/en/class.swoole-http-server.php

@aftabnaveed

This comment has been minimized.

Copy link
Author

aftabnaveed commented Jun 8, 2018

Based on the above conversation I was able to find complete information online, though they say it is complete but does not recommend it to replace nginx. They are also suggesting to keep nginx for nonstandard and static files requests.

I opened an issue to find out some more details it can be traced here:
swoole/swoole-src#1687

@alibo

This comment has been minimized.

Copy link

alibo commented Jun 10, 2018

Only 7/11 RPS? 😧
May you please share the configurations too?
(outdoor/outdoor-chairs.htm (is it a static file?), Dockerfile, Laravel env variables, Laravel & PHP versions, Nginx, Opcache, ...)

@aftabnaveed

This comment has been minimized.

Copy link
Author

aftabnaveed commented Jun 11, 2018

@alibo that URL is from an actual application in development mode and is not a static file. I was using nginx + lua + mysql to resolve URLs to the Laravel routes. After replacing mysql with Redis (nginx + lua + redis) the requests per second has now significantly improved.

The URL I shared has a complex Setup which talks to MongoDB for product data, Doctrine MYSQL for reviews and nodejs server for rendering the view components built in ReactJS (Blade is only used for a single template). MongoDB and Doctrine are quite optimized and adds only 10 to 25ms combined to fetch the data. The view, however, adds around 150ms and it needs to be optimized.

I shared that matrix for the sake of interest and see if PHP-PM creators would be interested in abstracting the core functionality. Thus providing an opportunity to allow drivers built in different libraries such as ReactPHP, SwoolePHP, or AmpPHP/Ayers and make it pluggable.

@andreybolonin

This comment has been minimized.

Copy link
Contributor

andreybolonin commented Jul 13, 2018

screen shot 2018-07-13 at 10 05 15 am

screen shot 2018-07-13 at 10 05 33 am

Swoole vs PHP-PM
on Symfony 4

@yehosef-idt

This comment has been minimized.

Copy link

yehosef-idt commented Jul 18, 2018

I think this is valuable to have as an alternative to ReactPHP but I don't think you could replace it. Swoole is a C-extension that many will not be able to use/install. ReactPHP uses normal PHP so will work in more environments.

If it's possible to support both, that would be great.

@aftabnaveed

This comment has been minimized.

Copy link
Author

aftabnaveed commented Jul 18, 2018

If it's possible to support both, that would be great.

That's exactly what my point is.

@andreybolonin Those tests look very interesting did you use any library to convert Swoole request object to Symfony HttpRequests?

I will post some plain Laravel tests soon.

@yellow1912

This comment has been minimized.

Copy link

yellow1912 commented Jan 19, 2019

@andreybolonin your test seems to suggest that swoole is slower and has higher failed requests? Can you explain how you setup your tests in more details

@andig

This comment has been minimized.

Copy link
Contributor

andig commented Mar 20, 2019

Closing due to inactivity. Please respond here if you want to reopen this.

@andig andig closed this Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.