1414
1515from time import sleep
1616
17+ MAX_PG_QS_RETRIES = 50
18+ TPC_DS_EXCLUDE_LIST = [] # actual numbers of TPC-DS tests to exclude
19+ TPC_DS_STATEMENT_TIMEOUT = 20000 # statement_timeout in ms
20+ stress_in_progress = False
21+
1722def wait (conn ):
1823 """wait for some event on connection to postgres"""
1924 while 1 :
@@ -98,18 +103,21 @@ def pg_query_state(config, pid, verbose=False, costs=False, timing=False, \
98103
99104 conn = psycopg2 .connect (** config )
100105 curs = conn .cursor ()
101- set_guc (conn , 'statement_timeout' , 10000 )
106+
107+ if stress_in_progress :
108+ set_guc (conn , 'statement_timeout' , TPC_DS_STATEMENT_TIMEOUT )
109+ n_retries = 0
102110
103111 result = []
104- n_retries = 0
105112 while not result :
106113 curs .callproc ('pg_query_state' , (pid , verbose , costs , timing , buffers , triggers , format ))
107114 result = curs .fetchall ()
108- n_retries += 1
109115
110- if n_retries == 25 :
111- print ('pg_query_state tried 25 times with no effect' )
112- break
116+ if stress_in_progress :
117+ n_retries += 1
118+ if n_retries >= MAX_PG_QS_RETRIES :
119+ print ('\n pg_query_state tried %s times with no effect, giving up' % MAX_PG_QS_RETRIES )
120+ break
113121
114122 notices = conn .notices [:]
115123 conn .close ()
@@ -549,6 +557,7 @@ def load_tpcds_data(config):
549557
550558def stress_test (config ):
551559 """TPC-DS stress test"""
560+ stress_in_progress = True
552561 load_tpcds_data (config )
553562
554563 print ('Preparing TPC-DS queries...' )
@@ -565,24 +574,24 @@ def stress_test(config):
565574
566575 acon , = n_async_connect (config )
567576
568- print ('Starting test ...' )
577+ print ('Starting TPC-DS queries ...' )
569578 timeout_list = []
570- exclude_list = []
571579 bar = progressbar .ProgressBar (max_value = len (queries ))
572580 for i , query in enumerate (queries ):
573581 bar .update (i + 1 )
574- if i + 1 in exclude_list :
582+ if i + 1 in TPC_DS_EXCLUDE_LIST :
575583 continue
576584 try :
577- # Set query timeout to 10 sec
578- set_guc (acon , 'statement_timeout' , 10000 )
585+ # Set query timeout to TPC_DS_STATEMENT_TIMEOUT / 1000 seconds
586+ set_guc (acon , 'statement_timeout' , TPC_DS_STATEMENT_TIMEOUT )
579587 qs = query_state (config , acon , query )
580588
581- #TODO: Put here testgres exception when supported
582589 except psycopg2 .extensions .QueryCanceledError :
583- timeout_list .append (i )
590+ timeout_list .append (i + 1 )
584591
585592 n_close ((acon ,))
586593
587594 if len (timeout_list ) > 0 :
588- print ('There were pg_query_state timeouts (10s) on queries: ' , timeout_list )
595+ print ('There were pg_query_state timeouts (%s s) on queries:' % TPC_DS_STATEMENT_TIMEOUT , timeout_list )
596+
597+ stress_in_progress = False
0 commit comments