-
Notifications
You must be signed in to change notification settings - Fork 5
/
performance_test.py
145 lines (135 loc) · 4.08 KB
/
performance_test.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import math
from icedb.icedb import IceDBv3, CompressionCodec
from icedb.log import S3Client
from time import time
num_rows = 6_000_000
num_parts = 16
s3c = S3Client(s3prefix="tenant", s3bucket="testbucket", s3region="us-east-1", s3endpoint="http://localhost:9000",
s3accesskey="user", s3secretkey="password")
def part_func(row: dict) -> str:
row_time = math.floor(row['ts'])
part = f"{row_time % num_parts}" # do 100 partitions
return part
ice = IceDBv3(
part_func,
['event', 'ts'],
"us-east-1",
"user",
"password",
"http://localhost:9000",
s3c,
"dan-mbp",
s3_use_path=True,
compression_codec=CompressionCodec.ZSTD
)
try:
print("============= testing insert performance ==================")
print(f"making {num_rows} fake rows...")
rows = []
s = time()
for i in range(num_rows):
rows.append({
"ts": math.floor(time()*1000),
"event": "page_load",
"user_id": "a",
"hey": "ho",
"num": 1,
"ee": "fff"
})
print(f"made {num_rows} rows in {time()-s}")
s = time()
inserted = ice.insert(rows)
print(f"Inserted in {time()-s}")
print("\n============= testing insert performance with _partition ==================")
ice = IceDBv3(
part_func,
['event', 'ts'],
"us-east-1",
"user",
"password",
"http://localhost:9000",
s3c,
"dan-mbp",
s3_use_path=True,
compression_codec=CompressionCodec.ZSTD,
)
print(f"making {num_rows} fake rows...")
rows = []
s = time()
for i in range(num_rows):
rows.append({
"ts": math.floor(time() * 1000),
"event": "page_load",
"user_id": "a",
"hey": "ho",
"num": 1,
"ee": "fff",
"_partition": f"{math.floor(time() * 1000) % num_parts}"
})
print(f"made {num_rows} rows in {time() - s}")
s = time()
inserted = ice.insert(rows)
print(f"Inserted in {time() - s}")
print("\n============= testing insert performance with _partition (no delete) ==================")
ice = IceDBv3(
part_func,
['event', 'ts'],
"us-east-1",
"user",
"password",
"http://localhost:9000",
s3c,
"dan-mbp",
s3_use_path=True,
compression_codec=CompressionCodec.ZSTD,
preserve_partition=True
)
print(f"making {num_rows} fake rows...")
rows = []
s = time()
for i in range(num_rows):
rows.append({
"ts": math.floor(time() * 1000),
"event": "page_load",
"user_id": "a",
"hey": "ho",
"num": 1,
"ee": "fff",
"_partition": f"{math.floor(time() * 1000) % num_parts}"
})
print(f"made {num_rows} rows in {time() - s}")
s = time()
inserted = ice.insert(rows)
print(f"Inserted in {time() - s}")
print("test successful!")
except Exception as e:
# print('exception:', type(e).__name__, e)
raise e
finally:
# ================== Clean up =========================
clean = False
if clean:
s3_files: list[dict] = []
no_more_files = False
continuation_token = ""
while not no_more_files:
res = s3c.s3.list_objects_v2(
Bucket=s3c.s3bucket,
MaxKeys=1000,
Prefix='/'.join([s3c.s3prefix, '_log']),
ContinuationToken=continuation_token
) if continuation_token != "" else s3c.s3.list_objects_v2(
Bucket=s3c.s3bucket,
MaxKeys=1000,
Prefix='/'.join([s3c.s3prefix, '_log'])
)
s3_files += res['Contents']
no_more_files = not res['IsTruncated']
if not no_more_files:
continuation_token = res['NextContinuationToken']
for file in s3_files:
s3c.s3.delete_object(
Bucket=s3c.s3bucket,
Key=file['Key']
)
print(f"deleted {len(s3_files)} files")