Skip to content

Commit

Permalink
Code optimization, update dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Oct 31, 2018
1 parent 1b20665 commit c87864f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"require": {
"php": ">=7.0",
"swlib/http": "1.0.0",
"swlib/http": "1.0.1",
"swlib/util": "1.0.0"
},
"autoload": {
Expand Down
32 changes: 21 additions & 11 deletions examples/stress.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,32 @@

require __DIR__ . '/../vendor/autoload.php';

error_reporting(0);
co::set(['max_coroutine' => 8191]);
$http = new swoole_http_server('127.0.0.1', 1234);
$http->set(['worker_num' => 8]);
$http = new swoole_http_server('127.0.0.1', 1234, SWOOLE_BASE);
$http->set([
'log_file' => '/dev/null',
'worker_num' => swoole_cpu_num() * 2,
'enable_coroutine' => false
]);
$http->on('request', function (swoole_http_request $request, swoole_http_response $response) {
$response->end('<h1>Hello Swoole!</h1>');
});
$http->on('workerStart', function (swoole_server $serv, int $worker_id) {
$http->on('workerStart', function (swoole_server $server, int $worker_id) {
if ($worker_id === 1) {
$requests = array_fill(0, 6666, ['uri' => 'http://127.0.0.1:1234']);
$res = SaberGM::requests($requests);
echo "use {$res->time}s\n";
echo "success: $res->success_num, error: $res->error_num\n";
// on MacOS
// use 0.91531705856323s
// success: 6666, error: 0
$serv->shutdown();
go(function () use ($server) {
SaberGM::default(['use_pool' => true]);
$requests = array_fill(0, 6666, ['uri' => 'http://127.0.0.1:1234']);
$res = SaberGM::requests($requests, ['max_co' => ((int)(`ulimit -n`) / 2)]);
echo "use {$res->time}s\n";
echo "success: $res->success_num, error: $res->error_num\n";
// on MacOS
// use 0.91531705856323s
// success: 6666, error: 0
saber_pool_release();
swoole_event_exit();
$server->shutdown();
});
}
});
$http->start();

0 comments on commit c87864f

Please sign in to comment.