leocavalcante / siler

⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
https://siler.leocavalcante.dev
MIT License
1.12k stars 90 forks source link

Add project Siler+Swoole in benchmarker from "Web-Frameworks" #285

Closed RicardoSette closed 4 years ago

RicardoSette commented 4 years ago

I found a project to benchmark Web Frameworks, want help adding the Siler with Swoole? I believe he will be in the Top 10.

The link: https://github.com/the-benchmarker/web-frameworks

leocavalcante commented 4 years ago

I think you should open a issue an ask this possibility before because of: https://github.com/the-benchmarker/web-frameworks/pull/1335 and https://github.com/the-benchmarker/web-frameworks/issues/1502

The author doesn't seems to be open for Swoole related additions, maybe because of https://github.com/the-benchmarker/web-frameworks/issues/1481

RicardoSette commented 4 years ago

There are projects using Swoole, such as: "one" / "Hyperf" / "simps", exemple configure in php/one project:

https://github.com/the-benchmarker/web-frameworks/blob/6983459e42396f869c2031092bfac32d3806ea44/php/one/config.yaml

framework:
  github: lizhichao/one
  version: 2.0

php_ext:
  - swoole

command: php App/swoole.php

Just configure yaml correctly for the Swoole extension to be installed, and running the command to start the Swoole server instead of using nginx+php-fpm.

leocavalcante commented 4 years ago

Oh, how cool. I thought the repo isn't accepting Swoole based applications until the variations thing was resolved/closed.

Tests are just about returning empty strings?

I think we can work on something then.

RicardoSette commented 4 years ago

I added two Siler projects, for PHP-FPM and Swoole.

https://github.com/RicardoSette/web-frameworks/tree/yii2-swoole/php/siler https://github.com/RicardoSette/web-frameworks/tree/yii2-swoole/php/siler-swoole

The code and settings are simple, but you could revise, if you have something to add or remove to improve performance.

leocavalcante commented 4 years ago

Ok, I'll be sending a PR to your repo with some mods.

RicardoSette commented 4 years ago

This is the project with the highest score in PHP:

https://github.com/the-benchmarker/web-frameworks/tree/master/php/workerman

I was reviewing and I believe that Siler could be run in the same way, without Swoole and without PHP-FPM, do you think that could increase performance?

https://siler.leocavalcante.dev/web-servers

leocavalcante commented 4 years ago

This makes the use of PHP's built-in web server it is not suited for production environments.

RicardoSette commented 4 years ago

Hi @leocavalcante,

is there any planning or way to change Swoole settings?

See as an example this project https://github.com/the-benchmarker/web-frameworks/blob/master/php/simps/config/servers.php

Simps is now the first PHP Framework in the benchmarker list and Swoole's start configurations can be one of the differentials.

Let's see if we can take advantage of the change request at https://github.com/the-benchmarker/web-frameworks/pull/2598 to review Swoole settings on Siler

waghanza commented 4 years ago

Please not that the above results are not, yet, production-ready, until https://github.com/the-benchmarker/web-frameworks/pull/2593 is merged :heart:

RicardoSette commented 4 years ago

Yes, I know that, it's more to leave the Siler at full strength for the first test :sunglasses:

leocavalcante commented 4 years ago

Hi @RicardoSette

The http function returns a Swoole\Http\Server, so instead of:

http($handler, $port, $host)->start();

You can:


$server = http($handler, $port, $host);
$server->set([
    // Swoole settings like:
    'worker_num' => (int) shell_exec('nproc') ?? 32
]);
$server->start();
RicardoSette commented 4 years ago

In PHP projects Siler ranked fourth, but in test above 64 the position would be third 💪🔝

The first and second positions are outside the curve, the first with practically pure Swoole and the second with different uses of POSIX and PCNTL extensions. Then look at these two projects to add more performance to Siler.

Congratulations 😎

leocavalcante commented 4 years ago

@RicardoSette cool! I should inspect and study why Simps performs so much better in Swoole, Siler is practically pure PHP and pure Swoole as well, it only provides facades. Thanks for bringing this up!

RicardoSette commented 4 years ago

I found the reason why Simps got 175,713 points and Siler-Swoole got 64,343

Simps runs the swoole with Swoole\Server Siler runs the swoole with Swoole\Http\Server

In tests on my virtual machine, when I run in the settings above I have:

Simps (Swoole\Server) => 11256 req / s Siler (Swoole\Http\Server) => 4946 req / s

When I put Simps to run with Swoole \ Http \ Server see how it looks:

Simps (Swoole\Http\Server) => 5609 req / s Siler (Swoole\Http\Server) => 4849 req / s

I didn't find how to run Siler with Swoole\Server, is that possible?

When both use Swoole\Http\Server we notice a small gain from Simps over Siler, but it may be due to the use of nikic/fast-route or the fact that there are no controls like Container\set

leocavalcante commented 4 years ago

Awesome! Thank you very much for digging into this.

Yeah, it is skipping Swoole's HTTP parsing and making its own: https://github.com/simple-swoole/simps/blob/master/src/Server/Protocol/HTTP/SimpleRoute.php#L55 Cleaver.

waghanza commented 4 years ago

@RicardoSette @leocavalcante may I ask for your review when implementation of siler is updated ? (or a minor version is release, I always use the last patch)

leocavalcante commented 4 years ago

@waghanza sure!

leocavalcante commented 4 years ago

@RicardoSette Siler faster than Simps on the latest round: https://github.com/the-benchmarker/web-frameworks/tree/cloudify#results

RicardoSette commented 4 years ago

@leocavalcante updated and returned to the standards of the first test. If it were possible to configure Siler to work with Swoole\Server then it could be close to or above the Simps.

leocavalcante commented 4 years ago

@RicardoSette yeah, I misread the first published results lol. Do you know a good use case for doing raw sockets + naive method and path parsing, besides just being faster? Maybe in some specific micro-services where you just need the url path to route to something, but on real case scenarios you would need at least the headers and body I guess.

RicardoSette commented 4 years ago

The sky is the limit, we can have simple internal systems for message alerts where the URL would be the trigger, but we also have more complex IoT systems (mqtt) like those used for arduino.

Of course, the default is HTTP server, but the creation of simplistic servers with only TCP / UDP could be an option for the developer.