Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cordinate producer and consumer more gracefully #453

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions python/utils/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def producer(
)
if q.qsize() == 0:
break
sleep(1) # don't log to much
logging.info(
"[Parser] The stream is ended",
extra={
Expand Down Expand Up @@ -362,8 +363,12 @@ async def consumer_impl(
total_size = 0
for task_index in range(num_concurrent_processing_tasks):
if task_index == 0:
# If we're the first task, we should wait until we get data.
chain_id, size_in_bytes, transactions = q.get()
# If we're the first task, we should wait longer to get data.
try:
# here the producer may have exited, just calling q.get() will make the consumer_impl be stucked here
chain_id, size_in_bytes, transactions = q.get(timeout=5)
except queue.Empty:
continue
else:
# If we're not the first task, we should poll to see if we get any data.
try:
Expand All @@ -389,7 +394,9 @@ async def consumer_impl(
# os._exit(1)
last_fetched_version = transactions[-1].version
transaction_batches.append(transactions)

if len(transaction_batches) == 0:
# continue to check producer_thread.is_alive()
continue
processor_threads = []
for transactions in transaction_batches:
thread = IndexerProcessorServer.WorkerThread(
Expand Down