How Lease Balancing and Stealing works
masterKCL performs lease balancing to protect against worker interruptions (e.g., host failures). If a worker stops updating its leases, other workers can take them over.
Key Concepts:
- Balancing Interval: Balancing occurs at an interval configured by
leaseDurationandepsilonMillis. - Lease Stealing: If a worker wants more leases and there are no expired leases available, it can "steal" a lease. Stolen leases are randomly selected from the worker currently holding the most leases.
- Configuration: The maximum number of leases a worker can steal in a single loop is controlled by
maxLeasesToStealAtOneTime.
Trade-offs to consider:
- DynamoDB Cost:
LeaseRefresherperforms ascanon the lease table; frequent scans increase costs proportional to the number of leases. - Turnover vs. Stability: Frequent balancing increases DynamoDB
writecosts and can cause redundant work due to high lease turnover. - Recovery Speed: A low
maxLeasesToStealAtOneTimevalue may slow down the reassignment of leases during major events like deployments or host failures.