Skip to content

Commit 61b84c8

Browse files
ali-behjatiStanisław Drozd
andauthored
[test-publisher]: Set cap on dyn added symbols (#371)
* [test-publisher]: Set cap on dyn added symbols Currently the test publisher creates a new symbol every two minutes without any cap and running tilt for a long time will eventually drain all the resources. This change sets a cap of PYTH_TEST_SYMBOL_COUNT on the dynamically added symbols. It means that the publisher starts with PYTH_TEST_SYMBOL_COUNT and will add at most PYTH_TEST_SYMBOL_COUNT new symbols after that * Update third_party/pyth/pyth_publisher.py Co-authored-by: Stanisław Drozd <[email protected]> * Update third_party/pyth/pyth_publisher.py Co-authored-by: Stanisław Drozd <[email protected]> * Update third_party/pyth/pyth_publisher.py Co-authored-by: Stanisław Drozd <[email protected]> Co-authored-by: Stanisław Drozd <[email protected]>
1 parent 1a9dfb6 commit 61b84c8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

third_party/pyth/pyth_publisher.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,22 @@ def add_symbol(num: int):
147147
last_new_sym_added_at = time.monotonic()
148148

149149
with ThreadPoolExecutor() as executor: # Used for async adding of products and prices
150+
dynamically_added_symbols = 0
150151
while True:
151152
for sym in HTTP_ENDPOINT_DATA["symbols"]:
152153
publisher_random_update(sym["price"])
153154

154-
# Add a symbol if new symbol interval configured
155-
if PYTH_NEW_SYMBOL_INTERVAL_SECS > 0:
155+
# Add a symbol if new symbol interval configured. This will add a new symbol if PYTH_NEW_SYMBOL_INTERVAL_SECS
156+
# is passed since adding the previous symbol. The second constraint ensures that
157+
# at most PYTH_TEST_SYMBOL_COUNT new price symbols are created.
158+
if PYTH_NEW_SYMBOL_INTERVAL_SECS > 0 and dynamically_added_symbols < PYTH_TEST_SYMBOL_COUNT:
156159
# Do it if enough time passed
157160
now = time.monotonic()
158161
if (now - last_new_sym_added_at) >= PYTH_NEW_SYMBOL_INTERVAL_SECS:
159162
executor.submit(add_symbol, next_new_symbol_id) # Returns immediately, runs in background
160163
last_sym_added_at = now
161164
next_new_symbol_id += 1
165+
dynamically_added_symbols += 1
162166

163167
time.sleep(PYTH_PUBLISHER_INTERVAL_SECS)
164168
sys.stdout.flush()

0 commit comments

Comments
 (0)