Loadbalancer
cutana.loadbalancer
¶
Load balancer module for Cutana - manages dynamic resource allocation and process spawning.
This module handles: - Main process memory monitoring and worker memory allocation - Dynamic memory-based process spawning decisions - Periodic memory usage tracking with peak detection - Real-time load balancing with detailed logging
LoadBalancer(progress_dir=None, session_id=None)
¶
Manages dynamic load balancing for cutout processing.
Monitors main process memory and worker memory usage to make intelligent decisions about when to spawn new worker processes.
Initialize the load balancer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress_dir
|
str
|
Directory for progress files |
None
|
session_id
|
str
|
Session ID for progress file isolation |
None
|
update_memory_tracking()
¶
Update memory tracking synchronously. Called by orchestrator when needed.
log_memory_status_if_needed()
¶
Log memory status if enough time has passed. Called by orchestrator periodically.
update_config_with_loadbalancing(config, total_sources=None)
¶
Update configuration with optimal load balancing settings based on system resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
DotMap
|
Configuration DotMap to update |
required |
total_sources
|
int
|
Total number of sources to process (optional) |
None
|
update_memory_statistics(process_id)
¶
Update memory usage statistics from a completed process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process_id
|
str
|
Process ID to get memory statistics from |
required |
update_active_worker_count(count)
¶
Update the number of active worker processes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Current number of active worker processes |
required |
can_spawn_new_process(active_process_count, active_process_ids=None)
¶
Determine if a new process can be spawned based on current resource usage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active_process_count
|
int
|
Number of currently active processes |
required |
active_process_ids
|
List[str]
|
List of currently active process IDs (optional) |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple of (can_spawn, reason_message) |
get_spawn_recommendation(active_processes, pending_batches)
¶
Get recommendation for process spawning based on current state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active_processes
|
Dict[str, Any]
|
Dictionary of currently active processes |
required |
pending_batches
|
int
|
Number of batches still to process |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with spawn recommendation and reasoning |
get_resource_status()
¶
Get comprehensive resource status information for UI display.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with current resource status |