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

[WIP] Add MongoDB Event Store Benchmark #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bench.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

USAGE="Usage: bench.sh --driver [arangodb | postgres | mysql | mariadb] [--strategy Single | Simple | Aggregate]"
USAGE="Usage: bench.sh --driver [arangodb | postgres | mysql | mariadb | mongodb] [--strategy Single | Simple | Aggregate]"

DRIVER=
STREAM_STRATEGY=
Expand Down Expand Up @@ -40,7 +40,7 @@ export DRIVER=${DRIVER}
export STREAM_STRATEGY=${STRATEGY}

echo ""
echo "Starting benchmark ${DRIVER}!"
echo "Starting benchmark ${DRIVER} with strategy ${STRATEGY}!"
php src/prepare.php
php src/benchmark.php
php src/cleanup.php
Expand Down
12 changes: 10 additions & 2 deletions bench_docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

USAGE="Usage: bench_docker.sh --driver [arangodb | postgres | mysql | mariadb] [--strategy Single | Simple | Aggregate]"
USAGE="Usage: bench_docker.sh --driver [arangodb | postgres | mysql | mariadb | mongodb] [--strategy Single | Simple | Aggregate]"

IDLE_TIME=40
DRIVER=
Expand Down Expand Up @@ -68,9 +68,17 @@ sed -i "s/#mem_reservation: dbmem_reservation/mem_reservation: ${MEM}M/g" docker

sed -i "s/BUFFER_POOL_SIZE/${BUFFER_POOL_SIZE}M/g" docker-compose.yml

docker-compose up -d --no-recreate database
docker-compose up -d --no-recreate
docker-compose ps

if [ ${DRIVER} == "mongodb" ]; then
sleep 2
docker-compose exec mongodb0 sh init.sh
sleep 1
docker-compose exec mongodb0 sh status.sh
sleep 1
fi

echo ""
echo ""
echo "Docker Info"
Expand Down
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"prooph/pdo-event-store":"^1.5.1",
"prooph/arangodb-event-store":"dev-master",
"prooph/arangodb-php-driver-polyfill":"dev-master",
"prooph/mongodb-event-store": "dev-feature/projection-change-stream",
"psr/container":"^1.0",
"zendframework/zend-servicemanager":"^3.3",
"vlucas/phpdotenv": "^2.4"
Expand Down Expand Up @@ -47,6 +48,14 @@
{
"type": "git",
"url": "https://github.com/sandrokeil/arangodb-php-driver-polyfill"
},
{
"type": "git",
"url": "[email protected]:sandrokeil/mongodb-event-store.git"
},
{
"type": "git",
"url": "[email protected]:sandrokeil/mongodb-document-store.git"
}
]
}
59 changes: 59 additions & 0 deletions docker-compose-mongodb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: '2.3'
services:
# To run benchmark suite docker-compose run --rm php src/benchmark
php:
image: prooph/php:7.2-cli
environment:
DRIVER: "arangodb"
PHP_IDE_CONFIG: "serverName=application"
MONGODB_HOST: "mongodb://node0.mongodb.local:27017,node1.mongodb.local:27017,node2.mongodb.local:27017/replicaSet=cluster"
MONGODB_DB: event_store_bench
volumes:
- "./:/app"
#cpuset: phpcpuset
#cpu_count: phpcpu_count
#mem_limit: phpmem_limit
#mem_reservation: phpmem_reservation

mongodb0:
build: ./env/docker/mongo
command: ['mongod', '--config', '/etc/mongod.conf']
ports:
- "27017:27017"
hostname: node0.mongodb.local
networks:
default:
aliases:
- node0.mongodb.local
#cpuset: dbcpuset
#cpu_count: dbcpu_count
#mem_limit: dbmem_limit
#mem_reservation: dbmem_reservation

mongodb1:
build: ./env/docker/mongo
command: ['mongod', '--config', '/etc/mongod.conf']
ports:
- "27018:27017"
hostname: node1.mongodb.local
networks:
default:
aliases:
- node1.mongodb.local
#cpuset: dbcpuset
#cpu_count: dbcpu_count
#mem_limit: dbmem_limit

mongodb2:
build: ./env/docker/mongo
command: ['mongod', '--config', '/etc/mongod.conf']
ports:
- "27019:27017"
hostname: node2.mongodb.local
networks:
default:
aliases:
- node2.mongodb.local
#cpuset: dbcpuset
#cpu_count: dbcpu_count
#mem_limit: dbmem_limit
5 changes: 5 additions & 0 deletions env/docker/mongo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mongo:4.0

COPY mongod.conf /etc
COPY init.sh /
COPY status.sh /
5 changes: 5 additions & 0 deletions env/docker/mongo/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -ex

