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

Update ArangoDB implementation and use projection options #20

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
35 changes: 13 additions & 22 deletions bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ USAGE="Usage: bench.sh --driver [arangodb | postgres | mysql | mariadb] [--strat
DRIVER=
STREAM_STRATEGY=

while [[ ${1} ]]; do
while [ ${1} ]; do
case "${1}" in
--driver)
DRIVER=${2}
Expand Down Expand Up @@ -40,6 +40,8 @@ export DRIVER=${DRIVER}
export STREAM_STRATEGY=${STRATEGY}

echo ""
php -v

echo "Starting benchmark ${DRIVER}!"
php src/prepare.php
php src/benchmark.php
Expand All @@ -54,44 +56,33 @@ php src/prepare.php
WRITER_COUNTER=0
WRITER_ITERATIONS=10

start=$(adjtimex | awk '/(time.tv_sec|time.tv_usec):/ { printf("%07d", $2) }')
read up rest </proc/uptime;
start=${up%.*}${up#*.}

while [ ${WRITER_COUNTER} -lt ${WRITER_ITERATIONS} ]; do
for type in user post todo blog comment
do
php src/writer.php writer${WRITER_COUNTER} ${type} >logs/writer${WRITER_COUNTER}${type}.log &
php src/writer.php writer${WRITER_COUNTER} ${type} | tee logs/writer${WRITER_COUNTER}${type}.log &
done
WRITER_COUNTER=$((WRITER_COUNTER + 1))
done

for type in user post todo blog comment all
do
php src/projector.php projectors${type} ${type} >logs/projector${type}.log &
php src/projector.php projectors${type} ${type} | tee logs/projector${type}.log &
done

echo "Waiting ... stay patient!"
wait

end=$(adjtimex | awk '/(time.tv_sec|time.tv_usec):/ { printf("%07d", $2) }')

WRITER_COUNTER=0
while [ ${WRITER_COUNTER} -lt ${WRITER_ITERATIONS} ]; do
for type in user post todo blog comment
do
cat logs/writer${WRITER_COUNTER}${type}.log
done

WRITER_COUNTER=$((WRITER_COUNTER + 1))
done

for type in user post todo blog comment all
do
cat logs/projector${type}.log
done
read up rest </proc/uptime;
end=${up%.*}${up#*.}

echo ""
duration=$((end - start))
duration=$(printf ${duration} | awk '{ printf("%.08f\n", $1/1000000000.0) }' )
# it's in ms
duration=$((10*(end - start)))

duration=$(printf ${duration} | awk '{ printf("%.08f\n", $1/1000.0) }' )
printf "%s real world test duration %s seconds\\n" "${DRIVER} - ${STRATEGY}" "${duration}";

avgWriters=$(printf ${duration} | awk '{ printf("%.08f\n", 12500/$1) }' )
Expand Down
4 changes: 2 additions & 2 deletions bench_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ USAGE="Usage: bench_docker.sh --driver [arangodb | postgres | mysql | mariadb] [

IDLE_TIME=40
DRIVER=
STREAM_STRATEGY=
STRATEGY=

while [[ ${1} ]]; do
while [ ${1} ]; do
case "${1}" in
--driver)
DRIVER=${2}
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require":{
"prooph/pdo-event-store":"^1.5.1",
"prooph/arangodb-event-store":"dev-master",
"prooph/arangodb-php-driver-polyfill":"dev-master",
"psr/container":"^1.0",
"zendframework/zend-servicemanager":"^3.3",
"vlucas/phpdotenv": "^2.4"
"prooph/pdo-event-store":"^1.10",
"prooph/arangodb-event-store":"^0.2.1",
"vlucas/phpdotenv": "^2.4",
"laminas/laminas-diactoros": "^2.3.0",
"filp/whoops": "^2.7"
},
"require-dev":{
"malukenho/docheader": "^0.1.4",
Expand Down
8 changes: 3 additions & 5 deletions docker-compose-arangodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ version: '2.3'
services:
# To run benchmark suite docker-compose run --rm php src/benchmark
php:
image: prooph/php:7.2-cli
image: prooph/php:7.4-cli
environment:
DRIVER: "arangodb"
PHP_IDE_CONFIG: "serverName=application"
ARANGODB_HOST: "tcp://database:8529"
ARANGODB_USERNAME: ""
ARANGODB_PASSWORD: ""
ARANGODB_DB: _system
ARANGODB_DB: event-store-bench
volumes:
- "./:/app"
#cpuset: phpcpuset
Expand All @@ -18,12 +17,11 @@ services:
#mem_reservation: phpmem_reservation

database:
image: arangodb:3.2
image: arangodb:3.6.4
ports:
- 8529:8529
environment:
ARANGO_NO_AUTH: 1
#ARANGO_STORAGE_ENGINE: rocksdb
#cpuset: dbcpuset
#cpu_count: dbcpu_count
#mem_limit: dbmem_limit
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2.3'
services:
# To run benchmark suite docker-compose run --rm php src/benchmark
php:
image: prooph/php:7.2-cli
image: prooph/php:7.4-cli
environment:
DRIVER: "mariadb"
MARIADB_USER: "dev"
Expand All @@ -19,7 +19,7 @@ services:
#mem_reservation: phpmem_reservation

database:
image: mariadb:10.4.1
image: mariadb:10.5.4
ports:
- 3306
environment:
Expand Down
9 changes: 4 additions & 5 deletions docker-compose-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2.3'
services:
# To run benchmark suite docker-compose run --rm php src/benchmark
php:
image: prooph/php:7.2-cli
image: prooph/php:7.4-cli
environment:
DRIVER: "mysql"
MYSQL_USER: "dev"
Expand All @@ -19,10 +19,9 @@ services:
#mem_reservation: phpmem_reservation

database:
# mysql 8.0 not working properly
# see https://github.com/docker-library/mysql/issues/303
#image: mysql:8.0.13
image: mysql:5.7.24
image: mysql:8.0.21
cap_add:
- SYS_NICE
ports:
- 3306
environment:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2.3'
services:
# To run benchmark suite docker-compose run --rm php src/benchmark
php:
image: prooph/php:7.2-cli
image: prooph/php:7.4-cli
environment:
DRIVER: "postgres"
POSTGRES_USER: "dev"
Expand All @@ -19,7 +19,7 @@ services:
#mem_reservation: phpmem_reservation

database:
image: postgres:9.6
image: postgres:12.3-alpine
ports:
- 5432:5432
environment:
Expand Down
10 changes: 6 additions & 4 deletions env/mysql/my.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ max_heap_table_size = 64M
# * Query Cache Configuration
#
# Cache only tiny result sets, so we can fit more in the query cache.
query_cache_limit = 128K
query_cache_size = 128M
query_cache_min_res_unit=2k
query_cache_type=1

# not available for mysql 8.0.21
# query_cache_limit = 128K
# query_cache_size = 128M
# query_cache_min_res_unit=2k
# query_cache_type=1

# * InnoDB
#
Expand Down
14 changes: 12 additions & 2 deletions src/AllProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Prooph\EventStoreBenchmarks;

use Prooph\Common\Messaging\Message;
use Prooph\EventStore\Pdo\Projection\PdoEventStoreProjector;
use Prooph\EventStore\Util\Assertion;

class AllProjector
Expand Down Expand Up @@ -33,7 +34,15 @@ public function run()

$start = \microtime(true);

$projection = $projectionManager->createProjection('all_projection');
$projection = $projectionManager->createProjection(
'all_projection',
[
PdoEventStoreProjector::OPTION_PERSIST_BLOCK_SIZE => 50,
PdoEventStoreProjector::OPTION_CACHE_SIZE => 50,
PdoEventStoreProjector::OPTION_SLEEP => 10000,
PdoEventStoreProjector::OPTION_PCNTL_DISPATCH => true,
]
);
$projection
->init(function (): array {
return ['count' => 0];
Expand All @@ -57,12 +66,13 @@ public function run()
$avg = $this->stopAt / $time;

outputText("Projection $this->id read $readEvents events");
outputText("Projection $this->id used $time seconds, avg $avg events/second");
outputText("Projection $this->id used $time seconds, avg $avg events/second " . getMemoryConsumption());
outputText("Projection $this->id checking integrity ...", true, '');
Assertion::eq($readEvents, $stopAt, 'Number of all projected events invalid: Value "%s" does not equal expected value "%s".');
outputText(" ok\n", false);
} catch (\Throwable $e) {
echo $e->getMessage() . PHP_EOL . $e->getTraceAsString();
throw $e;
}
}
}
14 changes: 12 additions & 2 deletions src/CategoryProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Prooph\EventStoreBenchmarks;

use Prooph\Common\Messaging\Message;
use Prooph\EventStore\Pdo\Projection\PdoEventStoreProjector;
use Prooph\EventStore\Util\Assertion;
use Ramsey\Uuid\Uuid;

Expand Down Expand Up @@ -37,7 +38,15 @@ public function run()
$start = \microtime(true);
$uuid = Uuid::uuid4()->toString();

$projection = $projectionManager->createProjection('category_projection_' . $uuid);
$projection = $projectionManager->createProjection(
'category_projection_' . $uuid,
[
PdoEventStoreProjector::OPTION_PERSIST_BLOCK_SIZE => 50,
PdoEventStoreProjector::OPTION_CACHE_SIZE => 50,
PdoEventStoreProjector::OPTION_SLEEP => 10000,
PdoEventStoreProjector::OPTION_PCNTL_DISPATCH => true,
]
);
$projection
->init(function (): array {
return ['count' => 0];
Expand All @@ -61,12 +70,13 @@ public function run()
$avg = $this->stopAt / $time;

outputText("Projection $this->id read $readEvents events");
outputText("Projection $this->id used $time seconds, avg $avg events/second");
outputText("Projection $this->id used $time seconds, avg $avg events/second " . getMemoryConsumption());
outputText("Projection $this->id checking integrity ...", true, '');
Assertion::eq($readEvents, 2500, 'Number of category projected events invalid: Value "%s" does not equal expected value "%s".');
outputText(" ok\n", false);
} catch (\Throwable $e) {
echo $e->getMessage() . PHP_EOL . $e->getTraceAsString();
throw $e;
}
}
}
15 changes: 12 additions & 3 deletions src/StreamCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,24 @@ public function run()

