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

Adjust swolle settings #15

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
169 changes: 86 additions & 83 deletions aerys/v0.8/composer.lock

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions aerys/v0.8/server-super-tiny.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/*
* (c) 2018, Dmitrijs Balabka
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

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

// This is a very simple HTTP server that just prints a message to each client that connects.
// It doesn't check whether the client sent an HTTP request.

// You might notice that your browser opens several connections instead of just one, even when only making one request.

use Amp\Loop;
use Amp\Socket\ServerSocket;
use function Amp\asyncCoroutine;

Loop::run(function () {
$clientHandler = asyncCoroutine(function (ServerSocket $socket) {
list($ip, $port) = explode(":", $socket->getRemoteAddress());

$buffer = '';
while (($chunk = yield $socket->read()) !== null) {
$buffer .= $chunk;
if (\substr($buffer, -4, 4) === "\r\n\r\n") {
$date = \gmdate("D, d M Y H:i:s", \time()) . " GMT";
$body = "Hello world!";
$bodyLength = \strlen($body);
yield $socket->write("HTTP/1.1 200 OK\r\nContent-Type: text/plain; Charset=utf-8\r\nX-Powered-By: AerysServer\r\nConnection: keep-alive\r\nContent-Length: ${bodyLength}\r\nKeep-Alive: timeout=10000\r\nDate: ${date}\r\n\r\n${body}\r\n\r\n\r\n\r\n");
}
}
});

$server = Amp\Socket\listen("0.0.0.0:8080");

echo "Listening for new connections on " . $server->getAddress() . " ..." . PHP_EOL;

while ($socket = yield $server->accept()) {
$clientHandler($socket);
}
});
2 changes: 1 addition & 1 deletion build/install-local.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& php composer.phar install -o -d ./aerys/v0.5.0 \
Expand Down
2 changes: 1 addition & 1 deletion build/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apt-get update \
&& docker-php-ext-install sockets \
&& docker-php-source extract \
&& pecl channel-update pecl.php.net \
&& printf "\n\n\n\n\n\n\n\n\n\n\n\n\n\n" | pecl install ev-1.0.4 event-2.3.0 swoole-4.2.1 \
&& printf "\n\n\n\n\n\n\n\n\n\n\n\n\n\n" | pecl install swoole-4.2.9 \
&& git clone https://github.com/bwoebi/php-uv.git && cd ./php-uv \
&& phpize && ./configure && make && make install && cd .. && rm -rf ./php-uv \
&& docker-php-source delete \
Expand Down
1 change: 1 addition & 0 deletions php/default-opcache-swoole.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ extension="pcntl.so"

[swoole]
extension="swoole.so"
swoole.aio_thread_num=1
10 changes: 5 additions & 5 deletions react-php/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions start_benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ AERYS1_WO_KEEP_ALIVE_COMMAND="./aerys/v0.5.0/vendor/bin/aerys -w 1 -c ./aerys/v0
#AERYS_COMMAND="./aerys2/vendor/bin/aerys -w 1 -c ./aerys2/server.php --worker-args=\"-n\""
AERYS_COMMAND="./aerys/version/server-tiny.php"
AERYS_TINY_COMMAND="./aerys/version/server-tiny.php"
AERYS_SUPER_TINY_COMMAND="./aerys/version/server-super-tiny.php"
AERYS_CURRENT_VERSION="v0.8"

SWOOLE_COMMAND="./swoole/server.php"
Expand Down Expand Up @@ -51,8 +52,8 @@ function checkPhpConfiguration {
printf "\n${INFO}Check PHP configuration: ${END}"
eval "${PHP_COMMAND} -c ./php/default.ini -i | grep 'zend.assertions => -1 => -1' 1>/dev/null" || { printf "${WARNING}Zend assertion isn't disabled!${END}\n"; exit 1; }
eval "${PHP_COMMAND} -c ./php/default-opcache.ini -i | grep 'opcache.enable => On => On' 1>/dev/null" || { printf "${WARNING}OpCache isn't loaded!${END}\n"; exit 1; }
eval "${PHP_COMMAND} -c ./php/default-opcache-ev.ini -i | grep '^ev$' 1>/dev/null" || { printf "${WARNING}EV isn't loaded!${END}\n"; exit 1; }
eval "${PHP_COMMAND} -c ./php/default-opcache-event.ini -i | grep '^event$' 1>/dev/null" || { printf "${WARNING}Libevent isn't enabled!${END}\n"; exit 1; }
# eval "${PHP_COMMAND} -c ./php/default-opcache-ev.ini -i | grep '^ev$' 1>/dev/null" || { printf "${WARNING}EV isn't loaded!${END}\n"; exit 1; }
# eval "${PHP_COMMAND} -c ./php/default-opcache-event.ini -i | grep '^event$' 1>/dev/null" || { printf "${WARNING}Libevent isn't enabled!${END}\n"; exit 1; }
eval "${PHP_COMMAND} -c ./php/default-opcache-uv.ini -i | grep '^uv$' 1>/dev/null" || { printf "${WARNING}Libuv isn't enabled!${END}\n"; exit 1; }
printf "OK\n"
}
Expand All @@ -77,12 +78,13 @@ php -n -c ./php/default-opcache.ini -i | grep "opcache.jit" 1>/dev/null \
&& start_benchmark "Benchmarking Aerys v0.7.4 (keep-alive + OPCache + w/o JIT)" "${PHP_COMMAND} -c ./php/default-opcache-nojit.ini ${AERYS_COMMAND//version/v0.7.4}"
start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} (keep-alive + OPCache)" "${PHP_COMMAND} -c ./php/default-opcache.ini ${AERYS_COMMAND//version/${AERYS_CURRENT_VERSION}}"
start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} tiny (keep-alive + OPCache)" "${PHP_COMMAND} -c ./php/default-opcache.ini ${AERYS_TINY_COMMAND//version/${AERYS_CURRENT_VERSION}}"
start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} super tiny (keep-alive + OPCache)" "${PHP_COMMAND} -c ./php/default-opcache.ini ${AERYS_SUPER_TINY_COMMAND//version/${AERYS_CURRENT_VERSION}}"
php -n -c ./php/default-opcache.ini -i | grep "opcache.jit" 1>/dev/null \
&& start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} (keep-alive + OPCache + w/o JIT)" "${PHP_COMMAND} -c ./php/default-opcache-nojit.ini ${AERYS_COMMAND//version/${AERYS_CURRENT_VERSION}}"
# TODO: Aerys doesn't work with EV extension on PHP 7.3
php -v | egrep -q "^PHP 7.(1|2)" \
&& start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} (keep-alive + OPCache + ev)" "${PHP_COMMAND} -c ./php/default-opcache-ev.ini ${AERYS_COMMAND//version/${AERYS_CURRENT_VERSION}}"
start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} (keep-alive + OPCache + event)" "${PHP_COMMAND} -c ./php/default-opcache-event.ini ${AERYS_COMMAND//version/${AERYS_CURRENT_VERSION}}"
#php -v | egrep -q "^PHP 7.(1|2)" \
#&& start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} (keep-alive + OPCache + ev)" "${PHP_COMMAND} -c ./php/default-opcache-ev.ini ${AERYS_COMMAND//version/${AERYS_CURRENT_VERSION}}"
#start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} (keep-alive + OPCache + event)" "${PHP_COMMAND} -c ./php/default-opcache-event.ini ${AERYS_COMMAND//version/${AERYS_CURRENT_VERSION}}"
start_benchmark "Benchmarking Aerys ${AERYS_CURRENT_VERSION} (keep-alive + OPCache + uv)" "${PHP_COMMAND} -c ./php/default-opcache-uv.ini ${AERYS_COMMAND//version/${AERYS_CURRENT_VERSION}}"

# Benchmark swoole
Expand Down
8 changes: 7 additions & 1 deletion swoole/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
use Swoole\Http\{Server, Request, Response};

$server = new Server('0.0.0.0', 8080);

// API docs: https://rawgit.com/tchiotludo/swoole-ide-helper/english/docs/classes/swoole_server.html#method_set
$server->set(array(
# https://github.com/swoole/swoole-docs/blob/master/modules/swoole-server/configuration/worker_num.md
'worker_num' => 1,
# https://github.com/swoole/swoole-docs/blob/master/modules/swoole-server/configuration/reactor_num.md
'reactor_num' => 1,
));
$server->on('request', function(Request $request, Response $response) {
if ($request->server['request_uri'] === '/') {
$response->status(200);
Expand Down