Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/benchmarks/native-sync-calc.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ native library, and run the Java driver with `-Dsync.mode=previous -Dsync.discar
This mode permits the baseline JVM assignment; it does not change the engine's SQL
or evaluation path. Keep each Flink line's compiled target directory separate.

## Direct numeric formatting follow-up

A release A/B run on the Apple M4 measured the same 131,072-row prepared Calc with
zero passthrough string columns and a varying timestamp. Direct numeric formatting
reduced the native median from 30.43 ms to 19.78 ms (35%). The stock Flink, previous
native, and optimized native runs produced the same checksum. The complete Paimon job
and individual samples are recorded in the [log-sink follow-up](paimon-log-sink.md#removing-redundant-formatting-and-batch-copies).

## Correctness evidence

The JDK 11 regression selection passes on both supported Flink lines: competing failures,
Expand Down
172 changes: 172 additions & 0 deletions docs/benchmarks/paimon-log-sink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Streaming Paimon log sink

`PaimonLogSinkBenchmark` submits a Flink streaming SQL job and times execution from
MiniCluster submission through the final Paimon commit. It uses a bounded, deterministic
row source that generates log content, hostname and path values, and epoch-second
timestamps. The projection applies the hostname/path NULL and space checks, conditional
concatenation, `FROM_UNIXTIME`, substring extraction, and 15-minute rounding. The public
Flink SQL spelling for the stakeholder's `LENGTH` call is `CHAR_LENGTH`.

The sink is a Paimon Parquet append table partitioned by `ds`, `hh`, and `mm`, with
`bucket=-1`, `write-only=true`, `changelog-producer=none`, and the six-hour update-time
partition expiration option. The default uses four source subtasks, four writers, four
interleaved partitions crossing midnight UTC, two million rows, 256-byte input messages,
65,536 deterministic message tails, and one-second checkpoints. The fixture substitutes a
local warehouse and a generated source for SLS and DFS. It uses the released Paimon Java
connector and omits deployment-specific catalog and connector options. The job duration
covers periodic and final commits. The six-hour retention window stays open throughout
each trial.

Stock and native jobs alternate order after a warmup for each engine. The timed interval
includes source generation, Flink job startup, the SQL transformation, required row/Arrow
conversions and IPC, Parquet encoding, filesystem writes, and commits. Planning and
verification occur outside the interval. Each trial checks the submitted graph, reads the
committed data through Paimon's released reader, checks every ID and exact content and
partition values, and verifies the writer in every Parquet footer. It reports native Calc
use, the presence of the round-robin stage, committed snapshots, file count, Parquet
bytes, elapsed time, and throughput.

## Reproduce

Run locally on a controlled host with JDK 17 and release native libraries.

```sh
mvn -Ppaimon,bench,benchmarks -pl streamfusion-paimon -am test \
-Dtest=PaimonLogSinkBenchmark -Dsurefire.failIfNoSpecifiedTests=false \
-Dsf.paimon.log.benchmark=true
```

Use `-Dsf.paimon.log.partitions=1` for one active 15-minute partition and
`-Dsf.paimon.log.partitions=24` for six hours of interleaved arrivals. Use
`-Dsf.paimon.log.writers=1` to exercise redistribution at a source parallelism of four.
The other knobs are `rows`, `parallelism`, `payloadBytes`, `payloadVariants`,
`checkpointMs`, `warmup`, and `runs`, all prefixed with `sf.paimon.log.`. Set
`-Dsf.paimon.log.engine=STOCK` or `NATIVE` for a single-engine profile. The benchmark
deletes its temporary warehouse after each trial. Set `java.io.tmpdir` for the fork to
place warehouse and Flink runtime files on the disk under test.

For CPU, allocation, and wall-clock sampling with async-profiler on macOS, set the fork
JVM argument below and run one engine per recording. The equivalent CPU event on Linux
is `cpu`. Filter the output to Flink task threads to exclude planning and readback.
Use unprofiled invocations for elapsed-time comparisons.

```sh
-Dsf.extraJvmArgs="-XX:+PreserveFramePointer -agentpath:$agent=start,event=itimer,interval=2ms,alloc=256k,wall=10ms,threads,cstack=fp,file=$recording"
```

Copy the benchmark into the corresponding test source tree for revisions before the
`benchmarks` profile existed. Build release libraries from each historical checkout, and
run the same fixture and settings. A single-file planner overlay can additionally
measure a routing change while holding the rest of the runtime constant.

## Historical routing regression

A ten-step source bisect from `743adedcf` to `3082b2626` located the added row/channel
reassignment at `8f12e1637` (November 13). That path reached main in `9d44371f1`, including append jobs
whose input and writers already had the same parallelism. `71dbaf767` (November 28) restored
local writer chaining in that case. The `v0.1.0-rc5` tag contains the added route and predates
the fix. The additional route split already partition-grouped Arrow batches, crossed the C
Data Interface again, serialized the routed batches and stripped the channel at the writer.

To isolate the change, the A/B comparison overlays the released `71dbaf767` sink planner
class on `3082b2626` (November 20). Both sides use the same Flink 2.2.1 and Paimon 2.1.0
artifacts, native release libraries, SQL, fixture, and resources. The local Apple M4 host
runs macOS 15.3.1 and Temurin 17.0.17 with a 3 GiB Java heap and six active JVM processors.
Release libraries use mimalloc with the unused native RocksDB feature disabled. Each
side uses two independent JVMs with one warmup and two measured jobs each. Fork order is
local, baseline, baseline, local.

| Four million rows, four partitions, four writers | Median s (range) | Median rows/s |
| --- | ---: | ---: |
| November 20, additional route and exchange | 2.531 (2.404–2.789) | 1,580,617 |
| November 20 with local routing from November 28 | 2.180 (1.960–2.450) | 1,834,839 |

Local routing increased throughput **1.16×** and reduced median elapsed time **13.9%**.
The patched runs also wrote 774 MB per job versus 704–772 MB in the original measured
runs. Changing the routing changes the order seen by the encoder. An initial 8,192-tail
corpus amplified the resulting compression difference, so the primary comparison uses
65,536 tails and reports the physical bytes for every job.

In diagnostic runs with async-profiler 4.6, the additional round-robin operator appeared
in 2,295 of 18,256 CPU samples (12.6%) and 40.1% of estimated Java allocation bytes on the
Flink task threads. These are inclusive stacks, so downstream work can appear under the
operator. The local variant had no such frames or Arrow IPC serializer frames in the
task-thread allocation recording. Across three jobs with identical input counts, sampled
task-thread allocation weight fell from 56.8 GB to 22.3 GB (−61%). These figures estimate
intermediate allocation traffic. Peak heap and RSS were outside this profile. With the
extra exchange removed, Calc and file encoding remain prominent in CPU samples. The
wall-clock recording was dominated by condition and semaphore waits and is unsuitable as
a stage throughput breakdown.

### Release checkout comparison

The historical checkout runs use their own release libraries. Each checkout alternates
stock Flink and native jobs with one warmup and three measured jobs per engine. The
November 20 row takes the four-million-row native samples from the routing ablation above.

| Git revision | Paimon | Native median s (range) | Stock median s (range) | Native median rows/s |
| --- | --- | ---: | ---: | ---: |
| Oct 29, `743adedcf` | 2.0.0 | 1.918 (1.888–1.975) | 3.373 (3.218–3.478) | 2,085,636 |
| Nov 20, `3082b2626` | 2.1.0 | 2.531 (2.404–2.789) | — | 1,580,617 |
| Nov 30, `1e5d322ba` | 2.1.0 | 1.882 (1.830–1.912) | 3.129 (3.012–3.210) | 2,124,980 |

The November 30 checkout processed **1.66×** as many rows per second as its stock Flink
control. The October and November 30 native runs used local writer chaining. Their
comparison includes intervening runtime and Paimon changes. The routing ablation controls
for those changes. Live SLS, DFS, and the stakeholder's connector distribution require
separate measurements for production throughput.

At 24 interleaved partitions and two million rows, medians were 1.988 s (1.946–2.042)
native and 2.031 s (1.934–2.205) stock. The ranges overlap. Snapshot boundaries and
file counts varied across trials. The four-partition speedup depends on the workload's
active partitions and checkpoint behavior.

### One writer

An experimental global exchange sent already routed bucket-zero batches from four source
tasks to one writer and avoided a second grouping. It passed the submitted-graph and
checkpoint-recovery checks on Flink 2.2/Paimon 2.1 and Flink 1.18/Paimon 2.0 and 1.0.
At 256 bytes per message and four million rows, the original median was 3.045 s
(3.028–3.073) and the direct-exchange median was 3.017 s (2.988–3.060). At 1,024 bytes
and two million rows, those medians were 4.084 s (3.978–4.189) and 4.216 s
(4.148–4.283). The profiling run showed 35.2 GB versus 34.6 GB of sample-weighted
Java task allocation, including warmup. The wider run and the overlapping narrow
samples leave the additional shortcut without a demonstrated elapsed-time gain.
The checked-in runtime uses the existing redistribution when writer parallelism differs.

The [structured trial data](results/paimon-log-sink-20261130.csv) include warmups,
diagnostics, file counts, and physical sizes alongside the unprofiled measurements.

## Removing redundant formatting and batch copies

The follow-up reduces work in two places. `FROM_UNIXTIME` formats ordinary date digits
directly and uses 64-bit offset addition on the common path. The Parquet encoder borrows
the original batch when the requested range covers all its rows.

The isolated date-partition Calc uses the same Flink-exported program and prepared
Arrow input for both native binaries. The program contains three `FROM_UNIXTIME`
calls. Over 131,072 rows, the median dropped from **30.43 ms** (29.20–31.24) to
**19.78 ms** (19.48–19.95), a **35%** reduction. Each native variant had 14 timed
trials across two processes. All Calc outputs had the same checksum as the prepared
stock Flink control, whose median was 77.99 ms across five timed trials.

An isolated Arrow allocation count used 1,024 rows, the 256-byte content column,
and the three partition strings. A whole-batch slice requested five allocations
and 608 bytes. Borrowing the batch requested zero. These counts cover the removed
array operation.

In the final four-writer check with four active partitions and one-second checkpoints,
one upstream `a11ca1203` trial read back 3,994,304 of 4,000,000 rows. The next three
upstream native jobs, three stock Flink jobs, and three jobs with both changes passed
exact readback. The readback discrepancy remains unexplained. The follow-up's speed
measurement is the isolated Calc result above.

The corrected build passed 18 focused Flink 1.18 checks and 46 Flink 2.2 checks,
including dynamic partition routing, append checkpoint recovery, and Parquet writer
parity. The Rust Parquet range test passed.
The stateless Rust engine test build hits a RocksDB codec error in an unrelated
TopN test module on both revisions. All 10 targeted formatter and routing tests
passed with that test module temporarily excluded from the local build. Timings
used the production release libraries built from the benchmarked source.

[Prepared Calc trial data](results/paimon-log-sink-followup.csv)
Loading