@@ -64,33 +64,25 @@ def calculate_p99_latency():
64
64
print ("No queries were executed." )
65
65
66
66
def oracle_ping (interval , csvfile ):
67
- # Establish a new database connection
67
+
68
68
conn = oracledb .connect (user = oracle_un , password = oracle_pw , dsn = oracle_cs )
69
-
70
- # Get cursor object
71
69
cursor = conn .cursor ()
72
-
73
- # Get session information
74
70
cursor .execute ("select sys_context('USERENV','SID'), sys_context('USERENV','INSTANCE') from dual" )
75
71
sid , instance = cursor .fetchone ()
76
72
77
- # Execute the query and time it
78
73
t0 = time .perf_counter ()
79
74
cursor .execute ("select 1 from dual" )
80
75
cursor .fetchall ()
81
76
t1 = time .perf_counter ()
82
77
83
- # Calculate the timings
84
78
query_time = (t1 - t0 ) * 1000
85
79
query_times .append (query_time )
86
80
87
- # Write the timings to the CSV file
88
81
if csvfile is not None :
89
82
writer = csv .writer (csvfile )
90
83
timestamp = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
91
84
writer .writerow ([timestamp , query_time , sid , instance ])
92
85
93
- # Close the cursor and the connection
94
86
cursor .close ()
95
87
conn .close ()
96
88
@@ -183,27 +175,27 @@ def url_ping(interval, csvfile):
183
175
184
176
185
177
186
- # Parse command line arguments
178
+ # cmd- line arguements
187
179
parser = argparse .ArgumentParser (description = "Connect and run a query." )
188
180
parser .add_argument ("--interval" , type = float , help = "interval between each query, default 1" , default = 1 )
189
181
parser .add_argument ("--period" , type = int , help = "runtime in seconds; default 60" , default = 60 )
190
182
parser .add_argument ("--csvoutput" , help = "write timings to the named CSV file" )
191
183
parser .add_argument ("--db" , choices = ['oracle' , 'postgresql' , 'mysql' , 'sqlserver' , 'url' ], required = True , help = "specify the database or url to test" )
192
184
args = parser .parse_args ()
193
185
194
- # Open the CSV file if specified
186
+
195
187
if args .csvoutput is not None :
196
188
csvfile = open (args .csvoutput , "w" , newline = "" )
197
189
writer = csv .writer (csvfile )
198
190
writer .writerow (["Timestamp" , "Query time (ms)" , "SID" , "Instance" ])
199
191
else :
200
192
csvfile = None
201
193
202
- # Calculate the start time and the end time
194
+
203
195
start_time = time .perf_counter ()
204
196
end_time = start_time + args .period
205
197
206
- # Run the main loop
198
+ # Main loop
207
199
while time .perf_counter () < end_time :
208
200
if args .db == 'oracle' :
209
201
oracle_ping (args .interval , csvfile )
@@ -217,7 +209,6 @@ def url_ping(interval, csvfile):
217
209
url_ping (args .interval , csvfile )
218
210
time .sleep (args .interval )
219
211
220
- # Calculate and print the final P99 latency
221
212
calculate_p99_latency ()
222
213
223
214
# Plot the latencies on a graph
0 commit comments