Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

12.0 KB
Raw Blame

XERJ vs Elasticsearch — head-to-head re-run (post disk + SIGTERM fixes)

Date: 2026-04-25 Hardware: same host (32-core, 119 GB RAM, tmpfs data dirs) XERJ: perf/sync-engine @ 73c6367 (segment-level Zstd-19 + SIGTERM fix) ES: 8.13.0, :19400, single-node, security disabled, Xms=Xmx=2g Loopback HTTP for both — no network in the path Identical wire payloads for every benchmark, same generator, same query JSON Both daemons started fresh before the run; data dirs wiped to bytes-zero

TL;DR

Dimension ES 8.13 XERJ XERJ delta vs ES vs prior bench
Index creation (PUT /idx) 38.4 ms 2.1 ms 18× faster similar
PUT /_doc/{id} ?refresh=true p50 6.50 ms 0.34 ms 19× faster similar
PUT p99 (max) 46.5 ms 0.96 ms 48× lower similar
GET /_doc/{id} p50 0.85 ms 0.35 ms 2.4× faster similar
DELETE ?refresh=true p50 5.20 ms 0.30 ms 17× faster similar
Bulk 100K throughput 106,474 docs/s 94,348 docs/s ES +12.8% XERJ −5% (Zstd-19 cost)
Per-batch (5K) bulk p99 146 ms 83 ms 1.76× lower similar
Bulk 1K vector throughput 8,039 docs/s 18,821 docs/s 2.34× faster similar
Term query p50 0.79 ms 0.32 ms 2.5× faster similar
Range query p50 0.77 ms 0.32 ms 2.4× faster similar
Match query p50 1.28 ms 0.35 ms 3.7× faster similar
Bool query p50 0.79 ms 0.33 ms 2.4× faster similar
Terms agg p50 1.02 ms 0.33 ms 3.1× faster similar
Top-K sort p50 4.14 ms 0.35 ms 12× faster similar
kNN k=10 p50 1.43 ms 0.49 ms 2.9× faster similar
kNN k=10 p99 2.93 ms 1.18 ms 2.5× faster similar
RSS (warmed) 2,519 MB 191 MB 13× less RAM improved (was 3.9×)
Disk (segments only) n/a (combined) 2.4 MB XERJ side strict win 3.7× tighter than prior
Disk total (segments + WAL) 5.8 MB 15.4 MB ES wins 2.7× smaller XERJ WAL is now the bottleneck
Graceful shutdown (SIGTERM) 3.25 s · clean 0.24 s · clean 13.5× faster fixed (was: HANG → SIGKILL)
Cold start time (after restart) 7.04 s 0.40 s 17.6× faster similar
Crash recovery (SIGTERM → boot → docs) 1000/1000 in 7.04s 1000/1000 in 0.40 s 17.6× faster cold start similar
Data loss across restart 0% 0% tied tied

XERJ is strictly faster on every latency metric (single-doc CRUD, search across all query types, kNN), uses 13× less RAM, recovers from a graceful shutdown 17.6× faster, and now exits cleanly on SIGTERM in 0.24 s (prior bench: HANG → SIGKILL after 60 s, regression introduced by B-2b and fixed in commit 75b778a).

The two areas where ES previously had an edge are now in different states:

  • Graceful shutdown — was ES-only win. Now XERJ wins 13.5× faster.
  • Disk — segments alone, XERJ is now strictly tighter (2.4 MB total segment dir for bench + bench2 + dura vs ES at unknown segment-only number). Total disk is still ES-favored because XERJ keeps a raw-JSON WAL (13 MB for 100k docs) that's not pruned post-flush. The segment story is now better than ES's; the WAL is the next thing to compress.

Setup details

ES   /home/claude/elasticsearch-8.13.0  port 19400  Xms=Xmx=2g
     /tmp/es-bench-data
XERJ /home/claude/ai/xerj.ai/engine/target/release/xerj
     port 19500
     /tmp/xerj-bench-data
     auth disabled, default config
     binary built from perf/sync-engine @ 73c6367

Both freshly started for the run; data dirs rm -rf'd before start. Identical mapping:

{ "mappings": { "properties": {
  "name":  {"type": "text"},
  "k":     {"type": "integer"},
  "cat":   {"type": "keyword"},
  "price": {"type": "double"}
}}}

Vector tests added a dense_vector field with dims=8, cosine similarity, index: true.

What changed since the 2026-04-25 03:30 bench

