Repository navigation
Expand file tree
/
Copy pathtest_types.py
More file actions
202 lines (159 loc) · 6.2 KB
/
Copy pathtest_types.py
File metadata and controls
202 lines (159 loc) · 6.2 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env python3
from __future__ import annotations
import sys
from pathlib import Path
_SCRIPT_DIR = Path(__file__).resolve().parent
_EXAMPLES_DIR = _SCRIPT_DIR.parent
sys.path.insert(0, str(_EXAMPLES_DIR))
from benchbox.platforms.duckdb import DuckDBAdapter
from benchbox.tpch import TPCH
def demonstrate_power_test():
print("=" * 70)
print("TEST TYPE 1: POWER TEST (Sequential Execution)")
print("=" * 70)
print("Purpose: Measure individual query performance")
print("Pattern: Q1 → Q2 → Q3 → ... → Q22 (one at a time)")
print()
benchmark = TPCH(
scale_factor=0.01,
output_dir=Path("./benchmark_runs/features/power_test"),
force_regenerate=False,
)
benchmark.generate_data()
adapter = DuckDBAdapter(database_path=":memory:")
print("Running power test (sequential execution)...")
results = adapter.run_benchmark(
benchmark,
test_execution_type="power",
)
print("\n✓ Power Test Complete!")
print(f" Queries executed: {results.total_queries} (sequential)")
print(f" Total time: {results.total_execution_time:.2f}s")
print(f" Average per query: {results.average_query_time:.2f}s")
print(" Pattern: Each query ran one after another")
print()
def demonstrate_throughput_test():
print("=" * 70)
print("TEST TYPE 2: THROUGHPUT TEST (Concurrent Streams)")
print("=" * 70)
print("Purpose: Measure concurrent query capacity")
print("Pattern: Stream1 || Stream2 || Stream3 (parallel execution)")
print()
benchmark = TPCH(
scale_factor=0.01,
output_dir=Path("./benchmark_runs/features/throughput_test"),
force_regenerate=False,
)
benchmark.generate_data()
adapter = DuckDBAdapter(database_path=":memory:")
print("Running throughput test (concurrent streams)...")
print("Note: This example shows 2 streams for demonstration")
results = adapter.run_benchmark(
benchmark,
test_execution_type="throughput",
)
print("\n✓ Throughput Test Complete!")
print(f" Total queries: {results.total_queries}")
print(f" Total time: {results.total_execution_time:.2f}s")
if results.total_execution_time > 0:
throughput = results.total_queries / results.total_execution_time
print(f" Throughput: {throughput:.2f} queries/second")
print(" Pattern: Multiple streams ran concurrently")
print()
def demonstrate_maintenance_test():
print("=" * 70)
print("TEST TYPE 3: MAINTENANCE TEST (Data Modifications)")
print("=" * 70)
print("Purpose: Measure data modification performance")
print("Pattern: INSERT → UPDATE → DELETE operations")
print()
benchmark = TPCH(
scale_factor=0.01,
output_dir=Path("./benchmark_runs/features/maintenance_test"),
force_regenerate=False,
)
benchmark.generate_data()
db_path = "./benchmark_runs/features/maintenance_test.duckdb"
adapter = DuckDBAdapter(database_path=db_path, force_recreate=True)
print("Running maintenance test (refresh functions)...")
print("Note: Executes INSERT and DELETE operations")
results = adapter.run_benchmark(
benchmark,
test_execution_type="maintenance",
)
print("\n✓ Maintenance Test Complete!")
print(f" Operations: {results.total_queries}")
print(f" Total time: {results.total_execution_time:.2f}s")
print(" Pattern: Data was inserted and deleted")
print(f" Database: {db_path}")
print()
print("=" * 70)
print("⚠️ WARNING: DATABASE HAS BEEN MODIFIED")
print("=" * 70)
print("The maintenance test permanently modified the database by:")
print(" • Inserting new orders and lineitems (RF1)")
print(" • Deleting old orders and lineitems (RF2)")
print()
print("To run power or throughput tests again, you MUST reload the database")
print("with fresh data. The current database contains modified data that will")
print("produce incorrect benchmark results.")
print("=" * 70)
print()
def show_test_type_comparison():
print("=" * 70)
print("WHEN TO USE EACH TEST TYPE")
print("=" * 70)
print()
print("POWER TEST (Sequential):")
print(" ✓ Measuring individual query latency")
print(" ✓ Comparing query-by-query performance")
print(" ✓ Identifying slow queries")
print(" ✓ Standard benchmark reporting")
print()
print("THROUGHPUT TEST (Concurrent):")
print(" ✓ Multi-user workload simulation")
print(" ✓ Measuring maximum capacity")
print(" ✓ Testing concurrent query handling")
print(" ✓ Queries per second metrics")
print()
print("MAINTENANCE TEST (Modifications):")
print(" ✓ Testing data warehouse refresh operations")
print(" ✓ Measuring INSERT/UPDATE/DELETE performance")
print(" ✓ Incremental load testing")
print(" ✓ Change data capture (CDC) patterns")
print()
def main() -> int:
print()
print("=" * 70)
print("BENCHBOX FEATURE: TEST EXECUTION TYPES")
print("=" * 70)
print()
print("This example demonstrates three test execution types.")
print("Each test type measures different aspects of database performance.")
print()
demonstrate_power_test()
demonstrate_throughput_test()
demonstrate_maintenance_test()
show_test_type_comparison()
print("=" * 70)
print("SUMMARY")
print("=" * 70)
print()
print("You learned about three test types:")
print(" 1. Power Test - Sequential queries (individual performance)")
print(" 2. Throughput Test - Concurrent streams (overall capacity)")
print(" 3. Maintenance Test - Data modifications (update performance)")
print()
print("Next steps:")
print(" • Use unified_runner.py with --phases flag:")
print(" --phases power # Power test")
print(" --phases throughput # Throughput test")
print(" --phases maintenance # Maintenance test")
print(" --phases power,throughput # Multiple phases")
print()
print(" • See BENCHMARK_GUIDE.md for more examples")
print(" • Try other feature examples in features/ directory")
print()
return 0
if __name__ == "__main__":
raise SystemExit(main())