Skip to content

Commit ca20efe

Browse files
Merge pull request #7 from oracle-quickstart/delta-update
Delta update
2 parents 441aade + e4686ff commit ca20efe

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

delta.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,25 @@ def calculate_p99_latency():
6464
print("No queries were executed.")
6565

6666
def oracle_ping(interval, csvfile):
67-
# Establish a new database connection
67+
6868
conn = oracledb.connect(user=oracle_un, password=oracle_pw, dsn=oracle_cs)
69-
70-
# Get cursor object
7169
cursor = conn.cursor()
72-
73-
# Get session information
7470
cursor.execute("select sys_context('USERENV','SID'), sys_context('USERENV','INSTANCE') from dual")
7571
sid, instance = cursor.fetchone()
7672

77-
# Execute the query and time it
7873
t0 = time.perf_counter()
7974
cursor.execute("select 1 from dual")
8075
cursor.fetchall()
8176
t1 = time.perf_counter()
8277

83-
# Calculate the timings
8478
query_time = (t1 - t0) * 1000
8579
query_times.append(query_time)
8680

87-
# Write the timings to the CSV file
8881
if csvfile is not None:
8982
writer = csv.writer(csvfile)
9083
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
9184
writer.writerow([timestamp, query_time, sid, instance])
9285

93-
# Close the cursor and the connection
9486
cursor.close()
9587
conn.close()
9688

@@ -183,27 +175,27 @@ def url_ping(interval, csvfile):
183175

184176

185177

186-
# Parse command line arguments
178+
# cmd-line arguements
187179
parser = argparse.ArgumentParser(description="Connect and run a query.")
188180
parser.add_argument("--interval", type=float, help="interval between each query, default 1", default=1)
189181
parser.add_argument("--period", type=int, help="runtime in seconds; default 60", default=60)
190182
parser.add_argument("--csvoutput", help="write timings to the named CSV file")
191183
parser.add_argument("--db", choices=['oracle', 'postgresql', 'mysql', 'sqlserver', 'url'], required=True, help="specify the database or url to test")
192184
args = parser.parse_args()
193185

194-
# Open the CSV file if specified
186+
195187
if args.csvoutput is not None:
196188
csvfile = open(args.csvoutput, "w", newline="")
197189
writer = csv.writer(csvfile)
198190
writer.writerow(["Timestamp", "Query time (ms)", "SID", "Instance"])
199191
else:
200192
csvfile = None
201193

202-
# Calculate the start time and the end time
194+
203195
start_time = time.perf_counter()
204196
end_time = start_time + args.period
205197

206-
# Run the main loop
198+
# Main loop
207199
while time.perf_counter() < end_time:
208200
if args.db == 'oracle':
209201
oracle_ping(args.interval, csvfile)
@@ -217,7 +209,6 @@ def url_ping(interval, csvfile):
217209
url_ping(args.interval, csvfile)
218210
time.sleep(args.interval)
219211

220-
# Calculate and print the final P99 latency
221212
calculate_p99_latency()
222213

223214
# Plot the latencies on a graph

0 commit comments

Comments
 (0)