Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61cf837

Browse files
committed
Refactor the main cycle of tpc-ds stress test
1 parent 2ac1f8a commit 61cf837

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

tests/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import select
99
import time
1010

11+
BACKEND_IS_IDLE_INFO = 'INFO: state of backend is idle\n'
12+
BACKEND_IS_ACTIVE_INFO = 'INFO: state of backend is active\n'
13+
1114
def wait(conn):
1215
"""wait for some event on connection to postgres"""
1316
while 1:

tests/tpcds.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,28 @@ def run_tpcds(config):
7878

7979
# periodically run pg_query_state on running backend trying to get
8080
# crash of PostgreSQL
81-
MAX_PG_QS_RETRIES = 10
82-
PG_QS_DELAY, BEFORE_GOT_QS_DELAY = 0.1, 0.1
83-
BEFORE_GOT_QS, GOT_QS = range(2)
84-
state, n_retries = BEFORE_GOT_QS, 0
81+
MAX_FIRST_GETTING_QS_RETRIES = 10
82+
PG_QS_DELAY, BEFORE_GETTING_QS_DELAY = 0.1, 0.1
83+
BEFORE_GETTING_QS, GETTING_QS = range(2)
84+
state, n_first_getting_qs_retries = BEFORE_GETTING_QS, 0
8585
while True:
86-
result, _ = common.pg_query_state(config, pid)
87-
if state == BEFORE_GOT_QS:
88-
if len(result) > 0:
89-
state = GOT_QS
86+
result, notices = common.pg_query_state(config, pid)
87+
# run state machine to determine the first getting query state
88+
# and query finishing
89+
if state == BEFORE_GETTING_QS:
90+
if len(result) > 0 or common.BACKEND_IS_ACTIVE_INFO in notices:
91+
state = GETTING_QS
9092
continue
91-
n_retries += 1
92-
if n_retries >= MAX_PG_QS_RETRIES:
93+
n_first_getting_qs_retries += 1
94+
if n_first_getting_qs_retries >= MAX_FIRST_GETTING_QS_RETRIES:
9395
# pg_query_state callings don't return any result, more likely run
9496
# query has completed
9597
break
96-
time.sleep(BEFORE_GOT_QS_DELAY)
97-
if state == GOT_QS:
98-
if len(result) == 0:
98+
time.sleep(BEFORE_GETTING_QS_DELAY)
99+
elif state == GETTING_QS:
100+
if common.BACKEND_IS_IDLE_INFO in notices:
99101
break
100-
time.sleep(PG_QS_DELAY)
102+
time.sleep(PG_QS_DELAY)
101103

102104
# wait for real query completion
103105
common.wait(acon)

0 commit comments

Comments
 (0)