crafty_proto/queue_autoscale.rs
1//! Queue autoscale policy metadata replicated through Meta-Raft / group 0.
2
3use serde::{Deserialize, Serialize};
4
5/// Serializable worker autoscale tunables (durations as millis).
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub struct AutoscalePolicyWire {
8 /// Actor group name to scale (registered worker type).
9 pub worker_group: String,
10 /// Target `(pending + leased) / worker` before scaling up.
11 pub target_pending_per_worker: u64,
12 /// Floor on worker instance count.
13 pub min_workers: usize,
14 /// Ceiling on worker instance count (also capped by live node count).
15 pub max_workers: usize,
16 /// Minimum time between scale decisions (millis).
17 pub cooldown_ms: u64,
18 /// Metrics sampling interval (millis).
19 pub poll_interval_ms: u64,
20}
21
22/// Serializable membership autoscale tunables (durations as millis).
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24pub struct MembershipAutoscalePolicyWire {
25 /// Add a node when `(pending + leased) / live_nodes` exceeds this.
26 pub pending_per_node_threshold: u64,
27 /// Maximum cluster size this policy may grow to.
28 pub max_nodes: usize,
29 /// Minimum time between join attempts (millis).
30 pub cooldown_ms: u64,
31 /// Depth sampling interval (millis).
32 pub poll_interval_ms: u64,
33}
34
35/// Upsert queue autoscale policy for `stream` (Meta-Raft metadata entry).
36#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
37pub struct QueueAutoscalePolicyCommand {
38 /// Queue stream these policies apply to.
39 pub stream: String,
40 /// Worker-group scaling policy (`None` leaves prior worker policy unchanged).
41 pub worker: Option<AutoscalePolicyWire>,
42 /// Cluster membership scaling policy (`None` leaves prior membership policy unchanged).
43 pub membership: Option<MembershipAutoscalePolicyWire>,
44}