mongo <<EOF
rs.initiate({'_id':'cluster',members:[{'_id':0,'host':'node0.mongodb.local:27017'},{'_id':1,'host':'node1.mongodb.local:27017'},{'_id':2,'host':'node2.mongodb.local:27017'}]});
EOF
25 changes: 25 additions & 0 deletions env/docker/mongo/mongod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# mongod.conf

# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
verbosity: 0
quiet: true

# Where and how to store data.
storage:
dbPath: /data/db
journal:
enabled: true

# network interfaces
net:
port: 27017

#operationProfiling:

replication:
replSetName: cluster

5 changes: 5 additions & 0 deletions env/docker/mongo/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -ex

mongo <<EOF
rs.status();
EOF
46 changes: 43 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace Prooph\EventStoreBenchmarks;

use ArangoDb\Connection;
use MongoDB\Client;
use PDO;
use Prooph\Common\Messaging\FQCNMessageFactory;
use Prooph\EventStore\ArangoDb\EventStore as ArangoDbEventStore;
use Prooph\EventStore\ArangoDb\Projection\ProjectionManager as ArangoDbProjectionManager;
use Prooph\EventStore\ArangoDb\Type\DeleteCollection;
use Prooph\EventStore\EventStore;
use Prooph\EventStore\MongoDb\MongoDbEventStore;
use Prooph\EventStore\MongoDb\Projection\MongoDbProjectionManager;
use Prooph\EventStore\Pdo\MariaDbEventStore;
use Prooph\EventStore\Pdo\MySqlEventStore;
use Prooph\EventStore\Pdo\PostgresEventStore;
Expand All @@ -32,6 +33,7 @@ function testDatabases(): array
'mariadb' => \getenv('MARIADB_DB'),
'postgres' => \getenv('POSTGRES_DB'),
'arangodb' => \getenv('ARANGODB_DB'),
'mongodb' => \getenv('MONGODB_DB'),
];
}

Expand Down Expand Up @@ -69,6 +71,10 @@ function createStreamStrategy(string $driver)
case 'arangodb':
$class = 'Prooph\EventStore\ArangoDb\PersistenceStrategy\\' . \getenv('STREAM_STRATEGY') . 'StreamStrategy';

return new $class();
case 'mongodb':
$class = 'Prooph\EventStore\MongoDb\PersistenceStrategy\MongoDb' . \getenv('STREAM_STRATEGY') . 'StreamStrategy';

return new $class();
default:
throw new \RuntimeException(\sprintf('Driver "%s" not supported', $driver));
Expand Down Expand Up @@ -116,6 +122,14 @@ function createConnection(string $driver)
$connection->connect();

return $connection;
case 'mongodb':
return new Client(
\getenv('MONGODB_HOST'),
[],
['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']]
);
default:
throw new \RuntimeException(\sprintf('Driver "%s" not supported', $driver));
}
}

Expand Down Expand Up @@ -151,6 +165,10 @@ function createDatabase($connection, string $driver, string $dbName): void
execute($connection, null, ...eventStreamsBatch());
execute($connection, null, ...projectionsBatch());
break;
case 'mongodb':
\Prooph\EventStore\MongoDb\MongoDbHelper::createProjectionCollection($connection, $dbName, 'projections');
\Prooph\EventStore\MongoDb\MongoDbHelper::createEventStreamsCollection($connection, $dbName, 'event_streams');
break;
default:
throw new \RuntimeException(\sprintf('Driver "%s" not supported', $driver));
}
Expand All @@ -159,7 +177,7 @@ function createDatabase($connection, string $driver, string $dbName): void
\sleep(1);
}

function destroyDatabase($connection, string $driver, string $dbName): void
function destroyDatabase($connection, string $driver): void
{
switch (\strtolower($driver)) {
case 'mysql':
Expand Down Expand Up @@ -188,6 +206,9 @@ function destroyDatabase($connection, string $driver, string $dbName): void
);
}
break;
case 'mongodb':
$connection->dropDatabase(\getenv('MONGODB_DB'));
break;
default:
throw new \RuntimeException(\sprintf('Driver "%s" not supported', $driver));
}
Expand Down Expand Up @@ -220,6 +241,15 @@ function createEventStore(string $driver, $connection): EventStore
$connection,
createStreamStrategy($driver)
);
case 'mongodb':
return new MongoDbEventStore(
new FQCNMessageFactory(),
$connection,
\getenv('MONGODB_DB'),
createStreamStrategy($driver)
);
default:
throw new \RuntimeException(\sprintf('Driver "%s" not supported', $driver));
}
}

Expand All @@ -246,6 +276,16 @@ function createProjectionManager(EventStore $eventStore, string $driver, $connec
$eventStore,
$connection
);
case 'mongodb':
return new MongoDbProjectionManager(
$eventStore,
$connection,
createStreamStrategy($driver),
new FQCNMessageFactory(),
\getenv('MONGODB_DB')
);
default:
throw new \RuntimeException(\sprintf('Driver "%s" not supported', $driver));
}
}

Expand Down