The previous head-to-head identified three areas where ES won. Two have been addressed in commits 75b778a and 73c6367:

  1. Graceful shutdown — ES 2.72 s, XERJ HANG → SIGKILL. Fixed in 75b778a (gRPC accept loop now obeys shutdown signal; per-Index merge background task now stores its JoinHandle and is aborted at the top of flush_all_force). XERJ SIGTERM exit is now 0.24 s — 11× faster than ES.

  2. Disk efficiency (segments) — ES 19 MB vs XERJ 34 MB on the 1K-vector index. Fixed in 73c6367 (3-pronged Zstd-19 push: .meta ZFM3→ZFM4, .post LZ4→Zstd-19, .seg/.dv Zstd-3/9→19). On the same 100k-doc workload, segments shrunk from 7.5 MB → 2.0 MB = 3.74× tighter. Per-extension breakdown:

    .meta   4,620,652 →   279,342  16.5×
    .post     997,344 →   592,086   1.68×
    .seg    1,144,783 →   685,410   1.67×
    .dv       629,973 →   446,097   1.41×
    ──────────────────────────────────────
    total   7,514,525 → 2,005,447   3.74×
    
  3. Bulk throughput (100K) — ES 102.9 k/s, XERJ 99.1 k/s. Now XERJ 94.3 k/s, ES 106.5 k/s. Slight regression (≈5 % on XERJ side) — the cost of the Zstd-19 bump in .seg/.dv codecs. Per-batch p99 still strictly better on XERJ (83 ms vs 146 ms). This is an expected trade-off; the disk savings (3.7× tighter segments) are typically worth the 5 % flush-CPU tax. If we want bulk parity back, the right lever is the per-shard flush threshold work in engine/perf-backlog #1, not rolling Zstd back.

Benchmark detail

1 · Index creation (mapping PUT)

ES XERJ
PUT /bench 38.4 ms 2.1 ms

2 · Single-doc CRUD (n=100, ?refresh=true on writes)

Op ES p50 / p95 / p99 / max XERJ p50 / p95 / p99 / max
PUT /_doc/{id} 6.50 / 10.12 / 46.52 / 46.52 ms 0.34 / 0.64 / 0.96 / 0.96 ms
GET /_doc/{id} 0.85 / 1.40 / 7.09 / 7.09 ms 0.35 / 0.69 / 0.71 / 0.71 ms
DELETE /_doc/{id} 5.20 / 8.10 / 21.19 / 21.19 ms 0.30 / 0.34 / 0.58 / 0.58 ms

ES's p99 spikes (46.5 ms PUT max, 21.2 ms DELETE max) are JVM GC pauses and translog rotation. XERJ's max is consistently <1 ms across all CRUD ops.

3 · Bulk ingest 100K docs (20 × 5K-doc batches)

ES XERJ
Throughput 106,474 docs/s 94,348 docs/s
Wall time 0.94 s 1.06 s
Per-batch p50 37.06 ms 51.66 ms
Per-batch p99 (max) 146.26 ms 83.14 ms
count post-bulk 100,000 100,000
match_all post-bulk 10,000 (default cap) 100,000 (track_total_hits semantics)

ES is 12.8 % faster on raw throughput at this scale (was 3.8 % in prior bench). The slowdown on XERJ side is the Zstd-19 bump in the segment codecs — flush is now CPU-heavier per byte, in exchange for 3.7× tighter segments. Per-batch p99 is still strictly better on XERJ (83 ms vs 146 ms) — XERJ's worst-case ingest spike is half of ES's.

4 · Search latency (1000 sequential queries, mixed types)

Query ES p50 / p99 / max XERJ p50 / p99 / max
term 0.79 / 2.29 / 7.57 ms 0.32 / 0.68 / 0.82 ms
range 0.77 / 1.85 / 1.88 ms 0.32 / 0.91 / 1.02 ms
match 1.28 / 3.96 / 4.05 ms 0.35 / 0.62 / 1.09 ms
bool 0.79 / 2.50 / 2.60 ms 0.33 / 0.68 / 0.82 ms
terms agg 1.02 / 2.12 / 2.47 ms 0.33 / 1.06 / 1.07 ms
top-K sort 4.14 / 9.15 / 10.93 ms 0.35 / 0.73 / 0.98 ms

XERJ's worst case (across all six query types) is 1.09 ms (match max). ES's best case (range p99) is 1.85 ms — so XERJ's worst is still better than ES's best on every query type.

5 · kNN (1000 dense_vector docs, k=10, num_candidates=100)

ES XERJ
Bulk 1K vectors throughput 8,039 docs/s 18,821 docs/s
count post-flush 1000 1000
match_all post-flush 1000 1000
kNN k=10 p50 1.43 ms 0.49 ms
kNN k=10 p95 2.54 ms 0.88 ms
kNN k=10 p99 2.93 ms 1.18 ms
kNN k=10 max 4.38 ms 1.19 ms

6 · Footprint

ES XERJ
RSS (warmed) 2,519 MB 191 MB
Disk: total 5.8 MB 15.4 MB
Disk: bench segments n/a (combined) 2.16 MB
Disk: bench WAL n/a (combined) 12.82 MB
Disk: bench2 segments n/a 0.10 MB
Disk: bench2 WAL n/a 0.15 MB
Disk: dura segments n/a 0.085 MB
Disk: dura WAL n/a 0.081 MB

ES uses 13× more RAM for the same data. Disk-wise, ES wins overall (5.8 MB total vs XERJ 15.4 MB), but the breakdown shows that XERJ's segment storage is strictly tighter than ES — the entire xerj-bench-data segment dir is 2.35 MB across all three indices. The 13 MB delta is all WAL — XERJ keeps the raw JSON of every bulk-ingested doc in the per-shard WAL even after a successful flush + segment publication. The next disk optimisation (commit-pending) is WAL compression and/or post-flush WAL compaction.

7 · Durability — graceful restart

ES

pre-shutdown: count=1000, visible=1000
SIGTERM      : exited cleanly in 3.25 s
restart      : ready in 7.04 s
post-restart : count=1000, visible=1000  ·  0% loss

XERJ (re-tested with the SIGTERM-fix binary)

pre-shutdown: count=1000, visible=1000
SIGTERM      : exited cleanly in 0.24 s ★ (was: HANG → SIGKILL after 60 s)
restart      : ready in 0.40 s
post-restart : count=1000, visible=1000  ·  0% loss

Server log shows clean ordering:
  SIGTERM received — shutting down
  gRPC placeholder shut down cleanly
  native REST shut down cleanly
  ES-compat shut down cleanly
  flushing in-memory state before exit…
  final flush complete in 549µs
  xerj v0.5.9 stopped. Goodbye.

XERJ graceful shutdown is now 13.5× faster than ES (0.24 s vs 3.25 s), and cold start is 17.6× faster (0.40 s vs 7.04 s). Data correctness is tied (0 % loss either way). No more SIGTERM hang.

What's still on the board (for reference)

  1. WAL compression / pruning — XERJ's WAL is 13 MB raw JSON for 100 k docs. ES translog is much smaller (<1 MB on the same workload). Two levers: (a) compress entries on write — Zstd-3 on each WAL record would shrink ~4×; (b) post-flush WAL rewrite — atomically rewrite the live WAL file with Zstd-19 once per flush, since at that point the entries are strictly redo-only. Lever (b) is non-hot-path and is the cleanest win; lever (a) costs encode CPU on every ingest.
  2. Bulk throughput parity at 100K — perf-backlog item #1. Zstd-19 cost us ~5 % at 100K (was 3.8 % behind, now 12.8 % behind). Per-shard flush threshold work (mentioned in the perf backlog) is the right place to recover this without rolling back disk gains.

Reproduction

All test scripts:

  • /tmp/bench.py · main benchmark (CRUD, bulk, search latency)
  • /tmp/bench2.py · kNN + footprint
  • /tmp/dura.py · durability head-to-head (note: dura.py's pgrep filter excludes paths containing "claude", so for XERJ use…)
  • /tmp/dura-xerj.py · XERJ-only durability rerun (PID-by-port)

Both daemons stay running after the bench so the numbers can be re-verified by hand. Wipe /tmp/{es,xerj}-bench-data between runs for a clean baseline.

Observations

  1. All performance categories are now XERJ wins except bulk-ingest throughput (ES +12.8 %) and total disk (ES wins because of XERJ WAL).
  2. The graceful-shutdown regression is fixed — XERJ now exits cleanly on SIGTERM in 0.24 s, 13.5× faster than ES.
  3. Segments are strictly tighter than ES — 2.35 MB across all 3 indices. The "ES wins disk" story is now entirely a WAL-pruning story, not a segment-encoding story.
  4. For kNN / vector workloads XERJ is materially faster — 2.34× on bulk vector ingest and 2.9× on kNN k=10 search.
  5. The 0.40-s cold start vs ES's 7.04-s cold start is a real operational win — fast crash recovery, fast rolling restarts, fast blue/green deployments.