This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
work.py
127 lines (103 loc) · 3.54 KB
/
work.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import abc
import os
import typing as t
from dataclasses import dataclass
from timeit import default_timer as timer
import neo4j
URL = os.environ.get("NEO4J_URL", "neo4j://localhost:7687")
AUTH_USER = os.environ.get("NEO4J_USER", "neo4j")
AUTH_PASS = os.environ.get("NEO4J_PASS", "pass")
AUTH = (AUTH_USER, AUTH_PASS)
DB = "neo4j"
QUERY_DESERIALIZE = """
UNWIND range(1, $length) AS _
RETURN [
_ IN range(1, $width)
| "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNMM"
] AS x
"""
QUERY_SERIALIZE = """
RETURN 1
"""
class Work(abc.ABC):
def __init__(self: t.Self, width: int, length: int) -> None:
self.width = width
self.length = length
@abc.abstractmethod
def run(self: t.Self, driver: neo4j.Driver, repetition: int) -> float:
raise NotImplementedError()
class WorkDeserialize(Work):
def run(self: t.Self, driver: neo4j.Driver, repetition: int) -> float:
start = timer()
for _ in range(repetition):
driver.execute_query(
QUERY_DESERIALIZE,
database_=DB,
width=self.width,
length=self.length,
)
end = timer()
elapsed = end - start
return elapsed
class WorkSerialize(Work):
def run(self: t.Self, driver: neo4j.Driver, repetition: int) -> float:
data_inner = ["qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNMM"]
data_inner *= self.width
data = [data_inner] * self.length
start = timer()
for _ in range(repetition):
driver.execute_query(
QUERY_SERIALIZE,
database_=DB,
data=data,
)
end = timer()
elapsed = end - start
return elapsed
def work_deserialize(driver: neo4j.Driver, width: int, length: int) -> None:
driver.execute_query(
QUERY_DESERIALIZE,
database_=DB,
width=width,
length=length,
)
@dataclass
class Workload:
name: str
work: t.Type[Work]
width: int
length: int
repetition: int
WORKLOADS = (
Workload("1x1_de", WorkDeserialize, 1, 1, 100),
Workload("10x1_de", WorkDeserialize, 10, 1, 100),
Workload("100x1_de", WorkDeserialize, 100, 1, 100),
Workload("1000x1_de", WorkDeserialize, 1000, 1, 100),
Workload("10000x1_de", WorkDeserialize, 10000, 1, 100),
Workload("100000x1_de", WorkDeserialize, 100000, 1, 100),
Workload("1x10_de", WorkDeserialize, 1, 10, 100),
Workload("1x100_de", WorkDeserialize, 1, 100, 100),
Workload("1x1000_de", WorkDeserialize, 1, 1000, 100),
Workload("1x10000_de", WorkDeserialize, 1, 10000, 100),
Workload("1x1_se", WorkSerialize, 1, 1, 1000),
Workload("10x1_se", WorkSerialize, 10, 1, 1000),
Workload("100x1_se", WorkSerialize, 100, 1, 1000),
Workload("1000x1_se", WorkSerialize, 1000, 1, 1000),
Workload("10000x1_se", WorkSerialize, 10000, 1, 1000),
Workload("1x10_se", WorkSerialize, 1, 10, 1000),
Workload("1x100_se", WorkSerialize, 1, 100, 1000),
Workload("1x1000_se", WorkSerialize, 1, 1000, 1000),
Workload("1x10000_se", WorkSerialize, 1, 10000, 1000),
)
def main() -> None:
print("name,took")
with neo4j.GraphDatabase.driver(URL, auth=AUTH) as driver:
driver.verify_connectivity()
for workload in WORKLOADS:
work = workload.work(workload.width, workload.length)
# warm-up
work.run(driver, 20)
elapsed = work.run(driver, workload.repetition)
print(f"{workload.name},{elapsed}")
if __name__ == "__main__":
main()