-
Notifications
You must be signed in to change notification settings - Fork 32
🎨 Computational backend performance: improvements step1 #8349
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
🎨 Computational backend performance: improvements step1 #8349
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #8349 +/- ##
==========================================
- Coverage 87.86% 87.79% -0.08%
==========================================
Files 1947 1521 -426
Lines 75673 63198 -12475
Branches 1322 679 -643
==========================================
- Hits 66487 55482 -11005
+ Misses 8789 7482 -1307
+ Partials 397 234 -163
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
69434bf to
4d177b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces performance improvements to the computational backend by implementing a Redis-based distributed semaphore system to limit concurrent access and adding a new docker image source for redis-commander.
- Implements a comprehensive distributed semaphore system using Redis with Lua scripts for atomic operations
- Adds a decorator
with_limited_concurrencyto control concurrent function execution across processes - Updates docker-compose configurations to use a different redis-commander image source
Reviewed Changes
Copilot reviewed 23 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| services/web/server/tests/unit/with_dbs/docker-compose-devel.yml | Updates redis-commander image source and adds user configuration |
| services/docker-compose-ops.yml | Updates redis-commander image source and adds user configuration |
| services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_scheduler_dask.py | Integrates distributed semaphore to limit concurrent cluster client acquisitions |
| packages/service-library/tests/redis/test_semaphore_decorator.py | Comprehensive test suite for the semaphore decorator functionality |
| packages/service-library/tests/redis/test_semaphore.py | Test suite for the core distributed semaphore implementation |
| packages/service-library/tests/redis/test_decorators.py | Minor spelling correction in comment |
| packages/service-library/tests/redis/conftest.py | Adds test fixtures for semaphore testing |
| packages/service-library/src/servicelib/redis/lua/*.lua | Atomic Lua scripts for semaphore operations (acquire, release, renew, count) |
| packages/service-library/src/servicelib/redis/_*.py | Core semaphore implementation with decorator, errors, and utilities |
| .github/instructions/*.md | Restructures GitHub Copilot instructions into separate files |
packages/service-library/src/servicelib/redis/_semaphore_decorator.py
Outdated
Show resolved
Hide resolved
services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_scheduler_dask.py
Outdated
Show resolved
Hide resolved
services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_scheduler_dask.py
Outdated
Show resolved
Hide resolved
3ace35b to
03b3d4b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 26 out of 29 changed files in this pull request and generated 2 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 28 out of 30 changed files in this pull request and generated 4 comments.
b674c21 to
399af1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
packages/service-library/src/servicelib/redis/_semaphore_decorator.py
Outdated
Show resolved
Hide resolved
packages/service-library/src/servicelib/redis/_semaphore_decorator.py
Outdated
Show resolved
Hide resolved
services/director-v2/src/simcore_service_director_v2/modules/comp_scheduler/_scheduler_dask.py
Outdated
Show resolved
Hide resolved
f89e4a0 to
5b96c97
Compare
This reverts commit 876c682.
b60cec1 to
701c798
Compare
|



This PR introduces a distributed semaphore support to the service library, enabling concurrency limits for async tasks using Redis.
It adds a new
DistributedSemaphoreclass, associated error types, and Lua scripts to ensure atomic semaphore operations.Distributed Semaphore Feature
DistributedSemaphoreclass inservicelib/redis/_semaphore.pyto provide a Redis-backed distributed semaphore for limiting concurrent operations across processes/instances. This includes context manager support and atomic acquire/release/renew/count operations via Lua scripts.SemaphoreAcquisitionError,SemaphoreNotAcquiredError, andSemaphoreLostErrorinservicelib/redis/_errors.py.with_limited_concurrencydecorator andwith_limited_concurrency_cmdecorator for usage with coroutines/async context managers.Director-v2
How the Semaphore Works
Semaphore Representation: Each semaphore is a Redis sorted set (ZSET), where instance IDs are members and their acquisition timestamps are scores. This allows for time-based expiration and ordering of holders.
Acquisition (acquire_semaphore.lua): On acquire, expired holders are cleaned, capacity is checked, and if available, the instance is inserted into the ZSET and a separate holder key (with TTL) is set. Success/failure, current counts, and cleanup information are returned atomically.
Counting (count_semaphore.lua): Expired holders are removed, and the ZSET cardinality is counted for the active holders.
Release (release_semaphore.lua): Checks if the instance is a current holder, cleans expired, then deletes ZSET entry and holder key. Handles already released and expired situations gracefully.
Renewal (renew_semaphore.lua): Validates current holding, checks if the holder key has expired, and if not, renews both the ZSET score and holder key TTL.
References:
What do these changes do?
Related issue/s
How to test
Dev-ops