$start = \microtime(true);

$streamName = new StreamName($this->category . '-' . $this->id);

for ($i = 0; $i < $this->executions; $i++) {
$count += $this->numberOfEvents;
$streamName = $this->category . '-' . Uuid::uuid4()->toString();
$events = createTestEvents(testPayload(), $this->numberOfEvents);

if ($eventStore instanceof TransactionalEventStore) {
$eventStore->beginTransaction();
}

$eventStore->create(new Stream(new StreamName($streamName), \SplFixedArray::fromArray($events)));
if (getenv('STREAM_STRATEGY') === 'Aggregate') {
$streamName = $this->category . '-' . Uuid::uuid4()->toString();
$eventStore->create(new Stream(new StreamName($streamName), \SplFixedArray::fromArray($events)));
} elseif ($i === 0 && $eventStore->hasStream($streamName) === false) {
$eventStore->create(new Stream($streamName, \SplFixedArray::fromArray($events)));
} else {
$eventStore->appendTo($streamName, \SplFixedArray::fromArray($events));
}

if ($eventStore instanceof TransactionalEventStore) {
$eventStore->commit();
Expand All @@ -65,12 +73,13 @@ public function run()
$avg = ($this->executions * $this->numberOfEvents) / $time;

outputText("Writer $this->id-$this->category wrote $this->eventsWritten events");
outputText("Writer $this->id-$this->category used $time seconds, avg $avg events/second");
outputText("Writer $this->id-$this->category used $time seconds, avg $avg events/second " . getMemoryConsumption());
outputText("Writer $this->id checking integrity ...", true, '');
Assertion::eq($count, $this->numberOfEvents * $this->executions, 'Number of writer events invalid: Value "%s" does not equal expected value "%s".');
outputText(" ok\n", false);
} catch (\Throwable $e) {
echo $e->getMessage() . PHP_EOL . $e->getTraceAsString();
throw $e;
}
}
}
24 changes: 21 additions & 3 deletions src/benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Dotenv\Dotenv;
use Prooph\Common\Messaging\Message;
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Pdo\Projection\PdoEventStoreProjector;
use Prooph\EventStore\Projection\ProjectionManager;
use Prooph\EventStore\Stream;
use Prooph\EventStore\StreamName;
Expand Down Expand Up @@ -143,7 +144,7 @@
$eventsPerSecond = 2500 / $time;

outputText("test 3 using $name took $time seconds");
outputText("test 3 using $name writes $eventsPerSecond events per second\n");
outputText("test 3 using $name writes $eventsPerSecond events per second");
outputText('test 3 checking integrity ...', true, '');
checkWriteIntegrity($eventStore, $numberStreams[$name], $numberEvents[$name]);
outputText(" ok\n", false);
Expand Down Expand Up @@ -178,7 +179,15 @@

foreach ($projectionManagers as $name => $projectionManager) {
/* @var ProjectionManager $projectionManager */
$projection = $projectionManager->createProjection('test_projection_5');
$projection = $projectionManager->createProjection(
'test_projection_5',
[
PdoEventStoreProjector::OPTION_PERSIST_BLOCK_SIZE => 50,
PdoEventStoreProjector::OPTION_CACHE_SIZE => 50,
PdoEventStoreProjector::OPTION_SLEEP => 10000,
PdoEventStoreProjector::OPTION_PCNTL_DISPATCH => true,
]
);
$projection
->init(function (): array {
return ['count' => 0];
Expand Down Expand Up @@ -213,7 +222,15 @@
foreach ($streamNamesTest1[$name] as $streamName) {
$streamNames[] = $streamName->toString();
}
$projection = $projectionManager->createProjection('test_projection_6');
$projection = $projectionManager->createProjection(
'test_projection_6',
[
PdoEventStoreProjector::OPTION_PERSIST_BLOCK_SIZE => 50,
PdoEventStoreProjector::OPTION_CACHE_SIZE => 50,
PdoEventStoreProjector::OPTION_SLEEP => 10000,
PdoEventStoreProjector::OPTION_PCNTL_DISPATCH => true,
]
);
$projection
->init(function (): array {
return ['count' => 0];
Expand All @@ -235,4 +252,5 @@
outputText('test 6 checking integrity ...', true, '');
Assertion::eq($projection->getState()['count'], 1000, 'Number of projected events invalid: Value "%s" does not equal expected value "%s".');
outputText(" ok\n", false);
outputText( "Mem usage/peak: " . getMemoryConsumption() . PHP_EOL, false);
}
Loading