Performance
What makes MLambda.Data fast or slow, how its storage behaves, and what to watch. This page states how the system works; measure your own workload for numbers.
Structural advantages
No parsing
A request is a value (an entity, a specification, an engine message), not text. There is no lexing, parsing or planning of a query language on any request; the query planner only picks an index for filters it already has.
No serialization inside a node
Inside a node a request is a value put in an actor’s mailbox. Between nodes the actor transport writes it once as a binary document and reads it once on the other side.
| Path | Serialization |
|---|---|
| Traditional database (client → server → client) | 4 times |
| MLambda.Data, same node | none |
| MLambda.Data, another node | once each way |
One message at a time
Each actor owns its state and handles one message at a time, so there are no locks, no lock contention and no deadlocks from locks. Actors are fibers on the runtime’s scheduler: a fiber waiting on an answer is parked while the others run.
Native code
The database compiles to one native executable: no virtual machine, no JIT warm-up, no runtime to start.
Storage
Writes
- The write is appended to the log and synced. The sync dominates a write’s latency; use SSDs.
- Writes that arrive together share one sync (group commit: 64 rows, or 2 ms after the first), so concurrent writers cost about one sync each batch, and a lone writer waits at most 2 ms more.
- The write goes into the memtable and the table’s indexes.
Reads
- The memtable.
- Each SSTable, newest first, skipped when its bloom block rules the key out.
- The newest item wins.
Write amplification
Each row is written to the log, then to an SSTable when the memtable flushes, then again each time compaction merges its tier. Size-tiered compaction (tables of about the same size merged together) keeps write amplification low, at the cost of more SSTables for a read to consult between compactions; bloom blocks keep most of those consultations in memory.
Indexes
| Index | Lookup | Range | Insert | Use it for |
|---|---|---|---|---|
| Hash | O(1) | — | O(1) | Equality (an email, an id) |
| B-tree | O(log n) | O(log n + k) | O(log n) | Ranges, prefixes, ordering |
| Bloom | O(probes) | — | O(probes) | Skipping SSTables that cannot hold a key |
| Inverted | O(1) a word | — | O(words) | Full-text search |
Bloom blocks use about 10 bits a key and 7 probes, for about 1% false positives.
Every index costs each write an update: index the columns your queries filter on, and no others. A query whose filters no index fits is a scan of the table.
Compaction
Compaction merges SSTables in the background. Management.CompactionBreaker paces it by the disk’s load:
Closed full speed; throttled past half the disk's I/O
→ I/O at 80%, or the fastest of the last eight log syncs past 50 ms → Open: compaction pauses
Open → after a minute → Half open: one probe
Half open → a probe under 70% of both limits → Closed; anything else → Open
A merge runs on a background thread, streaming its inputs a block at a time; at most two run at once in a process.
So compaction never competes with foreground writes on a busy disk.
Memory
The memtable
A table’s memtable is flushed to an SSTable past 4 MiB: the engine’s flushAt parameter
(actorOf system (parameters [("root", root), ("flushAt", "16777216")])), passed to every table’s store. A larger memtable means
fewer flushes and SSTables, but a longer log to replay after a crash; snapshots shorten that replay.
Consistency and latency
| Level | Writes wait for | Reads wait for | Guarantee |
|---|---|---|---|
One |
1 replica | 1 replica | Eventual: a read may miss the latest write |
Quorum (Fast) |
a majority, one round | a majority | Last write wins by the coordinator’s clock |
Linearizable |
a majority, two rounds | a majority, two when copies differ | Linearizable per key |
All |
every replica | every replica | Last write wins; one slow replica slows every request |
Linearizable is the default of the ORM, batches and the REST API: a write costs two round trips to a majority.
Measuring your workload
- Run your scenario in the Docker topology you deploy (
compose.cluster.yml…), not only standalone. - Time with
System.Time.monoMillisaround the calls you care about; look at the slowest requests, not the average. - Watch the live channels:
/ws/metrics,/ws/compaction,/ws/ring.
What to watch
- Tail latency of writes: high means the disk’s sync is slow.
- Flush frequency: very frequent means the memtable is too small for the write rate.
- Compaction backlog: SSTables accumulating faster than compaction merges them slow reads.
- Ring skew: a node holding far more than its share of keys is a hot spot.
Anti-patterns
| Anti-pattern | Impact | Fix |
|---|---|---|
| Spinning disks | Every write waits for a slow sync | SSDs |
All for every request |
One slow replica blocks every request | Quorum unless All is required |
| Very large values (over 1 MB) | The memtable fills quickly; large log entries | Keep large values in their own table |
| Indexes nobody queries | Every write pays for them | Index only filtered columns |
| Filters no index fits, on large tables | Full scans | Add a B-tree or hash index on the filtered column |