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

Review how HTTP parsing is affecting performance #18

Open
dbalabka opened this issue Dec 1, 2019 · 1 comment
Open

Review how HTTP parsing is affecting performance #18

dbalabka opened this issue Dec 1, 2019 · 1 comment

Comments

@dbalabka
Copy link
Owner

dbalabka commented Dec 1, 2019

There is an assumption that HTTP parsing in Amphp might affect overall server performance.

The assumption is based on experimental results. The variant of pure TCP Amphp server without HTTP parsing performs closer to Swoole and faster than Nodejs.

HTTP parsing implemented with PHP PECL Regexp can be replaced with bind C or Rust library via FFI or Wasmer extension.

Possible fast parsing libraries are:

  1. https://github.com/seanmonstar/httparse/
  2. https://github.com/h2o/picohttpparser

Libraries benchmark: https://github.com/rust-bakery/parser_benchmarks/blob/master/http/README.md

@dbalabka
Copy link
Owner Author

dbalabka commented Dec 24, 2019

Amp simple socket server (w/o HTTP parsing):
https://github.com/dbalabka/aerys-benchmark/blob/adjust-swolle-settings/aerys/v0.8/server-super-tiny.php
perform much better:

Benchmarking Aerys v0.8 super tiny (keep-alive + OPCache)
Start server...
php -n -c ./php/default-opcache.ini ./aerys/v0.8/server-super-tiny.php
Response example:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0    12    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
HTTP/1.1 200 OK
Content-Type: text/plain; Charset=utf-8
X-Powered-By: AerysServer
Connection: keep-alive
Content-Length: 12
Keep-Alive: timeout=10000
Date: Sat, 29 Sep 2018 10:27:16 GMT
Run benchmark...
Running 30s test @ http://localhost:8080/
  1 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     2.41ms  418.61us   7.22ms   68.89%
    Req/Sec    41.74k     2.90k   50.58k    65.33%
  Latency Distribution
     50%    2.57ms
     75%    2.67ms
     90%    2.76ms
     99%    3.07ms
  1246262 requests in 30.01s, 255.53MB read
Requests/sec:  41531.25
Transfer/sec:      8.52MB

comparing with Amp with full HTTP proccesing:

Benchmarking Aerys v0.8 tiny (keep-alive + OPCache)
Start server...
php -n -c ./php/default-opcache.ini ./aerys/v0.8/server-tiny.php
Response example:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/1.1 200 OK
content-length: 12
content-type: text/plain; charset=utf-8
x-powered-by: AerysServer
connection: keep-alive
keep-alive: timeout=10000
date: Sat, 29 Sep 2018 10:26:42 GMT
  0    12    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
Run benchmark...
Running 30s test @ http://localhost:8080/
  1 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.91ms    3.73ms 247.67ms   99.61%
    Req/Sec    12.86k   262.44    13.29k    74.67%
  Latency Distribution
     50%    7.75ms
     75%    7.86ms
     90%    8.01ms
     99%    8.69ms
  383884 requests in 30.00s, 75.78MB read
Requests/sec:  12795.45
Transfer/sec:      2.53MB

and Swoole (with adjusted settings for single CPU):

Benchmarking Swoole (keep-alive + OPCache + swoole)
Start server...
php -n -c ./php/default-opcache-swoole.ini ./swoole/server.php
Response example:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0    12    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Keep-Alive: timeout=10000
Server: swoole-http-server
Connection: keep-alive
Date: Sat, 29 Sep 2018 10:29:27 GMT
Content-Length: 12
Run benchmark...
Running 30s test @ http://localhost:8080/
  1 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.01ms  488.48us   8.09ms   86.54%
    Req/Sec    33.30k     1.50k   43.81k    80.00%
  Latency Distribution
     50%    3.07ms
     75%    3.16ms
     90%    3.31ms
     99%    4.05ms
  993667 requests in 30.00s, 197.11MB read
Requests/sec:  33117.54
Transfer/sec:      6.57MB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant