synapse
A component of the AienOS ecosystem.
Brought by drakestapleton
synapse / crates / synapse-bench / src / query.rs
| 1 | //! Read-phase measurement: checkout-free queries against a populated Synapse service and |
| 2 | //! equivalent `git` CLI queries against a repository holding the same proposals as |
| 3 | //! commits, plus the per-proposal transfer-size estimate. |
| 4 | //! |
| 5 | //! Queries run from one client thread with no concurrent writers (separate from the write |
| 6 | //! phase; no mixed-load claim). Synapse timings include request signing, JSON request |
| 7 | //! encode/decode, the API call, and JSON response encode/decode for every page; `api_us` |
| 8 | //! records the API call alone. Git timings include process spawn unless the method is the |
| 9 | //! persistent `git cat-file --batch` process. |
| 10 | |
| 11 | use crate::fixture::{self, CatFileBatch}; |
| 12 | use crate::git_arm; |
| 13 | use crate::gitcmd::{git_ok, run_git}; |
| 14 | use crate::rng::SplitMix64; |
| 15 | use crate::rusage::sample_self; |
| 16 | use crate::stats::{round3, summarize_us, LatencySummary}; |
| 17 | use crate::synapse_arm::{self, AgentIdentity}; |
| 18 | use crate::workload::{generate_write_workload, EditOp, Proposal}; |
| 19 | use crate::write_jsonl; |
| 20 | use serde::de::DeserializeOwned; |
| 21 | use serde::{Deserialize, Serialize}; |
| 22 | use std::path::PathBuf; |
| 23 | use std::time::Instant; |
| 24 | use synapse_api::{ |
| 25 | ConflictQueryPayload, DiffQueryPayload, PageRequest, PageResponse, SynapseService, |
| 26 | TreeQueryPayload, TreeTarget, DEFAULT_MAX_PAGE_SIZE, |
| 27 | }; |
| 28 | use synapse_core::{ChangesetId, GitOid, RepoId, WalSeq}; |
| 29 | use synapse_store::{FsyncPolicy, IngestOutcome, RecoveryPolicy}; |
| 30 | |
| 31 | /// Input for one query cell. |
| 32 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 33 | pub struct QuerySpec { |
| 34 | pub rep: usize, |
| 35 | pub seed: u64, |
| 36 | pub agents: usize, |
| 37 | pub ops_per_agent: usize, |
| 38 | pub samples: usize, |
| 39 | pub clone_dir: PathBuf, |
| 40 | pub base_commit: String, |
| 41 | pub cell_dir: PathBuf, |
| 42 | pub trace_path: PathBuf, |
| 43 | } |
| 44 | |
| 45 | /// One timed query. |
| 46 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 47 | pub struct QueryTrace { |
| 48 | pub rep: usize, |
| 49 | pub query: String, |
| 50 | pub sample: usize, |
| 51 | pub latency_us: u64, |
| 52 | pub api_us: Option<u64>, |
| 53 | pub request_bytes: Option<u64>, |
| 54 | pub response_bytes: Option<u64>, |
| 55 | pub pages: Option<usize>, |
| 56 | /// Synapse only: the call built at least one changeset tree (not answered from the memo). |
| 57 | pub cold: Option<bool>, |
| 58 | pub result_items: Option<usize>, |
| 59 | pub ok: bool, |
| 60 | pub error: Option<String>, |
| 61 | } |
| 62 | |
| 63 | /// Summary of one query method. |
| 64 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 65 | pub struct QueryKindResult { |
| 66 | pub query: String, |
| 67 | pub system: String, |
| 68 | pub method: String, |
| 69 | pub latency: Option<LatencySummary>, |
| 70 | pub api_only: Option<LatencySummary>, |
| 71 | pub failures: usize, |
| 72 | pub cold_samples: Option<usize>, |
| 73 | pub mean_pages: Option<f64>, |
| 74 | pub mean_response_bytes: Option<f64>, |
| 75 | } |
| 76 | |
| 77 | /// Byte-size distribution. |
| 78 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 79 | pub struct ByteSummary { |
| 80 | pub n: usize, |
| 81 | pub min: u64, |
| 82 | pub p50: u64, |
| 83 | pub max: u64, |
| 84 | pub mean: f64, |
| 85 | pub total: u64, |
| 86 | } |
| 87 | |
| 88 | pub fn byte_summary(values: &[u64]) -> Option<ByteSummary> { |
| 89 | if values.is_empty() { |
| 90 | return None; |
| 91 | } |
| 92 | let mut v = values.to_vec(); |
| 93 | v.sort_unstable(); |
| 94 | let total: u64 = v.iter().sum(); |
| 95 | Some(ByteSummary { |
| 96 | n: v.len(), |
| 97 | min: v[0], |
| 98 | p50: crate::stats::nearest_rank(&v, 0.5)?, |
| 99 | max: v[v.len() - 1], |
| 100 | mean: round3(total as f64 / v.len() as f64), |
| 101 | total, |
| 102 | }) |
| 103 | } |
| 104 | |
| 105 | /// Per-proposal transfer-size estimate (labelled ESTIMATE in the report). |
| 106 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 107 | pub struct TransferEstimate { |
| 108 | pub label: String, |
| 109 | pub proposals: usize, |
| 110 | /// JSON-encoded `AuthenticatedRequest<SubmitChangesetPayload>` as built by this harness. |
| 111 | pub synapse_json_request_bytes: Option<ByteSummary>, |
| 112 | /// Sum of upserted file content bytes (lower bound for any encoding of the content). |
| 113 | pub raw_content_bytes: Option<ByteSummary>, |
| 114 | /// `git pack-objects --thin --stdout --revs` for `<commit> ^<base>`. |
| 115 | pub git_thin_pack_bytes: Option<ByteSummary>, |
| 116 | pub notes: Vec<String>, |
| 117 | } |
| 118 | |
| 119 | /// Cross-check between Synapse and Git answers for the same samples. |
| 120 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 121 | pub struct ParityCheck { |
| 122 | pub check: String, |
| 123 | pub compared: usize, |
| 124 | pub mismatches: usize, |
| 125 | } |
| 126 | |
| 127 | /// Result of one query cell. |
| 128 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 129 | pub struct QueryCellResult { |
| 130 | pub rep: usize, |
| 131 | pub population_changesets: usize, |
| 132 | pub samples_per_query: usize, |
| 133 | pub synapse_populate_ms: f64, |
| 134 | pub git_populate_ms: f64, |
| 135 | pub queries: Vec<QueryKindResult>, |
| 136 | pub parity: Vec<ParityCheck>, |
| 137 | pub transfer: TransferEstimate, |
| 138 | pub synapse_cached_virtual_trees_after: usize, |
| 139 | pub peak_rss_self_kib: u64, |
| 140 | } |
| 141 | |
| 142 | struct Populated { |
| 143 | proposal: Proposal, |
| 144 | changeset: ChangesetId, |
| 145 | commit: String, |
| 146 | wire_bytes: u64, |
| 147 | } |
| 148 | |
| 149 | struct SynapseClient<'a> { |
| 150 | svc: &'a mut SynapseService, |
| 151 | agent: &'a AgentIdentity, |
| 152 | repo_id: &'a RepoId, |
| 153 | counter: u64, |
| 154 | } |
| 155 | |
| 156 | struct CallTiming<R> { |
| 157 | value: R, |
| 158 | api_us: u64, |
| 159 | request_bytes: u64, |
| 160 | response_bytes: u64, |
| 161 | } |
| 162 | |
| 163 | impl SynapseClient<'_> { |
| 164 | /// Sign, wire-encode, decode, call, and wire-encode/decode the response. |
| 165 | fn call<P, R>( |
| 166 | &mut self, |
| 167 | payload: P, |
| 168 | api: impl FnOnce( |
| 169 | &mut SynapseService, |
| 170 | &synapse_auth::AuthenticatedRequest<P>, |
| 171 | u64, |
| 172 | ) -> synapse_core::SynapseResult<R>, |
| 173 | ) -> Result<CallTiming<R>, String> |
| 174 | where |
| 175 | P: Serialize + DeserializeOwned, |
| 176 | R: Serialize + DeserializeOwned, |
| 177 | { |
| 178 | self.counter += 1; |
| 179 | let now = crate::unix_now_ms(); |
| 180 | let label = format!("gate4/query/{}", self.counter); |
| 181 | let req = synapse_arm::build_read_request(self.agent, self.repo_id, payload, &label, now)?; |
| 182 | let (decoded, request_bytes) = synapse_arm::wire_roundtrip(&req)?; |
| 183 | let t = Instant::now(); |
| 184 | let resp = api(self.svc, &decoded, now).map_err(|e| e.to_string())?; |
| 185 | let api_us = t.elapsed().as_micros() as u64; |
| 186 | let (value, response_bytes) = synapse_arm::wire_roundtrip(&resp)?; |
| 187 | Ok(CallTiming { |
| 188 | value, |
| 189 | api_us, |
| 190 | request_bytes: request_bytes as u64, |
| 191 | response_bytes: response_bytes as u64, |
| 192 | }) |
| 193 | } |
| 194 | |
| 195 | /// Fetch every page of a paginated query. Returns (items, pages, api_us, req, resp bytes). |
| 196 | fn all_pages<T, P>( |
| 197 | &mut self, |
| 198 | make: impl Fn(PageRequest) -> P, |
| 199 | api: fn( |
| 200 | &mut SynapseService, |
| 201 | &synapse_auth::AuthenticatedRequest<P>, |
| 202 | u64, |
| 203 | ) -> synapse_core::SynapseResult<PageResponse<T>>, |
| 204 | ) -> Result<(usize, usize, u64, u64, u64), String> |
| 205 | where |
| 206 | P: Serialize + DeserializeOwned, |
| 207 | T: Serialize + DeserializeOwned, |
| 208 | { |
| 209 | let mut cursor: Option<String> = None; |
| 210 | let mut snapshot: Option<WalSeq> = None; |
| 211 | let (mut items, mut pages, mut api_us, mut req_b, mut resp_b) = (0usize, 0, 0, 0, 0); |
| 212 | loop { |
| 213 | let page = PageRequest { |
| 214 | cursor: cursor.clone(), |
| 215 | limit: DEFAULT_MAX_PAGE_SIZE, |
| 216 | min_visible_seq: None, |
| 217 | snapshot_seq: snapshot, |
| 218 | }; |
| 219 | let r = self.call(make(page), api)?; |
| 220 | pages += 1; |
| 221 | items += r.value.items.len(); |
| 222 | api_us += r.api_us; |
| 223 | req_b += r.request_bytes; |
| 224 | resp_b += r.response_bytes; |
| 225 | snapshot = Some(r.value.snapshot_seq); |
| 226 | match r.value.next_cursor { |
| 227 | Some(next) => cursor = Some(next), |
| 228 | None => break, |
| 229 | } |
| 230 | } |
| 231 | Ok((items, pages, api_us, req_b, resp_b)) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | fn trace(rep: usize, query: &str, sample: usize) -> QueryTrace { |
| 236 | QueryTrace { |
| 237 | rep, |
| 238 | query: query.to_string(), |
| 239 | sample, |
| 240 | latency_us: 0, |
| 241 | api_us: None, |
| 242 | request_bytes: None, |
| 243 | response_bytes: None, |
| 244 | pages: None, |
| 245 | cold: None, |
| 246 | result_items: None, |
| 247 | ok: false, |
| 248 | error: None, |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | fn summarize_kind(query: &str, system: &str, method: &str, rows: &[QueryTrace]) -> QueryKindResult { |
| 253 | let ok: Vec<&QueryTrace> = rows.iter().filter(|r| r.ok).collect(); |
| 254 | let lat: Vec<u64> = ok.iter().map(|r| r.latency_us).collect(); |
| 255 | let api: Vec<u64> = ok.iter().filter_map(|r| r.api_us).collect(); |
| 256 | let pages: Vec<usize> = ok.iter().filter_map(|r| r.pages).collect(); |
| 257 | let resp: Vec<u64> = ok.iter().filter_map(|r| r.response_bytes).collect(); |
| 258 | let cold = ok.iter().filter(|r| r.cold == Some(true)).count(); |
| 259 | QueryKindResult { |
| 260 | query: query.to_string(), |
| 261 | system: system.to_string(), |
| 262 | method: method.to_string(), |
| 263 | latency: summarize_us(&lat), |
| 264 | api_only: summarize_us(&api), |
| 265 | failures: rows.len() - ok.len(), |
| 266 | cold_samples: if system == "synapse" { |
| 267 | Some(cold) |
| 268 | } else { |
| 269 | None |
| 270 | }, |
| 271 | mean_pages: if pages.is_empty() { |
| 272 | None |
| 273 | } else { |
| 274 | Some(round3( |
| 275 | pages.iter().sum::<usize>() as f64 / pages.len() as f64, |
| 276 | )) |
| 277 | }, |
| 278 | mean_response_bytes: if resp.is_empty() { |
| 279 | None |
| 280 | } else { |
| 281 | Some(round3(resp.iter().sum::<u64>() as f64 / resp.len() as f64)) |
| 282 | }, |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | fn line_count(bytes: &[u8]) -> usize { |
| 287 | bytes |
| 288 | .split(|&b| b == b'\n') |
| 289 | .filter(|l| !l.is_empty()) |
| 290 | .count() |
| 291 | } |
| 292 | |
| 293 | /// Run one query cell. |
| 294 | pub fn run_query_cell(spec: &QuerySpec) -> Result<QueryCellResult, String> { |
| 295 | std::fs::create_dir_all(&spec.cell_dir) |
| 296 | .map_err(|e| format!("mkdir {}: {e}", spec.cell_dir.display()))?; |
| 297 | let clone = spec.clone_dir.as_path(); |
| 298 | let base = fixture::list_base_tree(clone, &spec.base_commit)?; |
| 299 | let full = fixture::load_full_base(clone, &base)?; |
| 300 | let files = fixture::editable_from_full_base(&base, &full); |
| 301 | let workload = generate_write_workload( |
| 302 | spec.seed, |
| 303 | 10_000 + spec.rep, |
| 304 | spec.agents, |
| 305 | spec.ops_per_agent, |
| 306 | &files, |
| 307 | ); |
| 308 | drop(files); |
| 309 | |
| 310 | // Populate Synapse (untimed for query purposes; recorded as populate time). |
| 311 | let ids = synapse_arm::issue_identities(spec.seed, spec.agents, crate::unix_now_ms())?; |
| 312 | let t = Instant::now(); |
| 313 | let mut svc = synapse_arm::open_service( |
| 314 | &spec.cell_dir.join("synapse-store"), |
| 315 | &ids, |
| 316 | FsyncPolicy::BatchWindow { max_records: 1024 }, |
| 317 | RecoveryPolicy::StrictFailClosed, |
| 318 | )?; |
| 319 | let base_oid: GitOid = synapse_arm::register_base(&mut svc, &spec.base_commit, full)?; |
| 320 | let mut populated: Vec<Populated> = Vec::new(); |
| 321 | for (a, props) in workload.iter().enumerate() { |
| 322 | for p in props { |
| 323 | let label = format!("gate4/query-pop/r{}/a{}/p{}", spec.rep, a, p.index); |
| 324 | let now = crate::unix_now_ms(); |
| 325 | let req = synapse_arm::build_submit_request( |
| 326 | &ids.agents[a], |
| 327 | &ids.repo_id, |
| 328 | base_oid, |
| 329 | p, |
| 330 | &label, |
| 331 | now, |
| 332 | )?; |
| 333 | let (decoded, wire) = synapse_arm::wire_roundtrip(&req)?; |
| 334 | let cs = match svc.submit(&decoded, now).map_err(|e| e.to_string())? { |
| 335 | IngestOutcome::Committed { changeset_id, .. } |
| 336 | | IngestOutcome::IdempotentDuplicate { changeset_id, .. } => changeset_id, |
| 337 | }; |
| 338 | populated.push(Populated { |
| 339 | proposal: p.clone(), |
| 340 | changeset: cs, |
| 341 | commit: String::new(), |
| 342 | wire_bytes: wire as u64, |
| 343 | }); |
| 344 | } |
| 345 | } |
| 346 | svc.store_mut().sync_wal().map_err(|e| e.to_string())?; |
| 347 | let synapse_populate_ms = round3(t.elapsed().as_secs_f64() * 1000.0); |
| 348 | |
| 349 | // Populate Git with the same proposals through the plumbing path. |
| 350 | let t = Instant::now(); |
| 351 | let plumbing = git_arm::g3_setup_agent( |
| 352 | clone, |
| 353 | &spec.base_commit, |
| 354 | &spec.cell_dir.join("plumbing"), |
| 355 | 0, |
| 356 | &[], |
| 357 | )?; |
| 358 | for pop in populated.iter_mut() { |
| 359 | pop.commit = git_arm::g3_op(clone, &spec.base_commit, &plumbing, &pop.proposal, &[])?; |
| 360 | } |
| 361 | let git_populate_ms = round3(t.elapsed().as_secs_f64() * 1000.0); |
| 362 | |
| 363 | // Transfer estimate (outside any timing). |
| 364 | let mut thin_pack = Vec::with_capacity(populated.len()); |
| 365 | for pop in &populated { |
| 366 | let out = git_ok( |
| 367 | clone, |
| 368 | &[], |
| 369 | &[], |
| 370 | &["pack-objects", "--thin", "--stdout", "--revs", "-q"], |
| 371 | Some(format!("{}\n^{}\n", pop.commit, spec.base_commit).into_bytes()), |
| 372 | )?; |
| 373 | thin_pack.push(out.len() as u64); |
| 374 | } |
| 375 | let wire: Vec<u64> = populated.iter().map(|p| p.wire_bytes).collect(); |
| 376 | let raw: Vec<u64> = populated |
| 377 | .iter() |
| 378 | .map(|p| p.proposal.content_bytes()) |
| 379 | .collect(); |
| 380 | let transfer = TransferEstimate { |
| 381 | label: "ESTIMATE".into(), |
| 382 | proposals: populated.len(), |
| 383 | synapse_json_request_bytes: byte_summary(&wire), |
| 384 | raw_content_bytes: byte_summary(&raw), |
| 385 | git_thin_pack_bytes: byte_summary(&thin_pack), |
| 386 | notes: vec![ |
| 387 | "No Synapse network protocol exists yet; the JSON request is this harness's wire approximation and serde_json encodes blob bytes as decimal arrays.".into(), |
| 388 | "The Git figure is the thin pack a receiver that already has the base commit would need; protocol negotiation overhead is excluded on both sides.".into(), |
| 389 | ], |
| 390 | }; |
| 391 | |
| 392 | // Sample selection. |
| 393 | let mut rng = SplitMix64::derive(spec.seed, &[spec.rep as u64, 0x0E_E7]); |
| 394 | let n = populated.len(); |
| 395 | let readable: Vec<(usize, String, std::sync::Arc<Vec<u8>>)> = populated |
| 396 | .iter() |
| 397 | .enumerate() |
| 398 | .flat_map(|(i, p)| { |
| 399 | p.proposal.edits.iter().filter_map(move |e| match &e.op { |
| 400 | EditOp::Upsert { content, .. } => Some((i, e.path.clone(), content.clone())), |
| 401 | EditOp::Delete => None, |
| 402 | }) |
| 403 | }) |
| 404 | .collect(); |
| 405 | if readable.is_empty() || n < 2 { |
| 406 | return Err("query population has no upserted files".into()); |
| 407 | } |
| 408 | let reads: Vec<usize> = (0..spec.samples) |
| 409 | .map(|_| rng.below(readable.len())) |
| 410 | .collect(); |
| 411 | let trees: Vec<usize> = (0..spec.samples).map(|_| rng.below(n)).collect(); |
| 412 | let diffs: Vec<usize> = (0..spec.samples).map(|_| rng.below(n)).collect(); |
| 413 | let confl: Vec<usize> = (0..spec.samples).map(|_| rng.below(n)).collect(); |
| 414 | let pairs: Vec<(usize, usize)> = (0..spec.samples) |
| 415 | .map(|_| { |
| 416 | let i = rng.below(n); |
| 417 | let mut j = rng.below(n - 1); |
| 418 | if j >= i { |
| 419 | j += 1; |
| 420 | } |
| 421 | (i, j) |
| 422 | }) |
| 423 | .collect(); |
| 424 | |
| 425 | let reader = &ids.agents[0]; |
| 426 | let mut client = SynapseClient { |
| 427 | svc: &mut svc, |
| 428 | agent: reader, |
| 429 | repo_id: &ids.repo_id, |
| 430 | counter: 0, |
| 431 | }; |
| 432 | let mut rows: Vec<QueryTrace> = Vec::new(); |
| 433 | let mut kinds: Vec<QueryKindResult> = Vec::new(); |
| 434 | let rep = spec.rep; |
| 435 | |
| 436 | // read_file (Synapse) vs cat-file --batch (persistent) vs cat-file blob (spawn). |
| 437 | let mut chunk = Vec::new(); |
| 438 | for (s, &ri) in reads.iter().enumerate() { |
| 439 | let (pi, path, expected) = &readable[ri]; |
| 440 | let cs = populated[*pi].changeset; |
| 441 | let mut t = trace(rep, "read_file/synapse", s); |
| 442 | let before = client.svc.tree_store().stats().root_builds; |
| 443 | let start = Instant::now(); |
| 444 | let r = client.call( |
| 445 | (TreeTarget::Changeset(cs), path.clone(), None), |
| 446 | |svc, req, now| svc.read_file(req, now), |
| 447 | ); |
| 448 | t.latency_us = start.elapsed().as_micros() as u64; |
| 449 | t.cold = Some(client.svc.tree_store().stats().root_builds > before); |
| 450 | match r { |
| 451 | Ok(c) if c.value.as_slice() == expected.as_slice() => { |
| 452 | t.ok = true; |
| 453 | t.api_us = Some(c.api_us); |
| 454 | t.request_bytes = Some(c.request_bytes); |
| 455 | t.response_bytes = Some(c.response_bytes); |
| 456 | t.result_items = Some(1); |
| 457 | } |
| 458 | Ok(_) => t.error = Some("read_file returned unexpected bytes".into()), |
| 459 | Err(e) => t.error = Some(e), |
| 460 | } |
| 461 | chunk.push(t); |
| 462 | } |
| 463 | kinds.push(summarize_kind( |
| 464 | "read_file", |
| 465 | "synapse", |
| 466 | "SynapseService::read_file (signed request, JSON wire round trip both ways)", |
| 467 | &chunk, |
| 468 | )); |
| 469 | rows.append(&mut chunk); |
| 470 | |
| 471 | let mut batch = CatFileBatch::spawn(clone)?; |
| 472 | for (s, &ri) in reads.iter().enumerate() { |
| 473 | let (pi, path, expected) = &readable[ri]; |
| 474 | let spec_str = format!("{}:{}", populated[*pi].commit, path); |
| 475 | let mut t = trace(rep, "read_file/git-cat-file-batch", s); |
| 476 | let start = Instant::now(); |
| 477 | let r = batch.read(&spec_str); |
| 478 | t.latency_us = start.elapsed().as_micros() as u64; |
| 479 | match r { |
| 480 | Ok(bytes) if bytes.as_slice() == expected.as_slice() => { |
| 481 | t.ok = true; |
| 482 | t.response_bytes = Some(bytes.len() as u64); |
| 483 | } |
| 484 | Ok(_) => t.error = Some("cat-file --batch returned unexpected bytes".into()), |
| 485 | Err(e) => t.error = Some(e), |
| 486 | } |
| 487 | chunk.push(t); |
| 488 | } |
| 489 | batch.finish()?; |
| 490 | kinds.push(summarize_kind( |
| 491 | "read_file", |
| 492 | "git", |
| 493 | "git cat-file --batch (one persistent process, request/response per read)", |
| 494 | &chunk, |
| 495 | )); |
| 496 | rows.append(&mut chunk); |
| 497 | |
| 498 | for (s, &ri) in reads.iter().enumerate() { |
| 499 | let (pi, path, expected) = &readable[ri]; |
| 500 | let spec_str = format!("{}:{}", populated[*pi].commit, path); |
| 501 | let mut t = trace(rep, "read_file/git-cat-file-spawn", s); |
| 502 | let start = Instant::now(); |
| 503 | let r = git_ok(clone, &[], &[], &["cat-file", "blob", &spec_str], None); |
| 504 | t.latency_us = start.elapsed().as_micros() as u64; |
| 505 | match r { |
| 506 | Ok(bytes) if bytes.as_slice() == expected.as_slice() => { |
| 507 | t.ok = true; |
| 508 | t.response_bytes = Some(bytes.len() as u64); |
| 509 | } |
| 510 | Ok(_) => t.error = Some("cat-file blob returned unexpected bytes".into()), |
| 511 | Err(e) => t.error = Some(e), |
| 512 | } |
| 513 | chunk.push(t); |
| 514 | } |
| 515 | kinds.push(summarize_kind( |
| 516 | "read_file", |
| 517 | "git", |
| 518 | "git cat-file blob <commit>:<path> (process spawn per read)", |
| 519 | &chunk, |
| 520 | )); |
| 521 | rows.append(&mut chunk); |
| 522 | |
| 523 | // tree (all pages) vs git ls-tree -r. |
| 524 | let mut syn_tree_counts = Vec::new(); |
| 525 | for (s, &i) in trees.iter().enumerate() { |
| 526 | let target = TreeTarget::Changeset(populated[i].changeset); |
| 527 | let mut t = trace(rep, "tree/synapse", s); |
| 528 | let before = client.svc.tree_store().stats().root_builds; |
| 529 | let start = Instant::now(); |
| 530 | let r = client.all_pages( |
| 531 | |page| TreeQueryPayload { |
| 532 | target, |
| 533 | path_prefix: None, |
| 534 | page, |
| 535 | }, |
| 536 | SynapseService::tree, |
| 537 | ); |
| 538 | t.latency_us = start.elapsed().as_micros() as u64; |
| 539 | t.cold = Some(client.svc.tree_store().stats().root_builds > before); |
| 540 | match r { |
| 541 | Ok((items, pages, api, rq, rs)) => { |
| 542 | t.ok = true; |
| 543 | t.result_items = Some(items); |
| 544 | t.pages = Some(pages); |
| 545 | t.api_us = Some(api); |
| 546 | t.request_bytes = Some(rq); |
| 547 | t.response_bytes = Some(rs); |
| 548 | syn_tree_counts.push(Some(items)); |
| 549 | } |
| 550 | Err(e) => { |
| 551 | t.error = Some(e); |
| 552 | syn_tree_counts.push(None); |
| 553 | } |
| 554 | } |
| 555 | chunk.push(t); |
| 556 | } |
| 557 | kinds.push(summarize_kind( |
| 558 | "tree", |
| 559 | "synapse", |
| 560 | "SynapseService::tree, every page (limit 256), signed and JSON round-tripped", |
| 561 | &chunk, |
| 562 | )); |
| 563 | rows.append(&mut chunk); |
| 564 | |
| 565 | let mut tree_mismatch = 0usize; |
| 566 | for (s, &i) in trees.iter().enumerate() { |
| 567 | let mut t = trace(rep, "tree/git-ls-tree", s); |
| 568 | let start = Instant::now(); |
| 569 | let r = git_ok( |
| 570 | clone, |
| 571 | &[], |
| 572 | &[], |
| 573 | &["ls-tree", "-r", &populated[i].commit], |
| 574 | None, |
| 575 | ); |
| 576 | t.latency_us = start.elapsed().as_micros() as u64; |
| 577 | match r { |
| 578 | Ok(out) => { |
| 579 | t.ok = true; |
| 580 | let items = line_count(&out); |
| 581 | t.result_items = Some(items); |
| 582 | t.response_bytes = Some(out.len() as u64); |
| 583 | if syn_tree_counts[s] != Some(items) { |
| 584 | tree_mismatch += 1; |
| 585 | } |
| 586 | } |
| 587 | Err(e) => t.error = Some(e), |
| 588 | } |
| 589 | chunk.push(t); |
| 590 | } |
| 591 | kinds.push(summarize_kind( |
| 592 | "tree", |
| 593 | "git", |
| 594 | "git ls-tree -r <commit> (process spawn, full output read)", |
| 595 | &chunk, |
| 596 | )); |
| 597 | rows.append(&mut chunk); |
| 598 | |
| 599 | // diff (all pages) vs git diff-tree -r --name-status. |
| 600 | let mut syn_diff_counts = Vec::new(); |
| 601 | for (s, &i) in diffs.iter().enumerate() { |
| 602 | let target = TreeTarget::Changeset(populated[i].changeset); |
| 603 | let mut t = trace(rep, "diff/synapse", s); |
| 604 | let before = client.svc.tree_store().stats().root_builds; |
| 605 | let start = Instant::now(); |
| 606 | let r = client.all_pages( |
| 607 | |page| DiffQueryPayload { |
| 608 | base: TreeTarget::BaseGitCommit(base_oid), |
| 609 | target, |
| 610 | page, |
| 611 | }, |
| 612 | SynapseService::diff, |
| 613 | ); |
| 614 | t.latency_us = start.elapsed().as_micros() as u64; |
| 615 | t.cold = Some(client.svc.tree_store().stats().root_builds > before); |
| 616 | match r { |
| 617 | Ok((items, pages, api, rq, rs)) => { |
| 618 | t.ok = true; |
| 619 | t.result_items = Some(items); |
| 620 | t.pages = Some(pages); |
| 621 | t.api_us = Some(api); |
| 622 | t.request_bytes = Some(rq); |
| 623 | t.response_bytes = Some(rs); |
| 624 | syn_diff_counts.push(Some(items)); |
| 625 | } |
| 626 | Err(e) => { |
| 627 | t.error = Some(e); |
| 628 | syn_diff_counts.push(None); |
| 629 | } |
| 630 | } |
| 631 | chunk.push(t); |
| 632 | } |
| 633 | kinds.push(summarize_kind( |
| 634 | "diff", |
| 635 | "synapse", |
| 636 | "SynapseService::diff base..changeset, every page, signed and JSON round-tripped", |
| 637 | &chunk, |
| 638 | )); |
| 639 | rows.append(&mut chunk); |
| 640 | |
| 641 | let mut diff_mismatch = 0usize; |
| 642 | for (s, &i) in diffs.iter().enumerate() { |
| 643 | let mut t = trace(rep, "diff/git-diff-tree", s); |
| 644 | let start = Instant::now(); |
| 645 | let r = git_ok( |
| 646 | clone, |
| 647 | &[], |
| 648 | &[], |
| 649 | &[ |
| 650 | "diff-tree", |
| 651 | "-r", |
| 652 | "--name-status", |
| 653 | &spec.base_commit, |
| 654 | &populated[i].commit, |
| 655 | ], |
| 656 | None, |
| 657 | ); |
| 658 | t.latency_us = start.elapsed().as_micros() as u64; |
| 659 | match r { |
| 660 | Ok(out) => { |
| 661 | t.ok = true; |
| 662 | let items = line_count(&out); |
| 663 | t.result_items = Some(items); |
| 664 | t.response_bytes = Some(out.len() as u64); |
| 665 | if syn_diff_counts[s] != Some(items) { |
| 666 | diff_mismatch += 1; |
| 667 | } |
| 668 | } |
| 669 | Err(e) => t.error = Some(e), |
| 670 | } |
| 671 | chunk.push(t); |
| 672 | } |
| 673 | kinds.push(summarize_kind( |
| 674 | "diff", |
| 675 | "git", |
| 676 | "git diff-tree -r --name-status <base> <commit> (process spawn)", |
| 677 | &chunk, |
| 678 | )); |
| 679 | rows.append(&mut chunk); |
| 680 | |
| 681 | // conflicts (Synapse, against every same-base peer) and merge-tree (Git, one pair): |
| 682 | // different work, reported separately and never as a head-to-head. |
| 683 | for (s, &i) in confl.iter().enumerate() { |
| 684 | let candidate = populated[i].changeset; |
| 685 | let mut t = trace(rep, "conflicts/synapse", s); |
| 686 | let start = Instant::now(); |
| 687 | let r = client.all_pages( |
| 688 | |page| ConflictQueryPayload { |
| 689 | candidate, |
| 690 | against: None, |
| 691 | page, |
| 692 | }, |
| 693 | SynapseService::conflicts, |
| 694 | ); |
| 695 | t.latency_us = start.elapsed().as_micros() as u64; |
| 696 | match r { |
| 697 | Ok((items, pages, api, rq, rs)) => { |
| 698 | t.ok = true; |
| 699 | t.result_items = Some(items); |
| 700 | t.pages = Some(pages); |
| 701 | t.api_us = Some(api); |
| 702 | t.request_bytes = Some(rq); |
| 703 | t.response_bytes = Some(rs); |
| 704 | } |
| 705 | Err(e) => t.error = Some(e), |
| 706 | } |
| 707 | chunk.push(t); |
| 708 | } |
| 709 | kinds.push(summarize_kind( |
| 710 | "conflicts", |
| 711 | "synapse", |
| 712 | "SynapseService::conflicts candidate vs every same-base peer in the population (path level)", |
| 713 | &chunk, |
| 714 | )); |
| 715 | rows.append(&mut chunk); |
| 716 | |
| 717 | for (s, &(i, j)) in pairs.iter().enumerate() { |
| 718 | let mut t = trace(rep, "merge-tree/git", s); |
| 719 | let start = Instant::now(); |
| 720 | let r = run_git( |
| 721 | clone, |
| 722 | &[], |
| 723 | &[], |
| 724 | &[ |
| 725 | "merge-tree", |
| 726 | "--write-tree", |
| 727 | &populated[i].commit, |
| 728 | &populated[j].commit, |
| 729 | ], |
| 730 | None, |
| 731 | ); |
| 732 | t.latency_us = start.elapsed().as_micros() as u64; |
| 733 | match r { |
| 734 | Ok(run) if matches!(run.code, Some(0) | Some(1)) => { |
| 735 | t.ok = true; |
| 736 | t.result_items = Some(usize::from(run.code == Some(1))); |
| 737 | } |
| 738 | Ok(run) => t.error = Some(format!("merge-tree exit {:?}", run.code)), |
| 739 | Err(e) => t.error = Some(e), |
| 740 | } |
| 741 | chunk.push(t); |
| 742 | } |
| 743 | kinds.push(summarize_kind( |
| 744 | "merge-tree", |
| 745 | "git", |
| 746 | "git merge-tree --write-tree <commitA> <commitB> for one pair (content-level three-way merge)", |
| 747 | &chunk, |
| 748 | )); |
| 749 | rows.append(&mut chunk); |
| 750 | |
| 751 | let cached_after = client.svc.tree_store().memoized_roots(); |
| 752 | write_jsonl(&spec.trace_path, &rows)?; |
| 753 | Ok(QueryCellResult { |
| 754 | rep, |
| 755 | population_changesets: n, |
| 756 | samples_per_query: spec.samples, |
| 757 | synapse_populate_ms, |
| 758 | git_populate_ms, |
| 759 | queries: kinds, |
| 760 | parity: vec![ |
| 761 | ParityCheck { |
| 762 | check: "tree entry count: Synapse tree == git ls-tree -r".into(), |
| 763 | compared: trees.len(), |
| 764 | mismatches: tree_mismatch, |
| 765 | }, |
| 766 | ParityCheck { |
| 767 | check: "diff entry count: Synapse diff == git diff-tree -r --name-status".into(), |
| 768 | compared: diffs.len(), |
| 769 | mismatches: diff_mismatch, |
| 770 | }, |
| 771 | ], |
| 772 | transfer, |
| 773 | synapse_cached_virtual_trees_after: cached_after, |
| 774 | peak_rss_self_kib: sample_self()?.maxrss_kib, |
| 775 | }) |
| 776 | } |