@@ -23,10 +23,12 @@ def run_latency_test(
23
23
database = "" ,
24
24
url = "" ,
25
25
interval = 1.0 ,
26
- period = 10
26
+ period = 10 ,
27
+ custom_sql = ""
27
28
):
28
29
query_times = []
29
30
result_info = {"success" : False , "error" : None , "latency_stats" : {}, "details" : []}
31
+ custom_sql = (custom_sql or "" ).strip ()
30
32
try :
31
33
end_time = time .perf_counter () + period
32
34
while time .perf_counter () < end_time :
@@ -36,29 +38,33 @@ def run_latency_test(
36
38
if dbtype == "oracle" :
37
39
conn = oracledb .connect (user = username , password = password , dsn = host )
38
40
cursor = conn .cursor ()
39
- cursor .execute ("select 1 from dual" )
41
+ sql = custom_sql if custom_sql else "select 1 from dual"
42
+ cursor .execute (sql )
40
43
cursor .fetchall ()
41
44
cursor .close ()
42
45
conn .close ()
43
46
elif dbtype == "postgresql" :
44
47
conn = psycopg2 .connect (host = host , port = port , dbname = database , user = username , password = password )
45
48
cursor = conn .cursor ()
46
- cursor .execute ("SELECT 1" )
49
+ sql = custom_sql if custom_sql else "SELECT 1"
50
+ cursor .execute (sql )
47
51
cursor .fetchall ()
48
52
cursor .close ()
49
53
conn .close ()
50
54
elif dbtype == "mysql" :
51
55
conn = pymysql .connect (host = host , port = int (port ), user = username , password = password , db = database )
52
56
cursor = conn .cursor ()
53
- cursor .execute ("SELECT 1" )
57
+ sql = custom_sql if custom_sql else "SELECT 1"
58
+ cursor .execute (sql )
54
59
cursor .fetchall ()
55
60
cursor .close ()
56
61
conn .close ()
57
62
elif dbtype == "sqlserver" and mssql_ok :
58
63
conn_str = f"DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={ host } ,{ port } ;DATABASE={ database } ;UID={ username } ;PWD={ password } "
59
64
conn = pyodbc .connect (conn_str )
60
65
cursor = conn .cursor ()
61
- cursor .execute ("SELECT 1" )
66
+ sql = custom_sql if custom_sql else "SELECT 1"
67
+ cursor .execute (sql )
62
68
cursor .fetchall ()
63
69
cursor .close ()
64
70
conn .close ()
@@ -81,7 +87,6 @@ def run_latency_test(
81
87
"error" : error
82
88
})
83
89
time .sleep (interval )
84
- # Compute p99, p90, avg, stddev, mean on all query_times
85
90
arr = np .array (query_times )
86
91
result_info ["latency_stats" ] = {
87
92
"p99" : float (np .percentile (arr , 99 )) if len (arr ) else None ,
0 commit comments