-
Notifications
You must be signed in to change notification settings - Fork 453
/
subscribe.py
138 lines (116 loc) · 4.57 KB
/
subscribe.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
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
from random import getrandbits
from textwrap import dedent
from materialize.feature_benchmark.measurement_source import MeasurementSource, Td
from materialize.feature_benchmark.scenario import Scenario
class SubscribeParallel(Scenario):
"""Feature benchmarks related to SUBSCRIBE"""
SCALE = 2 # So 100 concurrent SUBSCRIBEs by default, limited by #18261
FIXED_SCALE = True
def benchmark(self) -> MeasurementSource:
return Td(
self.create_subscribe_source()
+ "\n".join(
[
dedent(
f"""
$ postgres-connect name=conn{i} url=postgres://materialize:materialize@${{testdrive.materialize-sql-addr}}
$ postgres-execute connection=conn{i}
# STRICT SERIALIZABLE is affected by #18353
START TRANSACTION ISOLATION LEVEL SERIALIZABLE;
DECLARE c{i} CURSOR FOR SUBSCRIBE s1
"""
)
for i in range(0, self.n())
]
)
+ self.insert()
# We measure from here ...
+ dedent(
"""
> SELECT COUNT(*) FROM s1;
/* A */
1
"""
)
+ "\n".join(
[
dedent(
f"""
$ postgres-execute connection=conn{i}
FETCH ALL FROM c{i};
"""
)
for i in range(0, self.n())
]
)
# ... to here
+ dedent(
"""
> SELECT 1
/* B */
1
"""
)
)
def create_subscribe_source(self) -> str:
assert False, "Scenario needs to provide a source/table definition"
def insert(self) -> str:
assert False, "Scenario needs to provide insert()"
class SubscribeParallelTable(SubscribeParallel):
def create_subscribe_source(self) -> str:
return dedent(
"""
> DROP TABLE IF EXISTS s1;
> CREATE TABLE s1 (f1 TEXT);
"""
)
def insert(self) -> str:
return "> INSERT INTO s1 VALUES (REPEAT('x', 1024))\n"
class SubscribeParallelTableWithIndex(SubscribeParallel):
def create_subscribe_source(self) -> str:
return dedent(
"""
> DROP TABLE IF EXISTS s1;
> CREATE TABLE s1 (f1 INTEGER);
> CREATE DEFAULT INDEX ON s1;
"""
)
def insert(self) -> str:
return "> INSERT INTO s1 VALUES (123)\n"
class SubscribeParallelKafka(SubscribeParallel):
def create_subscribe_source(self) -> str:
# As we are doing `kafka-ingest` in the middle of the benchmark() method
# we must always use a unique topic to ensure isolation between the individal
# measurements
self._unique_topic_id = getrandbits(64)
return dedent(
f"""
# Separate topic for each Mz instance
$ kafka-create-topic topic=subscribe-kafka-{self._unique_topic_id}
>[version<7800] CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${{testdrive.kafka-addr}}');
>[version>=7800] CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${{testdrive.kafka-addr}}', SECURITY PROTOCOL PLAINTEXT);
> DROP CLUSTER IF EXISTS source_cluster CASCADE;
> CREATE CLUSTER source_cluster SIZE '{self._default_size}', REPLICATION FACTOR 1;
> DROP SOURCE IF EXISTS s1 CASCADE;
> CREATE SOURCE s1
IN CLUSTER source_cluster
FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-subscribe-kafka-{self._unique_topic_id}-${{testdrive.seed}}')
FORMAT BYTES ENVELOPE NONE;
> CREATE DEFAULT INDEX ON s1;
"""
)
def insert(self) -> str:
return dedent(
f"""
$ kafka-ingest format=bytes topic=subscribe-kafka-{self._unique_topic_id}
123
"""
)