Skip to content

⚡ Offload blocking artifact import to threadpool#77

Open
miethe wants to merge 1 commit intomainfrom
perf-fix-blocking-import-10026217330691831741
Open

⚡ Offload blocking artifact import to threadpool#77
miethe wants to merge 1 commit intomainfrom
perf-fix-blocking-import-10026217330691831741

Conversation

@miethe
Copy link
Owner

@miethe miethe commented Feb 10, 2026

💡 What: Optimized the import_artifacts and reimport_catalog_entry endpoints in skillmeat/api/routers/marketplace_sources.py by offloading the synchronous, blocking coordinator.import_entries call to a thread pool using starlette.concurrency.run_in_threadpool.

🎯 Why: The ImportCoordinator.import_entries method performs blocking network I/O (using requests) to download artifacts from GitHub. When called directly within an async def FastAPI endpoint, this blocks the main event loop, preventing the server from handling other concurrent requests until the download completes. This degraded overall API responsiveness during imports.

📊 Measured Improvement:
A reproduction script (tests/reproduce_blocking.py) was used to simulate a blocking import operation (2s sleep) while concurrently sending a "ping" request.

  • Baseline: The "ping" request was blocked and took ~1.74s to complete.
  • Improved: With the optimization, the "ping" request completed in ~0.006s, demonstrating that the event loop remained responsive.

Existing tests (tests/test_marketplace_catalog_repository.py and tests/test_cache_marketplace.py) were run and passed, ensuring no regressions in related functionality. Some legacy tests (tests/test_cli_marketplace_integration.py) failed due to unrelated pre-existing issues (missing skillman module), consistent with repository history.


PR created automatically by Jules for task 10026217330691831741 started by @miethe

- Wraps `coordinator.import_entries` with `run_in_threadpool` in `marketplace_sources.py`
- Prevents blocking the async event loop during artifact downloads (sync I/O)
- Applied to both `import_artifacts` and `reimport_catalog_entry` endpoints
- Reduces endpoint latency for concurrent requests significantly (from >1s to <0.01s during import)

Co-authored-by: miethe <6800980+miethe@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant