Created
July 23, 2019 02:41
-
-
Save dasper/5862dc0f2d2360fafe32d3748ce33e24 to your computer and use it in GitHub Desktop.
Benchmarks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
use Amp\Http\Server\RequestHandler\CallableRequestHandler; | |
use Amp\Http\Server\Server; | |
use Amp\Http\Server\Request; | |
use Amp\Http\Server\Response; | |
use Amp\Http\Status; | |
use Amp\Socket; | |
use Psr\Log\NullLogger; | |
// Run this script, then visit http://localhost:1337/ in your browser. | |
Amp\Loop::run(function () { | |
$sockets = [ | |
Socket\listen("0.0.0.0:1337"), | |
Socket\listen("[::]:1337"), | |
]; | |
$server = new Server($sockets, new CallableRequestHandler(function (Request $request) { | |
return new Response(Status::OK, [ | |
"content-type" => "text/plain; charset=utf-8" | |
], json_encode([ | |
'code' => 'ok', | |
'error' => false, | |
'payload' => 'Hello World' | |
])); | |
}), new NullLogger); | |
yield $server->start(); | |
// Stop the server gracefully when SIGINT is received. | |
// This is technically optional, but it is best to call Server::stop(). | |
Amp\Loop::onSignal(SIGINT, function (string $watcherId) use ($server) { | |
Amp\Loop::cancel($watcherId); | |
yield $server->stop(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var data = { | |
'code': 'ok', | |
'error': false, | |
'payload': 'Hello World' | |
}; | |
var app = function (req, res) { | |
res.writeHead(200, { | |
'Content-Type': 'application/json' | |
}); | |
res.end(JSON.stringify(data)); | |
}; | |
var server = http.createServer(app); | |
server.listen(1337, function() { | |
console.log("Server running at http://127.0.0.1:1337"); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wrk -t4 -c400 -d10s http://127.0.0.1:1337/ | |
ReactPHP: | |
Running 10s test @ http://127.0.0.1:1337/ | |
4 threads and 400 connections | |
Thread Stats Avg Stdev Max +/- Stdev | |
Latency 129.98ms 234.70ms 1.94s 85.24% | |
Req/Sec 843.63 1.26k 5.10k 81.08% | |
18447 requests in 10.42s, 2.13MB read | |
Socket errors: connect 0, read 18447, write 0, timeout 10 | |
Requests/sec: 1770.11 | |
Transfer/sec: 209.16KB | |
Node: | |
Running 10s test @ http://127.0.0.1:1337/ | |
4 threads and 400 connections | |
Thread Stats Avg Stdev Max +/- Stdev | |
Latency 20.58ms 4.38ms 272.51ms 94.55% | |
Req/Sec 4.78k 614.18 5.41k 93.50% | |
190151 requests in 10.03s, 36.63MB read | |
Requests/sec: 18955.65 | |
Transfer/sec: 3.65MB | |
Swoole: | |
Running 10s test @ http://127.0.0.1:1337/ | |
4 threads and 400 connections | |
Thread Stats Avg Stdev Max +/- Stdev | |
Latency 1.68ms 845.37us 12.61ms 67.84% | |
Req/Sec 59.70k 5.63k 76.41k 70.75% | |
2377018 requests in 10.03s, 478.32MB read | |
Requests/sec: 237012.64 | |
Transfer/sec: 47.69MB | |
AmPHP: | |
Running 10s test @ http://127.0.0.1:1337/ | |
4 threads and 400 connections | |
Thread Stats Avg Stdev Max +/- Stdev | |
Latency 55.22ms 172.36ms 2.00s 96.60% | |
Req/Sec 3.43k 448.58 4.78k 81.25% | |
136495 requests in 10.04s, 28.12MB read | |
Socket errors: connect 0, read 0, write 0, timeout 70 | |
Requests/sec: 13599.16 | |
Transfer/sec: 2.80MB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
$loop = new React\EventLoop\ExtEventLoop(); | |
$socket = new React\Socket\Server('127.0.0.1:1337', $loop); | |
$socket->on('connection', function (React\Socket\ConnectionInterface $connection) { | |
$connection->once('data', function () use ($connection) { | |
$body = json_encode([ | |
'code' => 'ok', | |
'error' => false, | |
'payload' => 'Hello World' | |
]); | |
$connection->end("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nConnection: close\r\n\r\n" . $body); | |
}); | |
}); | |
echo "Server running at http://127.0.0.1:1337\n"; | |
$loop->run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$http = new swoole_http_server("127.0.0.1", 1337, SWOOLE_BASE); | |
$http->set([ | |
'worker_num' => 4, | |
]); | |
$data = [ | |
'code' => 'ok', | |
'error' => false, | |
'payload' => 'Hello World' | |
]; | |
$http->on('request', function ($request, swoole_http_response $response) use($data) { | |
$response->header('Content-Type', 'application/json'); | |
$response->end(json_encode($data)); | |
}); | |
$http->start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment