コード例 #1
0
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 1);
assert_options(ASSERT_ACTIVE, 1);
require dirname(dirname(__DIR__)) . '/dist/libserverbench.phar';
use ServerBench\App\Client\Client as ClientApp;
use ServerBench\App\Client\Poller;
use ServerBench\Base\CliArguments;
$arguments = new CliArguments(['c:' => 'concurrent:', 'C:' => 'connect:', 'T:' => 'time:', 'L:' => 'length:']);
function mt()
{
    return gettimeofday(true) * 1000;
}
if (!isset($arguments['concurrent']) && !isset($arguments['connect']) && !isset($arguments['time'])) {
    die("usage: benchmark.php -c {num of clients} -C {address} -T {timed testing}");
}
define('NUM_OF_CLIENTS', $arguments->get('concurrent'));
define('CONNECT', $arguments->get('connect'));
define('TIME_TO_TESTING', $arguments->get('time') * 1000);
define('LENGTH', $arguments->get('length', 100));
printf("clients %d, connect %s, time to testing %f sec, length %d\n", NUM_OF_CLIENTS, CONNECT, TIME_TO_TESTING / 1000, LENGTH);
// ready
$recv = [];
$clients = [];
$poller = new Poller();
$msg = str_repeat('-', LENGTH);
for ($i = 0; $i < NUM_OF_CLIENTS; ++$i) {
    $client = new ClientApp();
    $client->setSndHwm(1000000);
    $client->setRcvHwm(1000000);
    $client->connect(CONNECT, null, true);
    $client->setRecvTimeout(200);
コード例 #2
0
if (isset($arguments['dir'])) {
    chdir($arguments['dir']);
}
if (!isset($arguments['listen'])) {
    \ServerBench\Cli\printf_and_exit("argument --listen or -l should be set.\n");
}
$listen_addr = explode(',', $arguments['listen']);
if (!isset($arguments['ipcs'])) {
    \ServerBench\Cli\printf_and_exit("argument --ipcs should be set.\n");
}
$ipcs = explode(',', $arguments['ipcs']);
if (count($ipcs) != 2) {
    \ServerBench\Cli\printf_and_exit("argument --ipcs should be a couple of sock files.\n");
}
$api = null;
$app_path = $arguments->get('app');
ProcessUtil::setTitle($arguments->get('title', 'serverbench<proxy>'));
try {
    if (isset($app_path) && file_exists($app_path)) {
        $api = new Api('proxy', include $app_path);
    }
    if ($api && false === $api->init()) {
        \ServerBench\syslog_error('app->init(\'proxy\') returns false.');
        exit;
    }
    PeriodicGc::enable(300);
    $proxy = new Proxy($listen_addr, $ipcs);
    $proxy->run();
    if ($api && false === $api->fini()) {
        \ServerBench\syslog_error('app->fini(\'proxy\') returns false.');
    }
コード例 #3
0
ファイル: cli.php プロジェクト: wedgwood/serverbench.php
if (isset($arguments['help'])) {
    \ServerBench\Cli\printf_and_exit("%s\n", \ServerBench\Cli\get_usage());
}
$phpbin = $_SERVER['_'];
$script = $_SERVER['PWD'] . '/' . $_SERVER['PHP_SELF'];
if (isset($arguments['config'])) {
    $conf_path = realpath($arguments['config']);
    if (!file_exists($conf_path)) {
        \ServerBench\Cli\printf_and_exit("conf(%s) does not exist.\n", $arguments['config']);
    }
    $conf = parse_ini_file($conf_path, true);
    foreach ($conf as $k => $v) {
        $arguments[$k] = $v;
    }
}
$title = $arguments->get('title', 'serverbench');
$dir = $arguments->get('dir', getcwd());
if (isset($dir)) {
    $dir = realpath($dir);
    \ServerBench\syslog_info('cd %s', [$dir]);
    chdir($dir);
}
$get_pidarg = function () use($arguments) {
    $pid = $arguments->get('pid');
    if (!isset($pid)) {
        $pidfile = $arguments->get('pidfile', './pid');
        if (isset($pidfile)) {
            $pidfile = realpath($pidfile);
            if (file_exists($pidfile)) {
                $pid = file_get_contents($pidfile);
            }
コード例 #4
0
 * cli entry of serverbench's worker's pool
 *
 * @author Yuan B.J.
 */
require dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php';
require __DIR__ . '/misc.php';
use ServerBench\App\Server\Api;
use ServerBench\Base\CliArguments;
use ServerBench\Process\Util as ProcessUtil;
use ServerBench\App\Server\PeriodicGc;
use ServerBench\Worker\Worker;
if (PHP_SAPI !== 'cli') {
    \ServerBench\Cli\printf_and_exit("please run @ cli.\n");
}
$arguments = new CliArguments(['d' => 'daemonize', 'D:' => 'dir:', 'T:' => 'title:', 'app:', 'ipcs:']);
$dir = $arguments->get('dir', getcwd());
if (isset($dir)) {
    chdir($dir);
}
$app_path = $arguments->get('app');
if (!isset($app_path)) {
    \ServerBench\Cli\printf_and_exit("arugment --app should be set.\n");
}
if (!file_exists($app_path)) {
    \ServerBench\Cli\printf_and_exit("app(%s) does not exist.", $app_path);
}
if (!isset($arguments['ipcs'])) {
    \ServerBench\Cli\printf_and_exit("argument --ipcs should be set.\n");
}
$ipcs = explode(',', $arguments['ipcs']);
if (count($ipcs) != 2) {