Ling redistribution across Emacs daemons.
Redistributes lings from overloaded/degraded daemons to healthier ones. Unlike W3 (autoheal) which handles DEAD daemons, redistribution handles ALIVE but stressed daemons — the Emacs process is still running but is degraded or overloaded.
Redistribution is conservative:
DDD: Domain Service — stateless redistribution algorithm. Separated from daemon-selection (SRP: selection vs redistribution).
Ling redistribution across Emacs daemons. Redistributes lings from overloaded/degraded daemons to healthier ones. Unlike W3 (autoheal) which handles DEAD daemons, redistribution handles ALIVE but stressed daemons — the Emacs process is still running but is degraded or overloaded. Redistribution is conservative: 1. Only moves IDLE lings (never interrupts working lings) 2. Only migrates when the target daemon is significantly better 3. Caps migrations per cycle to avoid thundering herd 4. Respects project affinity (prefers same-project daemons) DDD: Domain Service — stateless redistribution algorithm. Separated from daemon-selection (SRP: selection vs redistribution).
(find-migration-candidates daemon)(find-migration-candidates daemon lookup-ling-fn)Find idle lings on an overloaded daemon that can be migrated.
Only idle lings are candidates — working/blocked lings are left alone to avoid task interruption.
Arguments: daemon - Daemon map (from get-all-daemons)
Returns: Seq of maps with :ling-id, :project-id, :ling-status. Empty if no eligible lings.
Find idle lings on an overloaded daemon that can be migrated. Only idle lings are candidates — working/blocked lings are left alone to avoid task interruption. Arguments: daemon - Daemon map (from get-all-daemons) Returns: Seq of maps with :ling-id, :project-id, :ling-status. Empty if no eligible lings.
(find-overloaded-daemons store)Find active daemons that are degraded or overloaded.
A daemon qualifies for redistribution when:
Arguments: store - IEmacsDaemon store instance
Returns: Seq of daemon maps that are candidates for offloading, or nil if none.
Find active daemons that are degraded or overloaded. A daemon qualifies for redistribution when: - Status is :active (still alive — dead daemons are handled by W3 autoheal) - AND either: a) Health level is :degraded (score 30-69) b) Ling count >= overloaded-ling-threshold (near capacity) Arguments: store - IEmacsDaemon store instance Returns: Seq of daemon maps that are candidates for offloading, or nil if none.
Maximum number of lings to redistribute in a single cycle. Prevents thundering herd when many lings need to move.
Maximum number of lings to redistribute in a single cycle. Prevents thundering herd when many lings need to move.
(migrate-ling! store migration)(migrate-ling! store
{:keys [ling-id source-daemon target-daemon]}
lookup-ling-fn)Execute a single ling migration from one daemon to another.
Steps:
Arguments: store - IEmacsDaemon store instance migration - Migration plan map from plan-redistribution
Returns: Map with :success?, :ling-id, :source-daemon, :target-daemon, :reason
Execute a single ling migration from one daemon to another. Steps: 1. Verify ling is still idle (guard against race conditions) 2. Unbind from source daemon 3. Bind to target daemon 4. Log the migration Arguments: store - IEmacsDaemon store instance migration - Migration plan map from plan-redistribution Returns: Map with :success?, :ling-id, :source-daemon, :target-daemon, :reason
A daemon is considered overloaded if it has this many or more lings. Set to max-lings-per-daemon - 1 to trigger before hard cap.
A daemon is considered overloaded if it has this many or more lings. Set to max-lings-per-daemon - 1 to trigger before hard cap.
(plan-redistribution store)Create a redistribution plan: which lings move where.
For each overloaded daemon, finds idle lings and scores potential
target daemons. Only plans migrations that improve by at least
redistribution-score-threshold points.
Arguments: store - IEmacsDaemon store instance
Returns: Seq of migration plan maps: {:ling-id, :source-daemon, :target-daemon, :source-score, :target-score, :improvement} Or nil if no beneficial migrations exist.
Create a redistribution plan: which lings move where.
For each overloaded daemon, finds idle lings and scores potential
target daemons. Only plans migrations that improve by at least
`redistribution-score-threshold` points.
Arguments:
store - IEmacsDaemon store instance
Returns:
Seq of migration plan maps:
{:ling-id, :source-daemon, :target-daemon, :source-score, :target-score, :improvement}
Or nil if no beneficial migrations exist.(redistribute-lings! store)Main entry point: plan and execute ling redistribution.
Called from the heartbeat loop to proactively rebalance lings across daemons when some become degraded or overloaded.
Arguments: store - IEmacsDaemon store instance
Returns: Map with :migrations-planned, :migrations-executed, :results Or nil if no redistribution needed.
Main entry point: plan and execute ling redistribution. Called from the heartbeat loop to proactively rebalance lings across daemons when some become degraded or overloaded. Arguments: store - IEmacsDaemon store instance Returns: Map with :migrations-planned, :migrations-executed, :results Or nil if no redistribution needed.
Minimum score improvement to justify a migration. Prevents churn from marginal improvements.
Minimum score improvement to justify a migration. Prevents churn from marginal improvements.
(redistribution-status store)Get current redistribution status without executing. Monitoring endpoint.
Arguments: store - IEmacsDaemon store instance
Returns: Map with :overloaded-daemons, :planned-migrations, or nil if balanced.
Get current redistribution status without executing. Monitoring endpoint. Arguments: store - IEmacsDaemon store instance Returns: Map with :overloaded-daemons, :planned-migrations, or nil if balanced.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |