This guide provides a comprehensive overview of Bacalhau's label and constraint system, which enables fine-grained control over job scheduling and resource allocation.
Understanding Labels and Constraints
Labels in Bacalhau are key-value pairs attached to nodes that describe their characteristics, capabilities, and properties. Constraints are rules you define when submitting jobs to ensure they run on nodes with specific labels.
Label Configuration
Command Line Configuration
Labels are defined when starting a Bacalhau node using the -c Labels flag:
# AND logic (all must match)
bacalhau run \
--constraints "storage=ssd" \
--constraints "cpu-arch=x64" \
high-performance-job
# OR logic with value lists
bacalhau run \
--constraints "zone in (us-east1,us-west2)" \
multi-region-job
# Exclusion patterns
bacalhau run \
--constraints "maintenance!=true" \
time-sensitive-job
Maintenance and Operations
Node Updates
# Exclude maintenance nodes
bacalhau run --constraints "!maintenance" critical-job
Monitoring and Troubleshooting
# List all node labels
bacalhau node list --output json | jq '.[] | .Labels'
# Check job constraint matches
bacalhau job describe JOB_ID --include-events
bacalhau node list --labels "required-label=value"
Label Updates Not Taking Effect
Remember that label changes require node restarts. After updating labels:
Gracefully stop the node
Apply new configuration
Restart the node
Verify labels with bacalhau node list
Conclusion
Effective use of Bacalhau's label and constraint system enables precise control over workload placement and resource utilization. Follow these best practices:
Use consistent naming conventions
Document your label taxonomy
Regularly audit and clean up unused labels
Test constraints before production deployment
Monitor constraint patterns for optimization opportunities
For additional support, consult the Bacalhau documentation or community resources.