Expand description
Request mirroring (18.11.0, #39): send a copy of a share of requests to other backends — a new version under real traffic, a shadow service — and throw the answers away.
Fire-and-forget: the client’s request never waits for, or depends on, a
mirror. Copies go through a bounded queue to a few worker threads (not a
thread per copy), so a slow or dead mirror can’t use up threads or
memory; when the queue is full the copy is dropped and counted. Only
requests whose body is in memory and at most MAX_MIRRORED_BODY are
mirrored: a streamed upload is read once, by the real backend.
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::proxy::mirror::{Mirror, MirrorLayer};
let shadow = Mirror::new("v2-shadow", vec!["http://10.0.0.9:8080".into()]).percent(10.0);
let app = App::new().wrap(MirrorLayer::new(shadow));Counts: rws_mirror_requests_total{mirror,outcome} with outcome sent
(the mirror answered), failed (no answer), dropped (queue full) and
skipped (body streamed or too large).
Structs§
- Mirror
- One mirror target: backends (round-robin) and the share of requests copied to it. Cheap to clone; clones share their state.
- Mirror
Layer - A
Mirroras middleware: copies the request, then hands it on.
Constants§
- MAX_
MIRRORED_ BODY - Larger request bodies aren’t mirrored.
- QUEUE
- Copies waiting for a worker; past this, copies are dropped.
- WORKERS
- Worker threads sending copies (shared by every mirror).