ITZMA is still taking shape, and its API can change between releases. Version 0.2.1: serde_with security fix
Docs / User guide

Caching and read budgets

A RAM and NVMe read cache, a cache of decoded structures, a byte budget on every read, and thread pools.

On this page

Read cache

The read cache wraps any store with a RAM tier and an optional NVMe tier, keyed by object and byte range. Only queries read through it. The manifest is never cached, so a query always sees the latest writes. Objects are immutable once written, so there is no invalidation, only eviction.

app.state.ns = await itzma.AsyncNamespace.open(
    store, "docs", cache=itzma.Cache(ram_bytes=2 << 30)
)
let cache = CacheStore::new(store, CacheOptions::default()).unwrap();
let ns = ns.with_cache(Arc::new(cache));

In Python, itzma.Cache(ram_bytes=..., nvme_dir=..., nvme_bytes=...) keeps segment and index bytes in RAM and optionally on a local disk. In Rust it is CacheStore, given to a handle with Namespace::with_cache.

Decoded cache

DecodedCache keeps parsed structures (segment directories, blocks, index heads and partitions, whole small segments) so a warm query skips decoding. Share one between handles with with_decoded_cache. Default 256 MiB.

rust
let cache = DecodedCache::new(DecodedCacheOptions::default());
let ns = Namespace::create(Arc::new(InMemory::new()), "docs", Schema::new(4, Metric::L2))
    .await?
    .with_decoded_cache(cache);

Fetch policy

A query reads parts of objects: some rows of a segment, a few index partitions. The fetch policy decides how those wanted byte ranges become requests. Ranges close together are merged into one request, a long merged range is split into parts fetched in parallel, and ranges are rounded out so nearby reads from different queries land on the same cache keys.

There are two presets:

PresetForWhat it does
object_store()S3 and other object storesThe default. Merges across gaps of 64 KiB to 4 MiB, splits above 16 MiB into 8 MiB parts, aligns to 64 KiB.
local()in-memory and local diskMerges across gaps of 8 to 64 KiB, never splits, no alignment, since a request costs about as much as its bytes.

In Python, pass fetch=itzma.FetchPolicy.local() to Namespace.create or open for a memory:// or file:// store; without it a handle uses object_store(). In Rust it is Namespace::with_fetch_policy(FetchPolicy::local()). The six fields (min_gap, max_gap, gap_divisor, split_above, part_size, align) can be set by hand. Only object_store()’s 64 KiB min_gap has been measured; its other numbers are starting points.

Read budget

Every query attempt, and each unit of a compaction, may read at most a byte budget: 1 GiB by default (DEFAULT_READ_BUDGET), or what read_budget= in Python or Namespace::with_read_budget in Rust sets. Past it the call fails with ReadBudgetExceeded before anything is written.

An indexed segment is charged only for what it fetches, so a namespace bigger than the budget can still be queried once its large segments are indexed. A query without an index, or with exact, reads every live vector of the unindexed segments, bounded by the budget.

Threads

CPU work runs on two thread pools: queries on every core, maintenance on a quarter of them. Size them once, before the first call that uses them: configure_cpu in Rust, itzma.configure(cpu_threads=n, maintenance_cpu_threads=m) in Python. In Python, itzma.configure(worker_threads=n) also sets the runtime’s thread count; call it before anything else.

Docs
esc

Loading the docs…