Repository navigation
Description
Context
My benchmark's documents transactions table (https://humem.ai/projects/arcadedb/next, ArcadeDB measured at 417314c18) runs a TPC-C-style new-order from Python: begin, a SELECT by a unique key, an INSERT, an UPDATE by the same key, commit. ArcadeDB embedded takes 0.45 ms per new-order there, where SQLite takes 0.012 ms and PostgreSQL over the network 0.09 ms. Before asking I checked my own side first, on a laptop with engine 7effa0950e: the transaction takes 0.37-0.40 ms through my Python binding and 0.27 ms in pure Java, so the binding adds about 0.1 ms and the rest is the engine. Of the engine's 0.27 ms, 70% is commit(), at txWalFlush=0, for a transaction that changes two records. This issue is the attribution of that commit time, in case any of it is avoidable.
Setup
Engine 7effa0950e (the published 26.10.1-SNAPSHOT image of 2026-09-25; LocalBucket, CachedPage, PageManager, TransactionContext, and TransactionIndexContext are unchanged on main at ff4e96b9ef). Temurin 25 with compact object headers, 4 cores (--cpuset-cpus 0-3), -Xms4g -Xmx4g, -Darcadedb.txWalFlush=0, database on ext4. Part: 200,000 documents (TPC-H SF1), UNIQUE index on p_partkey, loaded in 10,000-record transactions. OrderNew: UNIQUE index on okey. 5,000 warm-up transactions, then 20,000 to 100,000 timed. Laptop (Intel Core Ultra X9 388H), so read the shares rather than the absolute numbers; every split below was repeated three times and agreed within 2%.
Where a new-order's time goes (p50, pure Java)
| step | p50 |
|---|---|
begin() |
0.000 ms |
SELECT p_retailprice, stock FROM Part WHERE p_partkey=:k |
0.019 ms |
INSERT INTO OrderNew SET okey=:o, pkey=:p, qty=1, paid=0 |
0.017 ms |
UPDATE Part SET stock = stock - 1 WHERE p_partkey=:k |
0.038 ms |
commit() |
0.19 ms |
| whole transaction | 0.27 ms |
The statements are flat from 5,000 to 105,000 orders (checked in windows of 10,000), so nothing grows with the table. Through the record API instead of SQL (lookupByKey, newDocument().save(), modify().save()) the transaction is 0.23 ms: the SQL layer is about 15%.
Where commit's time goes
Measured with an instrumented copy of TransactionContext (cumulative System.nanoTime() around each step, diff below), mean per commit over 50,000 commits, three runs:
| commit step | mean | share |
|---|---|---|
commit1stPhase: bucket.compressPage(page, false) over the modified and new bucket pages |
0.067 ms | 31% |
publishCommittedPages: PageManager.publishPages |
0.054 ms | 25% |
commit1stPhase: indexChanges.commit() |
0.045 ms | 21% |
concludePhase2 (reset() and callbacks) |
0.016 ms | 7% |
writeTransactionToWAL (no fsync at txWalFlush=0) |
0.012 ms | 5% |
finishCommitBookkeeping |
0.009 ms | 4% |
commit1stPhase: file locks and updated records |
0.009 ms | 4% |
commit1stPhase: modified ranges, rebase, WAL buffer |
0.0025 ms | 1% |
validateAndBumpVersions |
0.001 ms | 0% |
A JFR CPU profile of the same run agrees: the top frames under commit are CachedPage.<init>, HashMap$HashIterator.nextNode (from finishCommitBookkeeping), PageManager.putPageInReadCache, HashMap.clear (from TransactionContext.reset), LocalBucket.computePageHoles, and LocalBucket.compressPageInternal.
1. compressPage runs on every modified bucket page at every commit (31%). compressPageInternal walks every record slot of the page (getOrderedRecordsInPage allocates an int[] per record and a list sized DEF_MAX_RECORDS_IN_PAGE), computes the holes, and defragments. A 64 KB Part page holds hundreds of small records, and this transaction only overwrote a fixed-size LONG on one of them and appended one record to another page, so there are no holes to remove. The call has been in commit1stPhase since #1539 (bcaad22c02, February 2025, "Delete reuse space").
2. publishPages deep-copies every modified page's whole backing array into the read cache (most of the 25%). CachedPage(page, true) does Arrays.copyOf(srcArray, srcArray.length), the copy added for #3714 (eb218dbcfa) so the cached page does not share an array with the flush queue. Bucket pages are 64 KB and LSMTreeIndex pages 256 KB, so this commit copies several hundred KB to change two small records. As an upper bound only, a CachedPage that shares the array instead (unsafe, measurement only) takes commit from 0.200 ms to 0.158 ms.
3. Reused maps keep their capacity (small). modifiedRecordsCache, immutableRecordsCache, and immutablePages are final fields cleared with clear(), which, like iteration, costs in proportion to capacity. Loading Part in 100-record transactions instead of 10,000-record ones makes the later small commits about 10% cheaper (0.195 ms to 0.175-0.180 ms).
Questions
- Does a commit need
compressPageon a page when the transaction did not delete a record on it or shrink one? If the page could carry a "may have holes" flag set only by those operations, most OLTP commits would skip the walk. - Is there a way to publish to the read cache without copying the whole page, for example copying lazily, sharing the array once the flush thread is done with it, or letting the flush thread write from the cached copy?
- Would shrinking (or replacing) the transaction's maps after an unusually large transaction be welcome, or is the 10% not worth it?
I am happy to test any change against the same repro. The 0.1 ms my Python binding adds on top is mine, and I am working on that part separately.
NewOrderBench.java and run.sh
import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.database.Document;
import com.arcadedb.index.IndexCursor;
import com.arcadedb.database.MutableDocument;
import com.arcadedb.query.sql.executor.ResultSet;
import java.io.File;
import java.util.Arrays;
import java.util.Map;
import java.util.Random;
/**
* The documents lane's new-order transaction, in-process on the engine, two ways:
* sql - the lane's statements: SELECT Part by key, INSERT OrderNew, UPDATE Part by key, each with a
* parameter map, between begin() and commit();
* api - the same effect through the record API: lookupByKey, newDocument().save(), modify().save().
* Part has 200,000 records (TPC-H SF1) with a UNIQUE index on p_partkey; OrderNew a UNIQUE index on okey.
* Prints p50/p99 per transaction after a warm-up. Usage: java NewOrderBench <dir> <ops>
*/
public class NewOrderBench {
public static void main(final String[] args) {
final String dir = args[0];
final int ops = Integer.parseInt(args[1]);
if (args.length > 2 && args[2].equals("phases-only")) {
LOAD_BATCH = args.length > 3 ? Integer.parseInt(args[3]) : 10_000;
PRESCAN = args.length > 4 && args[4].equals("1");
run(dir + "/phases", "phases", ops);
return;
}
for (final String mode : new String[] { "sql", "api", "sql", "api" })
run(dir + "/" + mode, mode, ops);
run(dir + "/phases", "phases", ops);
}
static int LOAD_BATCH = 10_000;
static boolean WINDOWS = Boolean.getBoolean("bench.windows");
static boolean PRESCAN = false;
static void run(final String path, final String mode, final int ops) {
deleteTree(new File(path));
try (final DatabaseFactory f = new DatabaseFactory(path); final Database db = f.create()) {
db.command("sql", "CREATE DOCUMENT TYPE Part");
db.command("sql", "CREATE PROPERTY Part.p_partkey LONG");
db.command("sql", "CREATE INDEX ON Part (p_partkey) UNIQUE");
db.command("sql", "CREATE DOCUMENT TYPE OrderNew");
db.command("sql", "CREATE PROPERTY OrderNew.okey LONG");
db.command("sql", "CREATE INDEX ON OrderNew (okey) UNIQUE");
final int parts = 200_000;
db.begin();
for (int k = 0; k < parts; k++) {
db.newDocument("Part").set("p_partkey", (long) k).set("p_retailprice", 900.0 + k % 1000).set("stock", 100L).save();
if ((k + 1) % LOAD_BATCH == 0) { db.commit(); db.begin(); }
}
db.commit();
if (PRESCAN) {
// one read-only transaction over every Part, as a report or a scan inside a transaction would do
db.begin();
try (final ResultSet rs = db.query("sql", "SELECT p_partkey, stock FROM Part")) {
while (rs.hasNext())
rs.next();
}
db.commit();
}
if (mode.equals("phases"))
System.out.printf("RESULT setup: Part loaded in %,d-record transactions%s%n", LOAD_BATCH,
PRESCAN ? ", then one transaction reading all 200,000" : "");
final Random rnd = new Random(11);
final int warm = 5_000;
if (mode.equals("phases"))
PHASES = new long[5][ops];
long[] prof = null;
try {
prof = (long[]) Class.forName("com.arcadedb.database.TransactionContext").getField("PROF").get(null);
} catch (final Exception ignored) {
// the stock class has no timers
}
final long[] ns = new long[ops];
for (int i = 0; i < warm + ops; i++) {
final long pkey = rnd.nextInt(parts);
final long t0 = System.nanoTime();
if (mode.equals("sql"))
sqlNewOrder(db, i, pkey);
else if (mode.equals("api"))
apiNewOrder(db, i, pkey);
else
phasedNewOrder(db, i, pkey, i >= warm ? i - warm : -1);
if (i >= warm)
ns[i - warm] = System.nanoTime() - t0;
if (i == warm - 1 && prof != null)
Arrays.fill(prof, 0);
}
if (prof != null && prof[7] > 0) {
final String[] names = { "phase 1 (commit1stPhase)", "publishCommittedPages", "finishCommitBookkeeping",
"concludePhase2 (reset)", " of which validateAndBumpVersions", " of which writeTransactionToWAL",
" of which publishPages", null, " p1: locks + updated records", " p1: indexChanges.commit()",
" p1: compressPage (buckets)", " p1: ranges, rebase, WAL buffer" };
for (int p = 0; p < names.length && p < prof.length; p++)
if (names[p] != null)
System.out.printf("RESULT step %-36s mean %.4f ms%n", names[p], prof[p] / 1e6 / prof[7]);
}
if (mode.equals("phases") && WINDOWS) {
// the per-phase p50 in windows of 10,000 transactions: does a statement get slower as OrderNew grows?
final String[] wn = { "begin", "SELECT", "INSERT", "UPDATE", "commit" };
for (int w = 0; w + 10_000 <= ops; w += 10_000) {
final StringBuilder sb = new StringBuilder(String.format("RESULT window orders %,7d-%,7d", warm + w, warm + w + 10_000));
for (int p = 1; p < 5; p++) {
final long[] win = Arrays.copyOfRange(PHASES[p], w, w + 10_000);
Arrays.sort(win);
sb.append(String.format(" %s %.3f", wn[p], win[5_000] / 1e6));
}
System.out.println(sb + " ms (p50)");
}
}
if (mode.equals("phases")) {
final String[] names = { "begin", "SELECT Part by key", "INSERT OrderNew", "UPDATE Part by key", "commit" };
for (int p = 0; p < names.length; p++) {
final long[] a = PHASES[p];
Arrays.sort(a);
System.out.printf("RESULT phase %-20s p50 %.3f ms p99 %.3f ms%n", names[p], a[ops / 2] / 1e6, a[(int) (ops * 0.99)] / 1e6);
}
}
Arrays.sort(ns);
System.out.printf("RESULT %-3s new-order p50 %.3f ms p99 %.3f ms (%,d ops after %,d warm-up)%n", mode,
ns[ops / 2] / 1e6, ns[(int) (ops * 0.99)] / 1e6, ops, warm);
db.drop();
}
}
static void sqlNewOrder(final Database db, final long i, final long pkey) {
db.begin();
try (final ResultSet rs = db.query("sql", "SELECT p_retailprice, stock FROM Part WHERE p_partkey=:k", Map.of("k", pkey))) {
while (rs.hasNext())
rs.next();
}
db.command("sql", "INSERT INTO OrderNew SET okey=:o, pkey=:p, qty=1, paid=0", Map.of("o", i, "p", pkey)).close();
db.command("sql", "UPDATE Part SET stock = stock - 1 WHERE p_partkey=:k", Map.of("k", pkey)).close();
db.commit();
}
static long[][] PHASES;
static void phasedNewOrder(final Database db, final long i, final long pkey, final int slot) {
final long t0 = System.nanoTime();
db.begin();
final long t1 = System.nanoTime();
try (final ResultSet rs = db.query("sql", "SELECT p_retailprice, stock FROM Part WHERE p_partkey=:k", Map.of("k", pkey))) {
while (rs.hasNext())
rs.next();
}
final long t2 = System.nanoTime();
db.command("sql", "INSERT INTO OrderNew SET okey=:o, pkey=:p, qty=1, paid=0", Map.of("o", i, "p", pkey)).close();
final long t3 = System.nanoTime();
db.command("sql", "UPDATE Part SET stock = stock - 1 WHERE p_partkey=:k", Map.of("k", pkey)).close();
final long t4 = System.nanoTime();
db.commit();
final long t5 = System.nanoTime();
if (slot >= 0) {
final long[] d = { t1 - t0, t2 - t1, t3 - t2, t4 - t3, t5 - t4 };
for (int p = 0; p < 5; p++)
PHASES[p][slot] = d[p];
}
}
static void apiNewOrder(final Database db, final long i, final long pkey) {
db.begin();
final IndexCursor c = db.lookupByKey("Part", "p_partkey", pkey);
final Document part = c.next().asDocument();
part.getDouble("p_retailprice");
db.newDocument("OrderNew").set("okey", i).set("pkey", pkey).set("qty", 1).set("paid", 0).save();
final MutableDocument m = part.modify();
m.set("stock", m.getLong("stock") - 1).save();
db.commit();
}
static void deleteTree(final File f) {
final File[] kids = f.listFiles();
if (kids != null)
for (final File k : kids)
deleteTree(k);
f.delete();
}
}#!/usr/bin/env bash
# Commit-step attribution: the stock engine against the same engine with an instrumented TransactionContext
# (cumulative nanoTime around each commit step), alternated, REPS each, OPS new-orders per run after 5,000
# warm-up. Same build (7effa0950e), 4 cores, 4 GiB heap, txWalFlush=0, Part loaded in 10,000-record transactions.
set -e
IMG=${1:-arcadedb-snap:7effa0950e}; OPS=${2:-50000}; REPS=${3:-3}
cd "$(dirname "$0")"; W=~/build-scratch/neworder; rm -rf lib cls pT "$W"; mkdir -p lib cls pT "$W"
cid=$(docker create "$IMG"); docker cp "$cid:/home/arcadedb/lib/." lib/ >/dev/null; docker rm "$cid" >/dev/null
echo "engine $(unzip -p lib/arcadedb-engine-*.jar com/arcadedb/arcadedb.properties | grep buildNumber)"
RUN="docker run --rm --user $(id -u):$(id -g) --cpuset-cpus 0-3 -m 8g -e HOME=/w -v $PWD:/w -v $W:/db -w /w eclipse-temurin:25-jdk"
$RUN javac -nowarn -cp '/w/lib/*' -d /w/pT patchT-src/TransactionContext.java 2>&1 | grep -v '^Note' || true
$RUN javac -cp '/w/lib/*' -d /w/cls NewOrderBench.java
JAVA="java -Xms4g -Xmx4g -XX:+UseCompactObjectHeaders -Darcadedb.txWalFlush=0 --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED"
for rep in $(seq 1 "$REPS"); do
for arm in stock timed; do
CP="/w/lib/*:/w/cls"; [ "$arm" = timed ] && CP="/w/pT:/w/lib/*:/w/cls"
echo "== $arm rep $rep"
$RUN $JAVA -cp "$CP" NewOrderBench /db/java "$OPS" phases-only 10000 0 2>&1 \
| grep -oE 'RESULT (phase commit.*|phases new-order.*|step.*)|Exception.*'
done
done
rm -rf lib cls pT "$W"The timer patch to TransactionContext (measurement only)
--- engine/src/main/java/com/arcadedb/database/TransactionContext.java 2026-09-26 08:13:28.437788380 +0900
+++ instrumented/TransactionContext.java 2026-09-27 17:22:50.034661512 +0900
@@ -132,6 +132,12 @@
// so AtomicInteger was only a mutable-cell trick. IntIntHashMap.add(key, delta) covers it directly.
private final IntIntHashMap bucketRecordDelta = new IntIntHashMap();
private final Map<RID, Record> immutableRecordsCache = new HashMap<>(1024);
+ // PATCH (measurement only): cumulative nanoseconds per commit step, read by NewOrderBench via reflection.
+ // 0 phase1, 1 publishCommittedPages, 2 finishCommitBookkeeping, 3 concludePhase2 (reset + callbacks),
+ // 4 validateAndBumpVersions, 5 writeTransactionToWAL, 6 publishPages, 7 commits counted
+ // 8 phase1: up to the index commit (locks, updated records), 9 indexChanges.commit(), 10 compressPage loops,
+ // 11 phase1: after compressPage (modified ranges, rebase, WAL buffer)
+ public static final long[] PROF = new long[12];
private final Map<RID, Record> modifiedRecordsCache = new HashMap<>(1024);
// Records created in this transaction (they got an optimistically-assigned RID at creation time). On rollback that
// RID no longer exists, so the identity is reset to provisional (null) letting the same in-memory object be cleanly
@@ -374,7 +380,10 @@
// The rollback-only refusal is NOT repeated here: it lives in commit1stPhase (issue #8053), which this
// method calls next and which every other commit path reaches directly.
+ final long _p0 = System.nanoTime();
final TransactionPhase1 phase1 = commit1stPhase(true);
+ PROF[0] += System.nanoTime() - _p0;
+ PROF[7]++;
if (phase1 != null) {
commit2ndPhase(phase1);
} else
@@ -2104,6 +2113,7 @@
// gates conflict-rebase below: replaying an index queue is a pure local recomputation, but rebasing a page
// against a newer local version is unsafe once the result has to survive an extra hop through Raft ordering.
this.indexChangesReplayed = true;
+ long _q0 = System.nanoTime();
try {
// #4937: explicit-lock mode captured before checkExplicitLocks nulls explicitLockedFiles, so the
@@ -2173,7 +2183,10 @@
// COMMIT INDEX CHANGES: always, on whichever node originates this commit (#6964) - see the note on
// indexChangesReplayed above.
+ final long _q1 = System.nanoTime();
+ PROF[8] += _q1 - _q0;
indexChanges.commit();
+ PROF[9] += System.nanoTime() - _q1;
// #4937: the steps above (updateRecordNoLock, indexChanges.commit) can add pages of files that were
// NOT in the lock set computed at lock time - EXTERNAL-property buckets, indexes created inside this
@@ -2230,6 +2243,7 @@
// COMPRESS PAGES BEFORE SAVING THEM
final LocalSchema localSchema = database.getSchema().getEmbedded();
+ final long _q2 = System.nanoTime();
for (MutablePage page : modifiedPages.values()) {
final LocalBucket bucket = localSchema.getBucketById(page.getPageId().getFileId(), false);
if (bucket != null)
@@ -2240,6 +2254,9 @@
if (bucket != null)
bucket.compressPage(page, false);
}
+ final long _q3 = System.nanoTime();
+ PROF[10] += _q3 - _q2;
+ _q0 = _q3;
List<PageId> pagesToRebase = null;
List<PageId> slotPagesToRebase = null;
@@ -2317,6 +2334,7 @@
result = database.getTransactionManager().createTransactionBuffer(txId, pages);
}
+ PROF[11] += System.nanoTime() - _q0;
return new TransactionPhase1(result, pages);
} catch (final DuplicatedKeyException | NeedRetryException e) {
@@ -2351,8 +2369,12 @@
boolean committed = false;
Throwable commitFailureCause = null;
try {
+ final long _p1 = System.nanoTime();
publishCommittedPages(changes);
+ final long _p2 = System.nanoTime();
+ PROF[1] += _p2 - _p1;
finishCommitBookkeeping();
+ PROF[2] += System.nanoTime() - _p2;
committed = true;
} catch (final ConcurrentModificationException e) {
commitFailureCause = e;
@@ -2371,7 +2393,9 @@
.log(this, Level.FINE, "Unknown exception during commit (threadId=%d)", e, Thread.currentThread().threadId());
throw new TransactionException("Transaction error on commit", e);
} finally {
+ final long _p3 = System.nanoTime();
concludePhase2(committed, commitFailureCause);
+ PROF[3] += System.nanoTime() - _p3;
}
}
@@ -2416,11 +2440,15 @@
throw new TransactionException(
"Cannot commit: the database is fenced after a failure past the WAL commit point, close and reopen it to run recovery");
+ final long _p4 = System.nanoTime();
final List<MutablePage> pagesToPublish = database.getPageManager().validateAndBumpVersions(newPages, modifiedPages);
+ PROF[4] += System.nanoTime() - _p4;
if (changes.result != null) {
// WRITE TO THE WAL: THE POINT OF NO RETURN
+ final long _p5 = System.nanoTime();
database.getTransactionManager().writeTransactionToWAL(changes.modifiedPages, getWALFlush(), txId, changes.result);
+ PROF[5] += System.nanoTime() - _p5;
// Only a REAL append crosses the point of no return (#5053/#4940): with useWAL=false (bulk loads)
// changes.result is null, nothing is durable and there is no WAL record for recovery to replay - a
// publish failure must then behave like any pre-durability failure (full rollback of user-held
@@ -2434,7 +2462,9 @@
// From here the transaction is durable in the WAL: a failure below is repaired by recovery replay,
// never by aborting.
+ final long _p6 = System.nanoTime();
database.getPageManager().publishPages(pagesToPublish, newPages, isAsyncFlush());
+ PROF[6] += System.nanoTime() - _p6;
for (final Map.Entry<Integer, Integer> entry : newPageCounters.entrySet())
((PaginatedComponent) database.getSchema().getFileById(entry.getKey())).updatePageCount(entry.getValue());
Activity
Merge pull request #8524 from ArcadeData/fix/8523-8492-8441-parallel-…
perf: parallel filtered scans and aggregation, cheaper small commits,…
tae898 commentedon Sep 28, 2026
Verified on the published
26.10.1-SNAPSHOTatc44f6604e8(this PR's merge) against7effa0950e(the build this issue was filed on), with the sameNewOrderBenchfrom the issue, the two engines alternated over two rounds, Temurin 25 with compact object headers and Temurin 21, cores 0-3,txWalFlush=0, 20,000 new-orders after 5,000 warm-up:7effa0950ec44f6604e8commit()Commit is 2.2x cheaper and the transaction 1.6-1.8x, the same on both JDKs. One small thing I noticed, which may be nothing: on Temurin 21 the first SQL pass's p99 rose (0.46-0.50 ms to 0.66 ms) while the second pass's p99 fell (0.32 ms to 0.20 ms); on Temurin 25 both fell. Thank you, this moves my documents transactions table at the next measurement.
CAMPAIGN: PR ArcadeData#8524 (our ArcadeData#8523 and ArcadeData#8492,…
lvca commentedon Sep 28, 2026
Fixed in #8524 (26.10.1).
On your new-order shape, commit p50 went from 0.046 to 0.021 ms and the whole transaction from 0.055 to 0.029 ms.
❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.