2017-11-16 17:27:29 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-11-20 18:58:05 +08:00
|
|
|
import sys
|
2017-11-16 17:27:29 +08:00
|
|
|
import os
|
|
|
|
import tempfile
|
|
|
|
from tabulate import tabulate
|
|
|
|
from timeit import default_timer as timer
|
|
|
|
|
|
|
|
# hackish way to resuse existing start code
|
2017-11-20 18:58:05 +08:00
|
|
|
sys.path.append(os.path.dirname(os.path.realpath(__file__)) +
|
2017-11-16 17:27:29 +08:00
|
|
|
"/../tests/macro_benchmark/")
|
|
|
|
from databases import *
|
|
|
|
from clients import *
|
|
|
|
from common import get_absolute_path
|
|
|
|
|
|
|
|
def main():
|
|
|
|
path = get_absolute_path("benchmarking.conf", "config")
|
2017-11-20 18:58:05 +08:00
|
|
|
durability_dir = tempfile.TemporaryDirectory()
|
2017-11-16 17:27:29 +08:00
|
|
|
|
2017-11-20 18:58:05 +08:00
|
|
|
DURABILITY_DIR_ARG = ["--durability-directory", durability_dir.name]
|
|
|
|
MAKE_SNAPSHOT_ARGS = ["--snapshot-on-exit"] + DURABILITY_DIR_ARG
|
|
|
|
RECOVER_SNAPSHOT_ARGS = ["--db-recover-on-startup"] + DURABILITY_DIR_ARG
|
2017-11-16 17:27:29 +08:00
|
|
|
snapshot_memgraph = Memgraph(MAKE_SNAPSHOT_ARGS, path, 1)
|
|
|
|
recover_memgraph = Memgraph(RECOVER_SNAPSHOT_ARGS, path, 1)
|
|
|
|
client = QueryClient(None, 1)
|
|
|
|
|
|
|
|
results = []
|
|
|
|
for node_cnt in [10**6, 5*10**6, 10**7]:
|
|
|
|
for edge_per_node in [0, 1, 3]:
|
|
|
|
for prop_per_node in [0, 1]:
|
|
|
|
snapshot_memgraph.start()
|
|
|
|
properties = "{}".format(",".join(
|
2017-11-20 18:58:05 +08:00
|
|
|
["p{}: 0".format(x) for x in range(prop_per_node)]))
|
2017-11-16 17:27:29 +08:00
|
|
|
client(["UNWIND RANGE(1, {}) AS _ CREATE ({{ {} }})".format(node_cnt, properties)], snapshot_memgraph)
|
|
|
|
client(["UNWIND RANGE(1, {}) AS _ MATCH (n) CREATE (n)-[:l]->(n)"
|
|
|
|
.format(edge_per_node)], snapshot_memgraph)
|
|
|
|
snapshot_memgraph.stop()
|
|
|
|
|
|
|
|
# This waits for the snapshot to be recovered and then exits
|
|
|
|
start = timer()
|
|
|
|
recover_memgraph.start()
|
|
|
|
recover_memgraph.stop()
|
|
|
|
stop = timer()
|
|
|
|
diff = stop - start
|
|
|
|
|
2017-11-20 18:58:05 +08:00
|
|
|
snapshots_dir = os.path.join(durability_dir.name, "snapshots")
|
|
|
|
assert (len(os.listdir(snapshots_dir)) == 1)
|
|
|
|
snapshot_file = os.path.join(snapshots_dir, os.listdir(snapshots_dir)[0])
|
|
|
|
snap_size = round(os.path.getsize(snapshot_file) / 1024. / 1024., 2)
|
|
|
|
os.remove(snapshot_file)
|
2017-11-16 17:27:29 +08:00
|
|
|
|
|
|
|
edge_cnt = edge_per_node * node_cnt
|
|
|
|
results.append((node_cnt, edge_cnt, prop_per_node, snap_size, diff))
|
|
|
|
|
2017-11-20 18:58:05 +08:00
|
|
|
print(tabulate(tabular_data=results, headers=["Nodes", "Edges",
|
2017-11-16 17:27:29 +08:00
|
|
|
"Properties", "Snapshot size (MB)", "Elapsed time (s)"]))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|