Pure health-scoring computation for Emacs daemons.
Extracted from daemon-selection to separate pure scoring algorithms from I/O-bound selection and heartbeat orchestration.
Contains:
DDD: Value Object / Domain Service (pure, no I/O).
Pure health-scoring computation for Emacs daemons. Extracted from daemon-selection to separate pure scoring algorithms from I/O-bound selection and heartbeat orchestration. Contains: - Health classification (health-level, healthy?) - EWMA-based health score computation - Latency, error, and load penalty calculations - Pure heartbeat helpers (metrics, tx-data, report) DDD: Value Object / Domain Service (pure, no I/O).
(apply-recovery-bonus score success? prev-errors)Pure: add recovery-bonus to score iff ping succeeded after prior errors.
Pure: add recovery-bonus to score iff ping succeeded after prior errors.
(capacity-left capacity used)Saturating subtraction for bounded daemon capacity.
Saturating subtraction for bounded daemon capacity.
(clamp-health-score score)Clamp numeric SCORE to the closed health interval 0..100.
Clamp numeric SCORE to the closed health interval 0..100.
(compute-health-score prev-score latency-ms consecutive-errors ling-count)Compute a new health score using EWMA blending of current and previous scores.
The raw score is 100 + penalties from latency, errors, and load. Then blended with the previous score using EWMA for smoothing.
Arguments: prev-score - Previous health score (0-100, nil = 100) latency-ms - Response time of latest heartbeat (nil = failed) consecutive-errors - Number of consecutive heartbeat failures ling-count - Number of lings bound to daemon
Returns: New health score (0-100, integer)
Compute a new health score using EWMA blending of current and previous scores. The raw score is 100 + penalties from latency, errors, and load. Then blended with the previous score using EWMA for smoothing. Arguments: prev-score - Previous health score (0-100, nil = 100) latency-ms - Response time of latest heartbeat (nil = failed) consecutive-errors - Number of consecutive heartbeat failures ling-count - Number of lings bound to daemon Returns: New health score (0-100, integer)
Default health score for daemons without an explicit score. Daemons start healthy until proven otherwise.
Default health score for daemons without an explicit score. Daemons start healthy until proven otherwise.
Health points deducted per consecutive error (capped at error-penalty-max).
Health points deducted per consecutive error (capped at error-penalty-max).
Maximum cumulative error penalty.
Maximum cumulative error penalty.
(error-score-delta consecutive-errors)Compute health score delta from consecutive error count.
Arguments: consecutive-errors - Number of consecutive heartbeat failures
Returns: Negative number (penalty) capped at error-penalty-max.
Compute health score delta from consecutive error count. Arguments: consecutive-errors - Number of consecutive heartbeat failures Returns: Negative number (penalty) capped at error-penalty-max.
EWMA smoothing factor. Higher = more weight on latest measurement. 0.3 means 70% historical, 30% new — smooths transient spikes.
EWMA smoothing factor. Higher = more weight on latest measurement. 0.3 means 70% historical, 30% new — smooths transient spikes.
(health-level score)Classify a health score into a health level.
Arguments: score - Health score 0-100 (nil treated as default-health-score)
Returns: :healthy (70-100), :degraded (30-69), or :unhealthy (0-29)
Classify a health score into a health level. Arguments: score - Health score 0-100 (nil treated as default-health-score) Returns: :healthy (70-100), :degraded (30-69), or :unhealthy (0-29)
(healthy? score)Is the daemon healthy enough for new ling spawns?
Is the daemon healthy enough for new ling spawns?
(heartbeat-report {:keys [success? latency-ms new-errors]}
final-score
ling-count)Pure: shape the public result map returned by heartbeat!.
Pure: shape the public result map returned by heartbeat!.
(heartbeat-tx-data eid now {:keys [success? new-errors]} final-score)Pure: build the DataScript tx payload for a heartbeat update.
Pure: build the DataScript tx payload for a heartbeat update.
Response time threshold for degraded health. Above this = heavy penalty.
Response time threshold for degraded health. Above this = heavy penalty.
Response time threshold for full health. Below this = no penalty.
Response time threshold for full health. Below this = no penalty.
Maximum health points deducted for latency (scales linearly).
Maximum health points deducted for latency (scales linearly).
(latency-score-delta latency-ms)Compute health score delta from response latency.
Arguments: latency-ms - Response time in milliseconds
Returns: Negative number (penalty) or 0 (no penalty). Fast responses (< 500ms): 0 penalty Slow responses (500-2000ms): linear penalty up to -40 Very slow (>2000ms): full -40 penalty
Compute health score delta from response latency. Arguments: latency-ms - Response time in milliseconds Returns: Negative number (penalty) or 0 (no penalty). Fast responses (< 500ms): 0 penalty Slow responses (500-2000ms): linear penalty up to -40 Very slow (>2000ms): full -40 penalty
(ling-load-delta ling-count)Compute health score delta from ling count (load pressure).
Arguments: ling-count - Number of lings bound to daemon
Returns: Negative number (penalty). First ling is free.
Compute health score delta from ling count (load pressure). Arguments: ling-count - Number of lings bound to daemon Returns: Negative number (penalty). First ling is free.
Health points deducted per ling beyond the first. Daemon with 5 lings = 4 * 2 = 8 points penalty.
Health points deducted per ling beyond the first. Daemon with 5 lings = 4 * 2 = 8 points penalty.
(ping-metrics ping-result prev-errors)Pure: derive (success?, latency-ms, new-errors) from a ping-result + prev-errors.
Pure: derive (success?, latency-ms, new-errors) from a ping-result + prev-errors.
Health points recovered per successful heartbeat after errors. Allows gradual recovery from error state.
Health points recovered per successful heartbeat after errors. Allows gradual recovery from error state.
(score-snapshot {:keys [previous latency-ms errors lings]})Schema-shaped pure score projection used by generative/proof facets.
Schema-shaped pure score projection used by generative/proof facets.
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 |