From 9498dd1a5d891612dc14a12ad30c8d073a7a09b1 Mon Sep 17 00:00:00 2001 From: Shaun Patterson Date: Sat, 21 Nov 2026 11:46:15 -0500 Subject: [PATCH] docs(#431): many small graph batches pay a fixed cost; say which arguments lower it --- .../modules/ROOT/pages/how-to/bulk-loads.adoc | 42 +++++++++++++++++++ src/arcadedb/core.py | 7 +++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/docs/modules/ROOT/pages/how-to/bulk-loads.adoc b/docs/modules/ROOT/pages/how-to/bulk-loads.adoc index 099184fc..9eb648b8 100644 --- a/docs/modules/ROOT/pages/how-to/bulk-loads.adoc +++ b/docs/modules/ROOT/pages/how-to/bulk-loads.adoc @@ -281,6 +281,48 @@ The engine-level Java run, repeated on the merge of the fix, kept the batch's ed From 26.11.1 on, `graph_batch()` is fine for a workload that deletes and inserts again. On an engine older than 26.11.1, write the edges with SQL (`CREATE EDGE`) or with `Vertex.new_edge` inside `db.transaction()` instead. Both stayed flat in the measurement (0.25 MiB in the table). +[[many-small-batches]] +== Many small graph batches + +A `graph_batch()` has a fixed cost that does not depend on how many edges it gets: with the default arguments the engine sizes its buffers and its head-chunk caches for a large load when the batch is created. A load that opens one batch for a few edges, such as a writer that stores the relationships of each request, pays that cost every time. + +The measurement is a laptop A/B, macOS arm64, Python 3.12, one `with db.graph_batch(...)` block with one `new_edge` call, 1,000 blocks after 200 warm-up blocks. The allocation is the JVM's, read with `ThreadMXBean.getThreadAllocatedBytes`, and applies to `arcadedb-jvm` only. + +[cols="3,1,1,1"] +|=== +| Arguments | `arcadedb` (native), time | `arcadedb-jvm`, time | `arcadedb-jvm`, allocated + +| default +| about 2.5 ms +| about 2.2 ms +| about 41 MiB + +| `chunk_cache_capacity=1000` +| +| +| about 8.6 MiB + +| `batch_size=100` +| +| +| about 33 MiB + +| `batch_size=100, chunk_cache_capacity=1000` +| about 0.22 ms +| about 0.25 ms +| about 0.6 MiB +|=== + +When you write small batches, pass a `batch_size` near the number of edges a batch holds and a `chunk_cache_capacity` near the number of vertices it touches: + +[source,python] +---- +with db.graph_batch(batch_size=100, chunk_cache_capacity=1_000) as batch: + batch.new_edge(alice, "Knows", bob) +---- + +Both arguments are bounds, not allocations you must reach: a batch that holds more edges than `batch_size` flushes early, and a cache that fills evicts entries and reloads them from the database on a miss. Leave them at their defaults for a bulk load of many edges in one batch. The numbers are one machine and single runs, so read them as an order of magnitude. + == If a graph batch is interrupted This section is about a `graph_batch()` load that stops before `close()` returns, for example when the process is killed (`kill -9`, the out-of-memory killer, power loss). An exception inside a `with db.graph_batch() as batch:` block still runs `close()`. The numbers below come from a kill probe on the `arcadedb` (native) package: `kill -9` in the middle of the edge phase, the default `commit_every=1000`, with and without `use_wal=True`. In the 40 kills of the probe, no committed vertex or edge chunk was lost, no record was torn, no edge pointed at a missing vertex, and every database reopened and accepted writes. The example below is one of these kills: 30,000 vertices and 70,000 edge records were in the database afterwards. diff --git a/src/arcadedb/core.py b/src/arcadedb/core.py index 29ef6574..c5b8ed84 100644 --- a/src/arcadedb/core.py +++ b/src/arcadedb/core.py @@ -2228,7 +2228,8 @@ def graph_batch( docs/modules/ROOT/pages/how-to/bulk-loads.adoc. Args: - batch_size: Maximum buffered edges before auto-flush. + batch_size: Maximum buffered edges before auto-flush. The engine sizes its buffers for it when the batch is created, so a + batch that holds a few edges should pass a small value (see ``chunk_cache_capacity``). expected_edge_count: Hint for auto-tuning batch size when not set. edge_list_initial_size: Initial edge-segment size in bytes. light_edges: Create property-less edges as light edges when True. From engine @@ -2262,7 +2263,9 @@ def graph_batch( just reloads the vertex's head chunk from disk; bounding them keeps memory flat on a long-lived stream instead of growing with the number of distinct vertices touched. Default 1,000,000 (roughly 100-150 MB - per cache). + per cache). The engine also sizes the caches for it when the batch is created: a + batch of one edge allocated about 41 MiB and took about 2 ms with the defaults, and about 0.6 MiB and + 0.2 ms with ``batch_size=100, chunk_cache_capacity=1000``. Pass small values for many small batches. max_deferred_incoming_edges: Buffered deferred incoming edges allowed before the incoming-edge connection pass runs early from `flush()` rather than once at `close()`, amortizing it over the load. Default