fly-shadow: review round 2, R3, G1 (in-shadow back-off), N3 (SHADOW-01)

R3: allows_cutover floors the window at REQUIRED_BRAIN_SECONDS (10,800):
a verdict run with a shorter --required-brain-seconds never passes
check. G1: the in-shadow back-off (LagJudge) judges the live lag growth
rate against fly-shadow-run's pre-start baseline (baseline.json lagRate
and margin, re-read every poll) instead of any growth, and lifts itself
for 10 minutes when a pause did not help (the shadow is not the cause);
--lag-guard-margin replaces --max-live-lag-seconds. N3: lagTransitions
is refreshed at every verdict write, backed off or not, over the rest of
the current file and every newer one.
This commit is contained in:
acamilo 2026-09-30 01:39:42 +00:00
parent 37c7befc11
commit a472adcaf4
5 changed files with 276 additions and 88 deletions

View file

@ -18,7 +18,7 @@
//! | `--mode in-process\|thread\|process` | `in-process` | //! | `--mode in-process\|thread\|process` | `in-process` |
//! | `--threads N` | `$FLY_SHADOW_THREADS`, else 2: the shadow agent's sweep threads | //! | `--threads N` | `$FLY_SHADOW_THREADS`, else 2: the shadow agent's sweep threads |
//! | `--required-brain-seconds S` | 10800 | //! | `--required-brain-seconds S` | 10800 |
//! | `--max-live-lag-seconds S` | 0.5; the shadow pauses 60 s whenever the live `fly_lag_seconds` grew by more than S within 30 s (0 disables) | //! | `--lag-guard-margin S` | 0.05 s/s; the shadow pauses 60 s while the live `fly_lag_seconds` grows faster than `fly-shadow-run`'s baseline rate (`<out>/baseline.json`) plus this margin (the baseline's own margin wins), and stops pausing for 10 minutes when a pause did not help (0 disables) |
//! | `--metrics HOST:PORT` | the live metrics listener | //! | `--metrics HOST:PORT` | the live metrics listener |
//! | `--spool-max-mib N` | 512 | //! | `--spool-max-mib N` | 512 |
//! | `--context N` | 30 transition pairs before a divergence | //! | `--context N` | 30 transition pairs before a divergence |
@ -227,7 +227,7 @@ fn run(mut args: Args) {
let required: f64 = args let required: f64 = args
.parsed("--required-brain-seconds") .parsed("--required-brain-seconds")
.unwrap_or(shadow::REQUIRED_BRAIN_SECONDS); .unwrap_or(shadow::REQUIRED_BRAIN_SECONDS);
let max_lag: f64 = args.parsed("--max-live-lag-seconds").unwrap_or(0.5); let lag_margin: f64 = args.parsed("--lag-guard-margin").unwrap_or(0.05);
let metrics = args.value("--metrics").or_else(|| { let metrics = args.value("--metrics").or_else(|| {
config.control.metrics_bind.map(|addr| { config.control.metrics_bind.map(|addr| {
if addr.ip().is_unspecified() { if addr.ip().is_unspecified() {
@ -266,14 +266,17 @@ fn run(mut args: Args) {
fly_session::legacy_env::DEFAULT_AUDIO_RATE fly_session::legacy_env::DEFAULT_AUDIO_RATE
)); ));
} }
let lag_guard = (max_lag > 0.0) let baseline_file = out_dir.join("baseline.json");
let lag_guard = (lag_margin > 0.0)
.then_some(()) .then_some(())
.and(metrics) .and(metrics)
.map(|metrics_addr| LagGuard { .map(|metrics_addr| LagGuard {
metrics_addr, metrics_addr,
growth_seconds: max_lag, baseline_file: Some(baseline_file),
window: Duration::from_secs(30), margin: lag_margin,
window: Duration::from_secs(60),
back_off: Duration::from_secs(60), back_off: Duration::from_secs(60),
suppress: Duration::from_secs(600),
}); });
let shadow_config = ShadowConfig { let shadow_config = ShadowConfig {
trace_dir, trace_dir,

View file

@ -43,6 +43,28 @@ pub fn superseded(path: &Path) -> bool {
matches!(next_file(dir, Some(path)), Ok(Some(_))) matches!(next_file(dir, Some(path)), Ok(Some(_)))
} }
/// About how many live transitions are written but not yet compared: the bytes beyond `consumed`
/// in `path` and every byte of the newer files, over the mean line length read so far.
pub fn backlog(path: &Path, consumed: u64, lines: u64) -> u64 {
if lines == 0 {
return 0;
}
let mean = (consumed / lines).max(1);
let here = std::fs::metadata(path)
.map(|m| m.len())
.unwrap_or(consumed)
.saturating_sub(consumed);
let newer: u64 = path
.parent()
.and_then(|dir| trace_files(dir).ok())
.into_iter()
.flatten()
.filter(|p| p.file_name() > path.file_name())
.filter_map(|p| std::fs::metadata(p).ok().map(|m| m.len()))
.sum();
(here + newer) / mean
}
/// A reader of one growing file that returns complete lines only. /// A reader of one growing file that returns complete lines only.
pub struct Follower { pub struct Follower {
path: PathBuf, path: PathBuf,
@ -83,19 +105,6 @@ impl Follower {
Ok(Some(line)) Ok(Some(line))
} }
/// About how many complete lines are written but not yet read: the bytes beyond the reader
/// over the mean line length so far.
pub fn backlog_lines(&self) -> u64 {
let Ok(len) = std::fs::metadata(&self.path).map(|m| m.len()) else {
return 0;
};
if self.lines == 0 {
return 0;
}
let mean = (self.consumed / self.lines).max(1);
len.saturating_sub(self.consumed) / mean
}
/// Bytes of an incomplete last line held back. /// Bytes of an incomplete last line held back.
pub fn pending_bytes(&self) -> usize { pub fn pending_bytes(&self) -> usize {
self.partial.len() self.partial.len()
@ -138,5 +147,8 @@ mod tests {
assert_eq!(next_file(dir.path(), None).unwrap(), Some(a.clone())); assert_eq!(next_file(dir.path(), None).unwrap(), Some(a.clone()));
assert_eq!(next_file(dir.path(), Some(&a)).unwrap(), Some(b.clone())); assert_eq!(next_file(dir.path(), Some(&a)).unwrap(), Some(b.clone()));
assert_eq!(next_file(dir.path(), Some(&b)).unwrap(), None); assert_eq!(next_file(dir.path(), Some(&b)).unwrap(), None);
// The backlog counts what is left here and everything in newer files.
std::fs::write(&b, b"01234567890\n01234567890\n").unwrap();
assert_eq!(backlog(&a, follower.consumed, follower.lines), 2);
} }
} }

View file

@ -107,38 +107,162 @@ pub struct ShadowConfig {
pub release: String, pub release: String,
} }
/// The back-off that keeps the shadow from costing the live fly real time. /// The back-off that keeps the shadow from costing the live fly real time, judged against the
/// live fly's own pace before the shadow existed (SHADOW-01 review round 2, G1).
/// ///
/// flysim's `fly_lag_seconds` is the *accumulated* pacing shortfall of the process: it never /// flysim's `fly_lag_seconds` is the accumulated pacing shortfall of the process: it grows, in
/// recovers, and it grows only when the loop fell more than a second behind its schedule /// chunks of more than a second, whenever the loop runs behind real time, and a fly that runs at a
/// (`pacing::MAX_CATCHUP`). So the signal is its growth, not its value: when it has grown by more /// realtime factor of 0.7 grows it by about 0.3 s every second whatever the shadow does. So the
/// than `growth_seconds` within the last `window`, the shadow pauses between frames for /// signal is the lag *growth rate* against the baseline rate `fly-shadow-run start` measured
/// `back_off`, and again for as long as the growth continues. A metrics listener that cannot be /// before the shadow started (`baseline.json`: `lagRate`, `margin`; 0 and `margin` when there is
/// read never pauses the shadow (the guard is a backstop; the unit's `SCHED_IDLE` is the plan). /// none). See [`LagJudge`] for the rule, which lifts the back-off when pausing the shadow does not
/// help: then the shadow is not the cause, and the host guard (`fly-shadow-run guard`) is what
/// acts on a lasting degradation. A metrics listener that cannot be read never pauses the shadow.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct LagGuard { pub struct LagGuard {
/// `host:port` of the live metrics listener. /// `host:port` of the live metrics listener.
pub metrics_addr: String, pub metrics_addr: String,
pub growth_seconds: f64, /// `fly-shadow-run`'s baseline, re-read every poll when it exists.
pub baseline_file: Option<PathBuf>,
/// The allowed rise of the lag growth rate (s/s) when no baseline gives one.
pub margin: f64,
/// The span the growth rate is measured over.
pub window: Duration, pub window: Duration,
pub back_off: Duration, pub back_off: Duration,
/// How long back-offs stay off after one that did not help.
pub suppress: Duration,
} }
/// Whether the live lag grew by more than `growth` seconds within `window` of the newest sample. #[derive(Clone, Copy, Debug, PartialEq)]
/// Samples are `(when, fly_lag_seconds)`, oldest first; a restart (the value falling) is growth enum JudgeMode {
/// from zero. Normal,
pub fn lag_grew(samples: &VecDeque<(Instant, f64)>, window: Duration, growth: f64) -> bool { /// Paused until `until`; the lag and time when the pause began.
let Some(&(newest_at, newest)) = samples.back() else { BackingOff {
return false; until: Instant,
}; from: (Instant, f64),
let mut floor = newest; },
for &(at, value) in samples.iter().rev() { Suppressed {
if newest_at.duration_since(at) > window { until: Instant,
break; },
}
/// The in-shadow back-off rule, fed `(now, fly_lag_seconds)` every poll:
///
/// - *Normal*: when the lag has grown faster than `base_rate + margin` over the last `window`,
/// pause the shadow for `back_off`.
/// - *At the end of a pause*: if the live lag kept growing faster than that while the shadow was
/// paused, the shadow is not the cause: no back-off for `suppress`. Otherwise back to normal,
/// with a fresh window.
/// - A new flysim process (the lag falls) starts the window again.
#[derive(Clone, Debug)]
pub struct LagJudge {
pub base_rate: f64,
pub margin: f64,
window: Duration,
back_off: Duration,
suppress: Duration,
samples: VecDeque<(Instant, f64)>,
mode: JudgeMode,
}
impl LagJudge {
pub fn new(
base_rate: f64,
margin: f64,
window: Duration,
back_off: Duration,
suppress: Duration,
) -> LagJudge {
LagJudge {
base_rate,
margin,
window,
back_off,
suppress,
samples: VecDeque::new(),
mode: JudgeMode::Normal,
} }
floor = floor.min(value);
} }
newest - floor > growth
fn limit(&self) -> f64 {
self.base_rate + self.margin
}
/// The growth rate over the last `window`, once the samples span it.
fn rate(&self) -> Option<f64> {
let &(newest_at, newest) = self.samples.back()?;
let &(oldest_at, oldest) = self
.samples
.iter()
.rev()
.find(|(at, _)| newest_at.duration_since(*at) >= self.window)?;
let dt = newest_at.duration_since(oldest_at).as_secs_f64();
(dt > 0.0).then(|| (newest - oldest) / dt)
}
/// Whether the shadow should be paused now.
pub fn observe(&mut self, now: Instant, lag: f64) -> bool {
if self.samples.back().is_some_and(|&(_, last)| lag < last) {
self.samples.clear();
if let JudgeMode::BackingOff { until, .. } = self.mode {
self.mode = JudgeMode::BackingOff {
until,
from: (now, lag),
};
}
}
self.samples.push_back((now, lag));
while self
.samples
.front()
.is_some_and(|&(at, _)| now.duration_since(at) > self.window * 3)
{
self.samples.pop_front();
}
match self.mode {
JudgeMode::Normal => {
if self.rate().is_some_and(|rate| rate > self.limit()) {
self.mode = JudgeMode::BackingOff {
until: now + self.back_off,
from: (now, lag),
};
return true;
}
false
}
JudgeMode::BackingOff { until, from } => {
if now < until {
return true;
}
let dt = now.duration_since(from.0).as_secs_f64();
let during = if dt > 0.0 { (lag - from.1) / dt } else { 0.0 };
self.mode = if during > self.limit() {
JudgeMode::Suppressed {
until: now + self.suppress,
}
} else {
JudgeMode::Normal
};
self.samples.clear();
self.samples.push_back((now, lag));
false
}
JudgeMode::Suppressed { until } => {
if now >= until {
self.mode = JudgeMode::Normal;
self.samples.clear();
self.samples.push_back((now, lag));
}
false
}
}
}
}
/// `fly-shadow-run`'s baseline: `(lagRate, margin)`.
pub fn read_baseline(path: &Path) -> Option<(f64, f64)> {
let v: Value = serde_json::from_str(&std::fs::read_to_string(path).ok()?).ok()?;
Some((v["lagRate"].as_f64()?, v["margin"].as_f64()?))
} }
/// What the poller shares: the last lag read (ms, `u64::MAX` unknown) and whether to back off. /// What the poller shares: the last lag read (ms, `u64::MAX` unknown) and whether to back off.
@ -181,7 +305,7 @@ impl StopFlag {
} }
} }
/// Polls the live `fly_lag_seconds` every two seconds and applies [`LagGuard`]. /// Polls the live `fly_lag_seconds` every two seconds and applies [`LagJudge`].
fn spawn_lag_poller(guard: &LagGuard, stop: StopFlag) -> Arc<LagState> { fn spawn_lag_poller(guard: &LagGuard, stop: StopFlag) -> Arc<LagState> {
let state = Arc::new(LagState { let state = Arc::new(LagState {
lag_ms: AtomicU64::new(u64::MAX), lag_ms: AtomicU64::new(u64::MAX),
@ -192,32 +316,30 @@ fn spawn_lag_poller(guard: &LagGuard, stop: StopFlag) -> Arc<LagState> {
std::thread::Builder::new() std::thread::Builder::new()
.name("fly-shadow-lag".to_owned()) .name("fly-shadow-lag".to_owned())
.spawn(move || { .spawn(move || {
let mut samples: VecDeque<(Instant, f64)> = VecDeque::new(); let mut judge = LagJudge::new(
let mut until: Option<Instant> = None; 0.0,
guard.margin,
guard.window,
guard.back_off,
guard.suppress,
);
while !stop.requested() { while !stop.requested() {
let now = Instant::now(); if let Some((rate, margin)) = guard.baseline_file.as_deref().and_then(read_baseline)
match read_lag_seconds(&guard.metrics_addr) { {
judge.base_rate = rate;
judge.margin = margin;
}
let back_off = match read_lag_seconds(&guard.metrics_addr) {
Some(lag) => { Some(lag) => {
out.lag_ms.store((lag * 1000.0) as u64, Ordering::Relaxed); out.lag_ms.store((lag * 1000.0) as u64, Ordering::Relaxed);
// A new process starts from zero: forget the old one's samples. judge.observe(Instant::now(), lag)
if samples.back().is_some_and(|&(_, last)| lag < last) {
samples.clear();
}
samples.push_back((now, lag));
while samples
.front()
.is_some_and(|&(at, _)| now.duration_since(at) > guard.window * 2)
{
samples.pop_front();
}
if lag_grew(&samples, guard.window, guard.growth_seconds) {
until = Some(now + guard.back_off);
}
} }
None => out.lag_ms.store(u64::MAX, Ordering::Relaxed), None => {
} out.lag_ms.store(u64::MAX, Ordering::Relaxed);
out.back_off false
.store(until.is_some_and(|u| now < u), Ordering::Relaxed); }
};
out.back_off.store(back_off, Ordering::Relaxed);
std::thread::sleep(Duration::from_secs(2)); std::thread::sleep(Duration::from_secs(2));
} }
}) })
@ -350,6 +472,7 @@ pub async fn run(config: ShadowConfig, stop: StopFlag) -> Result<(Ended, Verdict
lag, lag,
stop, stop,
last_write: Instant::now() - Duration::from_secs(60), last_write: Instant::now() - Duration::from_secs(60),
following: None,
}; };
shadow.write(); shadow.write();
let ended = shadow.follow().await; let ended = shadow.follow().await;
@ -388,11 +511,17 @@ struct Shadow {
stop: StopFlag, stop: StopFlag,
verdict: Verdict, verdict: Verdict,
last_write: Instant, last_write: Instant,
/// The file being compared, the bytes and lines of it compared so far.
following: Option<(PathBuf, u64, u64)>,
} }
impl Shadow { impl Shadow {
fn write(&mut self) { fn write(&mut self) {
self.verdict.spool_evicted = self.spool.evicted(); self.verdict.spool_evicted = self.spool.evicted();
// Refreshed on every write, backed off or not, so the verdict's catch-up bound is current.
if let Some((path, consumed, lines)) = &self.following {
self.verdict.lag_transitions = follow::backlog(path, *consumed, *lines);
}
self.verdict.live_lag_seconds = self.lag.as_ref().and_then(|lag| { self.verdict.live_lag_seconds = self.lag.as_ref().and_then(|lag| {
let ms = lag.lag_ms.load(Ordering::Relaxed); let ms = lag.lag_ms.load(Ordering::Relaxed);
(ms != u64::MAX).then(|| ms as f64 / 1000.0) (ms != u64::MAX).then(|| ms as f64 / 1000.0)
@ -530,7 +659,6 @@ impl Shadow {
)), )),
}; };
} }
self.verdict.lag_transitions = 0;
self.write_if_due(); self.write_if_due();
tokio::time::sleep(self.config.poll).await; tokio::time::sleep(self.config.poll).await;
} }
@ -1020,9 +1148,11 @@ impl Shadow {
self.spool.set_floor(*generation + 1); self.spool.set_floor(*generation + 1);
} }
self.verdict.agreement.count(&behaviour); self.verdict.agreement.count(&behaviour);
if self.verdict.agreement.transitions.is_multiple_of(600) { self.following = Some((
self.verdict.lag_transitions = follower.backlog_lines(); follower.path().to_owned(),
} follower.consumed,
follower.lines,
));
self.verdict.brain_ms += behaviour["ticksAdvanced"] self.verdict.brain_ms += behaviour["ticksAdvanced"]
.as_str() .as_str()
.and_then(|s| s.parse::<f64>().ok()) .and_then(|s| s.parse::<f64>().ok())
@ -1071,25 +1201,60 @@ mod tests {
assert_eq!(parse_lag_seconds("fly_lag_seconds_total 3\n"), None); assert_eq!(parse_lag_seconds("fly_lag_seconds_total 3\n"), None);
} }
#[test] /// Feeds a judge 2-s polls for `seconds`, the lag growing at `rate(paused)` s/s; returns the
fn the_guard_backs_off_on_growth_not_on_an_old_lag() { /// fraction of the time the shadow was paused.
fn paused_fraction(judge: &mut LagJudge, seconds: u64, rate: impl Fn(bool) -> f64) -> f64 {
let t0 = Instant::now(); let t0 = Instant::now();
let at = |s: u64| t0 + Duration::from_secs(s); let (mut lag, mut paused, mut paused_polls) = (5.0, false, 0u64);
let window = Duration::from_secs(30); for i in 0..seconds / 2 {
// An old lag of 40 s that no longer grows: no back-off. lag += 2.0 * rate(paused);
let steady: VecDeque<_> = (0..20).map(|i| (at(i * 2), 40.0)).collect(); paused = judge.observe(t0 + Duration::from_secs(i * 2), lag);
assert!(!lag_grew(&steady, window, 0.5)); paused_polls += u64::from(paused);
// It grew by 1.2 s within the window: back off.
let mut grew = steady.clone();
grew.push_back((at(40), 41.2));
assert!(lag_grew(&grew, window, 0.5));
// The same growth, but longer ago than the window: no longer.
let mut old = grew.clone();
for i in 21..45 {
old.push_back((at(i * 2), 41.2));
} }
assert!(!lag_grew(&old, window, 0.5)); paused_polls as f64 / (seconds / 2) as f64
assert!(!lag_grew(&VecDeque::new(), window, 0.5)); }
fn judge(base_rate: f64) -> LagJudge {
LagJudge::new(
base_rate,
0.05,
Duration::from_secs(60),
Duration::from_secs(60),
Duration::from_secs(600),
)
}
#[test]
fn a_fly_below_real_time_is_judged_against_its_own_pace() {
// The release CT at RTF 0.66: 0.34 s of lag every second, before and during the shadow.
let mut j = judge(0.34);
assert_eq!(paused_fraction(&mut j, 3 * 3600, |_| 0.34), 0.0);
// Without a baseline the same fly is paused once, the pause does not help, and the
// back-off lifts: at most one minute in eleven.
let mut j = judge(0.0);
let f = paused_fraction(&mut j, 3 * 3600, |_| 0.34);
assert!(f > 0.0 && f < 0.1, "{f}");
}
#[test]
fn a_shadow_that_costs_the_fly_time_stays_paused_while_it_would() {
// The fly keeps real time while the shadow is paused and loses 0.3 s/s while it runs:
// pausing helps, so the judge keeps pausing it, most of the time.
let mut j = judge(0.0);
let f = paused_fraction(&mut j, 3 * 3600, |paused| if paused { 0.0 } else { 0.3 });
assert!(f > 0.4, "{f}");
}
#[test]
fn a_restart_starts_the_window_again() {
let t0 = Instant::now();
let mut j = judge(0.0);
for i in 0..40u64 {
assert!(!j.observe(t0 + Duration::from_secs(i * 2), 50.0));
}
// The lag falls to zero (a new process): no rate across the restart.
assert!(!j.observe(t0 + Duration::from_secs(82), 0.0));
assert!(!j.observe(t0 + Duration::from_secs(84), 0.0));
} }
#[test] #[test]

View file

@ -23,7 +23,8 @@
//! cutting over, every one of these holds; anything else keeps the legacy fly: //! cutting over, every one of these holds; anything else keeps the legacy fly:
//! //!
//! - `format` is `fly-shadow-verdict-v1`, `status` is `pass`, `firstDivergence` is `null`, and //! - `format` is `fly-shadow-verdict-v1`, `status` is `pass`, `firstDivergence` is `null`, and
//! `compared.brainSeconds` reaches `required.brainSeconds`; //! `compared.brainSeconds` reaches `required.brainSeconds` and never less than the operator's
//! 10,800 s (`REQUIRED_BRAIN_SECONDS`), whatever window the shadow was run with;
//! - *the release*: `candidate.release` is the directory `/opt/fly/current` resolves to now, //! - *the release*: `candidate.release` is the directory `/opt/fly/current` resolves to now,
//! every binary in `candidate.binaries` still has its recorded SHA-256 there, and the binary //! every binary in `candidate.binaries` still has its recorded SHA-256 there, and the binary
//! being switched to (`flysim-session`, SERVE-01's service) is one of them -- the shadow //! being switched to (`flysim-session`, SERVE-01's service) is one of them -- the shadow
@ -408,9 +409,12 @@ pub fn allows_cutover(
return Err("the verdict is for another compatibility string".to_owned()); return Err("the verdict is for another compatibility string".to_owned());
} }
let compared = verdict["compared"]["brainSeconds"].as_f64().unwrap_or(0.0); let compared = verdict["compared"]["brainSeconds"].as_f64().unwrap_or(0.0);
// The operator's window is a floor the verdict cannot lower: a shadow run with a shorter
// `--required-brain-seconds` (a rehearsal, a test) never arms the cutover.
let required = verdict["required"]["brainSeconds"] let required = verdict["required"]["brainSeconds"]
.as_f64() .as_f64()
.unwrap_or(f64::INFINITY); .unwrap_or(f64::INFINITY)
.max(crate::shadow::REQUIRED_BRAIN_SECONDS);
if compared < required { if compared < required {
return Err(format!("{compared} of {required} brain seconds compared")); return Err(format!("{compared} of {required} brain seconds compared"));
} }
@ -544,6 +548,10 @@ mod tests {
allows_cutover(&pass, "flysim-session", &release, "c", now + 301_000, 300).is_err() allows_cutover(&pass, "flysim-session", &release, "c", now + 301_000, 300).is_err()
); );
assert!(ok(&verdict(Status::Pass, 10_799_000.0)).is_err()); assert!(ok(&verdict(Status::Pass, 10_799_000.0)).is_err());
// A verdict that asked for less than the operator's 3 h never passes the check.
let mut short_window = verdict(Status::Pass, 67_000.0);
short_window["required"]["brainSeconds"] = json!(60.0);
assert!(ok(&short_window).is_err());
for status in [ for status in [
Status::Running, Status::Running,
Status::Diverged, Status::Diverged,

View file

@ -18,7 +18,7 @@
# --bin DIR flysim, fly-shadow (and fly-session for --mode process); default # --bin DIR flysim, fly-shadow (and fly-session for --mode process); default
# $CARGO_TARGET_DIR/release or services/flysim/target/release # $CARGO_TARGET_DIR/release or services/flysim/target/release
# --port N first of three local ports (default 17400) # --port N first of three local ports (default 17400)
# --guard S the shadow's --max-live-lag-seconds against the live metrics (0.5, as # --guard S the shadow's --lag-guard-margin against the live metrics (0.05, as
# on the container; 0 disables) # on the container; 0 disables)
# #
# Environment: FLY_ROM (required); FLYSIM_PATHS_DATASET (default data/fafb-v783); # Environment: FLY_ROM (required); FLYSIM_PATHS_DATASET (default data/fafb-v783);
@ -31,7 +31,7 @@ set -euo pipefail
die() { echo "shadow-rehearsal: $*" >&2; exit 2; } die() { echo "shadow-rehearsal: $*" >&2; exit 2; }
repo="$(cd "$(dirname "$0")/.." && pwd)" repo="$(cd "$(dirname "$0")/.." && pwd)"
checkpoint=""; brain_minutes=30; restart_at=""; sugar_every=20; speed=0; live_threads=3 checkpoint=""; brain_minutes=30; restart_at=""; sugar_every=20; speed=0; live_threads=3
mode=in-process; threads=2; ledgers=1; out=""; bin=""; port=17400; guard=0.5 mode=in-process; threads=2; ledgers=1; out=""; bin=""; port=17400; guard=0.05
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--checkpoint) checkpoint="$2"; shift 2 ;; --checkpoint) checkpoint="$2"; shift 2 ;;
@ -99,7 +99,7 @@ stop_live() {
wall0=$(date +%s.%N) wall0=$(date +%s.%N)
"$bin/fly-shadow" run --out "$shadow_dir" --trace-dir "$live/trace" --all-files --keep-traces --keep-spool \ "$bin/fly-shadow" run --out "$shadow_dir" --trace-dir "$live/trace" --all-files --keep-traces --keep-spool \
--mode "$mode" --threads "$threads" --max-live-lag-seconds "$guard" \ --mode "$mode" --threads "$threads" --lag-guard-margin "$guard" \
--required-brain-seconds "$((brain_minutes * 60))" > "$out/shadow.log" 2>&1 & --required-brain-seconds "$((brain_minutes * 60))" > "$out/shadow.log" 2>&1 &
shadow_pid=$! shadow_pid=$!
# flysim starts no trace without the shadow's heartbeat. # flysim starts no trace without the shadow's heartbeat.