-
Notifications
You must be signed in to change notification settings - Fork 0
14_High_Performance_Scaling
BioPro handles computationally intensive biological analysis by offloading heavy lifting to background threads and strictly managing system resources (RAM/GPU).
Analysis tasks never run on the Main UI Thread. If they did, the application would freeze every time you clicked "Run," preventing you from switching tabs or even moving the window.
BioPro uses a QThreadPool to manage worker threads.
- Resource Control: By centralizing tasks, BioPro prevents thread exhaustion (where too many plugins spawn too many threads, crashing the OS).
-
Graceful Concurrency: If you submit 10 analysis tasks but only have 4 CPU cores, the
TaskSchedulerwill queue them and run them as threads become available.
graph TD
UI[🖱 User Click] -->|Submit| TS((⚙️ Task Scheduler))
TS -->|Queue| P[🧵 Global Thread Pool]
P -->|Run| W1[🧪 Worker 1]
P -->|Run| W2[🧪 Worker 2]
W1 -->|Finished| NB((🧠 Event Bus))
NB -->|Notify| UI
Every background task follows a strict lifecycle managed by the SDK and Core.
-
Submission: You pass an
AnalysisBaseand aPluginStatetotask_scheduler.submit(). -
Worker Initialization: The scheduler wraps your logic in an
AnalysisWorker(a QObject) and anAnalysisRunnable. -
Execution: The task runs in the background. It can emit
progress(int)signals without touching the UI. - Completion: Upon success, results are merged back into the state, and the UI is notified via the Nervous System (Event Bus).
Third-party plugins can accidentally "leak" memory if they leave large objects (like 4K images) in variables that aren't cleared. BioPro's ResourceInspector acts as a proactive garbage collector.
The ResourceInspector scans object trees for "Heavy" items (threshold > 1MB):
- Numpy Arrays: Scanned for byte size.
- Torch Tensors: GPU tensors are always flagged for immediate release.
- Matplotlib Figures: Flagged because they often hold references to GUI backends.
- File Handles: Flagged to ensure they are closed.
When a plugin tab is closed, BioPro runs a "Cleanse" operation:
- All identified heavy objects are nullified.
- GPU tensors are moved to CPU and deleted to avoid CUDA out-of-memory errors.
- Python's Garbage Collector is given a clear path to reclaim the memory immediately.
The central registry for all background work.
-
submit(analyzer, state): Offloads an analysis to the thread pool. -
task_finished(task_id, results): Global signal emitted when any background task completes. -
cancel_all(): Flushes the queue (useful during app shutdown).
Utility for deep-inspecting memory usage.
-
get_heavy_resources(obj): Returns a list of attribute names and objects that consume significant memory. -
is_heavy(value): Boolean check for specific types (Numpy/Torch/Matplotlib).