Skip to content

Commit 35dd55f

Browse files
committed
Give single-SMILES and CSV-batch their own bounded concurrency lanes
Explicitly configure the Gradio queue (previously implicit/default) with separate concurrency limits per action and a max queue size, so a heavy CSV batch can't starve quick single-SMILES requests and a burst of traffic degrades predictably instead of piling up on the Space's 2-core hardware.
1 parent bfb88da commit 35dd55f

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

scripts/protac_splitter_app.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,14 @@ def create_interface():
396396
cache_examples=True,
397397
)
398398

399-
# Connect the button click event to the processing function
399+
# Connect the button click event to the processing function.
400+
# Own concurrency lane, sized above the CSV lane: single-SMILES calls are
401+
# cheap, so several can run at once without starving each other.
400402
submit_smiles.click(
401403
process_single_smiles,
402404
inputs=[smiles_input, model, beam_size, betweenness_threshold, use_capacity_weight, betweenness_approx_frac],
403-
outputs=[smiles_input_image, smiles_output_images, smiles_output_texts, smiles_output_df]
405+
outputs=[smiles_input_image, smiles_output_images, smiles_output_texts, smiles_output_df],
406+
concurrency_limit=4,
404407
)
405408

406409
# ----------------------------------------------------------------------
@@ -419,14 +422,18 @@ def create_interface():
419422
# Output file download area
420423
download_output = gr.File(label="Download Predictions")
421424

422-
# Connect the button click event to the processing function
425+
# Connect the button click event to the processing function.
426+
# Own concurrency lane, capped at 1: batch jobs already use num_proc worker
427+
# processes internally, so running several batches at once on a 2-core Space
428+
# would oversubscribe the CPU rather than speed anything up.
423429
submit_csv.click(
424430
process_csv,
425431
inputs=[
426432
file_input, smiles_column, model, beam_size, batch_size, num_proc,
427433
betweenness_threshold, use_capacity_weight, betweenness_approx_frac,
428434
],
429-
outputs=[download_output]
435+
outputs=[download_output],
436+
concurrency_limit=1,
430437
)
431438

432439
gr.Markdown(f"""**Note:** The output CSV will contain the following columns:
@@ -462,6 +469,9 @@ def create_interface():
462469
# NOTE: `demo` must be a global variable, so to make the Gradio's hot-reload system work.
463470
# NOTE: Launch the app with `gradio scripts/protac_splitter_app.py` to develop it.
464471
demo = create_interface()
472+
# Bound the total queue backlog so a burst of requests degrades predictably (early
473+
# "queue full" errors) instead of piling up unboundedly on a 2-core Space.
474+
demo.queue(max_size=32)
465475

466476
if __name__ == "__main__":
467477
# Set logging level to DEBUG for detailed output

0 commit comments

Comments
 (0)