Skip to content

test(engine) #5519: isolate what a tag-heavy TimeSeries schema pays on ingest - #5520

Merged
lvca merged 2 commits into
mainfrom
issue-5519-tag-stride-benchmark
Jul 29, 2026
Merged

lvca merged 2 commits into
mainfrom
issue-5519-tag-stride-benchmark

Conversation

@lvca

@lvca lvca commented Jul 29, 2026

Copy link
Copy Markdown
Member

Backs the numbers quoted on #5519 and on #5474 with a benchmark that can be re-run.

What it measures

TimeSeriesBucket.calculateRowSize() reserves 2 + MAX_STRING_BYTES = 258 bytes of row stride for every STRING column, while writeStringValue() stores the row packed. Only the stride assumes the maximum, and the stride is what positions the row inside the page. On the TSBS cpu-only shape (10 STRING tags + 3 DOUBLE) that is a 2612-byte stride carrying ~110 bytes of data: 25 rows per 64 KB page, 4% fill.

The benchmark separates that cost from the row encoding with three arms that each differ in exactly one variable:

arm what it changes isolates
WideStride the TSBS shape, 10 tags of ~8 chars the baseline
WideStrideBigValues same schema, 200-char tag values: 20x more string bytes encoded per row, same stride encoding cost
NarrowStride same tag text joined into one column: identical content, one ninth the stride page traffic

Output at the default size:

=== TimeSeries tag stride, 20,000 rows per batch, 3 measured batches per arm ===
arm                      stride   rows/page      pages      payload       page traffic       ms
WideStride                 2612          25        800       2.1 MB      50.0 MB (23x)     28.3
WideStrideBigValues        2612          25        800      39.1 MB       50.0 MB (1x)     32.2
NarrowStride                290         225         89       1.9 MB        5.6 MB (2x)      3.1

Encoding twenty times more string data costs nothing. Changing only the stride is 9x. A batch moves 23x more page and WAL bytes than it stores, which also costs the page cache and compaction.

Note the WideStrideBigValues amplification of 1x: 200-char tags nearly fill the 258 reserved bytes. The reservation is only waste when tag values are short, which is every real tag set.

Notes on the method

  • One full warmup pass over all three arms runs before any arm is measured, so no arm profits from the JIT state another left behind. Timing is nanoTime, median of 3 batches.
  • Assertions are the two orderings, not absolute times, so this does not go flaky on other hardware. Observed margins are 3.7x and 9x against 2x bounds.
  • Named *Benchmark.java and tagged benchmark, so mvn-test.yml excludes it two ways and benchmark-tests.yml picks it up.
  • Default batch is 20k rows, not the 50k quoted on the issues: a wide-stride arm writes rows / 25 pages of 64 KB, so 50k costs roughly 1 GB under target/ across the three arms. -Darcadedb.tagStrideBenchmark.rows=50000 reproduces the published batch size.

Production change

One addition, TimeSeriesBucket.getRowSize(), so the stride can be reported exactly rather than derived from getMaxSamplesPerPage(). It sits next to that existing public accessor and changes no behaviour.

Verification

  • mvn -pl engine test -Dtest=TimeSeriesTagStrideBenchmark -Dgroups=benchmark passes
  • all 460 com.arcadedb.engine.timeseries.** tests pass with the accessor added

When the tag dictionary proposed in #5519 lands, WideStride should converge towards NarrowStride and the assertions in this test are expected to change.

…n ingest

calculateRowSize() reserves 2 + MAX_STRING_BYTES = 258 bytes of stride for every
STRING column, while writeStringValue() stores the row packed. Only the stride
assumes the maximum, and the stride is what positions the row in the page, so on
the TSBS cpu-only shape (10 tags + 3 DOUBLE) a 2612-byte stride carries ~110 bytes
of data: 25 rows per 64 KB page, 4% fill.

The benchmark separates that from the row encoding with three arms that differ in
one variable each. Twenty times more string bytes per row at the same stride costs
nothing; the same tag content in one column, at one ninth of the stride, is 9x
faster. A batch moves 23x more page and WAL bytes than it stores.

Adds TimeSeriesBucket.getRowSize() so the stride can be reported exactly rather
than derived from getMaxSamplesPerPage().

Tagged benchmark and named *Benchmark, so mvn-test.yml excludes it and
benchmark-tests.yml picks it up. Default batch is 20k rows because a wide-stride
arm writes rows/25 pages of 64 KB; -Darcadedb.tagStrideBenchmark.rows=50000
reproduces the batch size quoted on the issue.
@lvca lvca added performance storage Storage/paging/WAL engine layer java Pull requests that update java code labels Jul 29, 2026
@lvca lvca self-assigned this Jul 29, 2026
@lvca lvca added this to the 26.8.1 milestone Jul 29, 2026
@mergify

mergify Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@codacy-production

codacy-production Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 minor

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
CodeStyle 1 minor

View in Codacy

🟢 Metrics 30 complexity

Metric Results
Complexity 30

View in Codacy

🟢 Coverage 0.00% diff coverage · -6.32% coverage variation

Metric Results
Coverage variation ✅ -6.32% coverage variation
Diff coverage ✅ 0.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c906c6b) 146708 108811 74.17%
Head commit (e711b43) 178701 (+31993) 121254 (+12443) 67.85% (-6.32%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#5520) 1 0 0.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@claude

claude Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review: #5520 - TimeSeries tag-stride benchmark

Reviewed the production change (TimeSeriesBucket.getRowSize()) and the new TimeSeriesTagStrideBenchmark. This is a clean, self-justifying benchmark and the writeup is excellent - the three-arm design that varies exactly one variable per arm (encoding vs. page traffic) is a genuinely good way to isolate the finding. Verified the mechanics against the code:

Production change - good

  • getRowSize() is a pure accessor over the existing rowSize field, sits next to getMaxSamplesPerPage(), changes no behaviour. Javadoc correctly documents the packed-write vs. reserved-stride distinction. No concerns.
  • Confirmed all the accessors the test reaches through are already public: getShard, getMutableBucket, LocalTimeSeriesType.getEngine, getMaxSamplesPerPage.

Correctness spot-checks - all hold

  • medianNanos(): measurements reaches 3 (warmup uses appendOneBatch, not measureOneBatch), sorted[3/2] = sorted[1] is the true median. Good.
  • payloadBytesPerBatch derives from column[0] only, which is safe since every row in an arm carries identical values.
  • Caching bucket in the constructor is fine even if the mutable bucket seals/rolls mid-run: it is only read for getRowSize()/getMaxSamplesPerPage(), which are schema-level constants.

Minor points (non-blocking)

  1. Hardcoded PAGE_SIZE = 65_536. This matches the default of BUCKET_DEFAULT_PAGE_SIZE (verified), so the numbers are consistent today. But rowsPerPage()/pagesPerBatch() read the actual configured page size via the bucket, while pageTrafficAmplification() and report() multiply by the hardcoded constant. If someone runs with -Darcadedb.bucketDefaultPageSize=..., the two diverge and the reported traffic/amplification (and the > 10 assertion) silently drift. Consider deriving the constant from the bucket page size, or asserting PAGE_SIZE == configured up front.

  2. Timing-based assertions. The two medianNanos() orderings are inherently sensitive to a noisy runner. The 3.7x/9x observed margins against 2x bounds give good headroom, and it is @Tag("benchmark") so it is out of mvn-test.yml - so this is acceptable, just flagging that this class can flake on a contended CI host in a way the structural assertions (rowsPerPage, amplification) never will.

  3. System.out.printf reporting is the benchmark intended output (not stray debug), so it is fine here despite the usual "remove System.out" guideline.

  4. Disk footprint at the 20k default is ~600 MB across arms (4 batches x 800 pages x 64 KB x 3 arms); the doc ~1 GB figure is for the 50k override. Worth keeping in mind for wherever benchmark-tests.yml runs, but the @Tag gating handles it.

Nothing blocking - the production change is safe and the test is a solid, reproducible artifact for the #5519/#5474 numbers.

The reported traffic and the amplification assertion multiplied by a hardcoded
64 KB while rows/page came from the bucket, so running with a non-default
arcadedb.bucketDefaultPageSize made the two silently disagree. Both sides now read
getPageSize(), which was already public on PaginatedComponent.
@lvca

lvca commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Thanks - point 1 was a real defect and is fixed in e711b43.

1. Hardcoded page size. You are right that the two sides could disagree. PaginatedComponent.getPageSize() was already public, so the constant is gone entirely: pageTrafficBytesPerBatch() now reads it from the bucket, and both report() and the amplification assertion go through that one method. Running with -Darcadedb.bucketDefaultPageSize=... now stays internally consistent instead of drifting. Also made the two remaining prose references say "at the default 64 KB page size" rather than stating it as a fact of the layout.

2. Timing assertions. Accepted as a known trade-off. Worth being explicit about which assertions carry which weight: the two medianNanos() orderings are the finding, so they have to be timing-based, while the three structural ones (rowsPerPage, amplification) are the part that can never flake. If this does turn out to flake on the benchmark runner, the right fix is to drop the timing pair rather than widen the bounds, since a widened bound would stop testing anything.

3. System.out.printf. Agreed, that is the deliverable here.

4. Disk footprint. Your ~600 MB at the 20k default is right. The javadoc only quotes the 1 GB figure for the 50k override, so nothing to correct there.

Re-ran after the change: 29.9 / 25.5 / 4.3 ms across the three arms, ratios unchanged.

@claude

claude Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review: PR 5520 - TimeSeries tag-stride benchmark

Thanks for the very thorough write-up. I verified the change against the codebase and it looks solid. Summary: a 10-line no-behaviour accessor plus a self-contained, correctly-tagged benchmark. Approve with a few minor notes.

What is good

  • Production change is minimal and safe. getRowSize() just exposes the existing rowSize field next to getMaxSamplesPerPage(), no behaviour change. The Javadoc explaining the stride-vs-packed distinction is genuinely useful.
  • Correct test hygiene. @tag("benchmark") plus the *Benchmark.java naming means it is excluded from mvn-test.yml two ways and picked up by benchmark-tests.yml, matching the other files in engine/src/test/java/performance/.
  • Method design. Warmup over all arms before measuring any, median-of-3, and the structural (non-timing) assertions on rowsPerPage()/pageTrafficAmplification() are the robust part - they hold on any host. Sharing the same String reference across all rows in tenTagColumnValues keeps the WideStrideBigValues arm from blowing up heap. All referenced APIs (getPageSize, getMutableBucket, appendBatch(long[], Object[][])) exist as used.

Minor notes (non-blocking)

  1. Timing-based assertions can be brittle. The two medianNanos() orderings (wideBig < wide2, narrow2 < wide) are the only host-sensitive checks. You note observed margins of 3.7x/9x against 2x bounds, so there is headroom, but on a heavily loaded or throttled CI runner a 2x timing bound is the first thing that flakes. Since this is benchmark-tagged and off the default CI path the risk is low; just flagging that the structural assertions are the ones I would trust long-term.
  2. medianNanos() picks the upper median for even counts. sorted[sorted.length / 2] is correct for MEASURED = 3. If anyone later bumps MEASURED to an even value it silently becomes the upper-median rather than the average of the two middle values. A one-line comment or handling would future-proof it.
  3. System.out.printf reporting is intentional here (it is the benchmark output), so it does not fall under the remove-debug-System.out rule - fine as-is.
  4. Disk footprint is well-documented in the Javadoc (about 1 GB at 50k rows). Worth keeping the default at 20k as you have it.

Test coverage
This is test/verification code, so nothing to add. The claim that the accessor does not disturb existing behaviour is backed by the 460 com.arcadedb.engine.timeseries tests you ran.

Nice, reproducible artifact backing issues 5519/5474. LGTM.

@lvca
lvca merged commit 2d5b0fe into main Jul 29, 2026
22 of 26 checks passed
@lvca
lvca deleted the issue-5519-tag-stride-benchmark branch July 29, 2026 04:48
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 65.70%. Comparing base (c906c6b) to head (e711b43).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...m/arcadedb/engine/timeseries/TimeSeriesBucket.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5520      +/-   ##
============================================
+ Coverage     65.31%   65.70%   +0.39%     
+ Complexity     1114     1112       -2     
============================================
  Files          1748     1748              
  Lines        146708   146709       +1     
  Branches      31358    31358              
============================================
+ Hits          95817    96394     +577     
+ Misses        37940    37369     -571     
+ Partials      12951    12946       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

robfrank pushed a commit that referenced this pull request Aug 14, 2026
…n ingest (#5520)

* test(engine) #5519: isolate what a tag-heavy TimeSeries schema pays on ingest

calculateRowSize() reserves 2 + MAX_STRING_BYTES = 258 bytes of stride for every
STRING column, while writeStringValue() stores the row packed. Only the stride
assumes the maximum, and the stride is what positions the row in the page, so on
the TSBS cpu-only shape (10 tags + 3 DOUBLE) a 2612-byte stride carries ~110 bytes
of data: 25 rows per 64 KB page, 4% fill.

The benchmark separates that from the row encoding with three arms that differ in
one variable each. Twenty times more string bytes per row at the same stride costs
nothing; the same tag content in one column, at one ninth of the stride, is 9x
faster. A batch moves 23x more page and WAL bytes than it stores.

Adds TimeSeriesBucket.getRowSize() so the stride can be reported exactly rather
than derived from getMaxSamplesPerPage().

Tagged benchmark and named *Benchmark, so mvn-test.yml excludes it and
benchmark-tests.yml picks it up. Default batch is 20k rows because a wide-stride
arm writes rows/25 pages of 64 KB; -Darcadedb.tagStrideBenchmark.rows=50000
reproduces the batch size quoted on the issue.

* test(engine) #5519: derive page traffic from the bucket page size

The reported traffic and the amplification assertion multiplied by a hardcoded
64 KB while rows/page came from the bucket, so running with a non-default
arcadedb.bucketDefaultPageSize made the two silently disagree. Both sides now read
getPageSize(), which was already public on PaginatedComponent.

(cherry picked from commit 2d5b0fe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update java code performance storage Storage/paging/WAL engine layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant