Skip to content

Instantly share code, notes, and snippets.

@rybakit
Last active December 29, 2021 10:54
Show Gist options
  • Save rybakit/f03c2515a203518126c5479954c5fefb to your computer and use it in GitHub Desktop.
Save rybakit/f03c2515a203518126c5479954c5fefb to your computer and use it in GitHub Desktop.
tarantool/client swoole
<?php
/**
* This file is part of the Tarantool Client package.
*
* (c) Eugene Leonovich <gen.work@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
use Tarantool\Client\Client;
require __DIR__.'/../vendor/autoload.php';
$client = Client::fromDefaults();
$client->evaluate(
<<<LUA
if box.space[...] then box.space[...]:drop() end
space = box.schema.space.create(...)
space:create_index('primary', {type = 'tree', parts = {1, 'unsigned'}})
LUA
, 'bench');
$space = Client::fromDefaults()->getSpace('bench');
$spaceId = $space->getId();
printf("# of tuples before: %d\n", $client->call('box.space.bench:count')[0]);
Swoole\Runtime::enableCoroutine();
$s = microtime(true);
for ($c = 100; $c--;) {
go(static function () use ($c, $spaceId) {
$space = Client::fromDefaults()->getSpaceById($spaceId);
for ($n = 1000; $n--;) {
//$client->ping();
$space->replace([$c * 1000 + $n]);
}
});
}
Swoole\Event::wait();
printf("# of tuples after: %d\n", $client->call('box.space.bench:count')[0]);
printf("took %s sec\n", microtime(true) - $s);
# of tuples before: 0
# of tuples after: 100000
took 2.1963551044464 sec
# of tuples before: 0
# of tuples after: 100000
took 5.8799390792847 sec
cd tarantool-php/client
docker run -d --network host --name=tarantool -v $(pwd)/tests/Integration/client.lua:/client.lua tarantool/tarantool:2 tarantool /client.lua
php -n -dextension=swoole.so -dzend_extension=opcache.so -dpcre.jit=1 -dopcache.enable_cli=1 tests/bench_swoole.php
php -n -dextension=swoole.so -dzend_extension=opcache.so -v
PHP 7.2.18 (cli) (built: Apr 30 2019 08:49:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment