Nano 1.3 Batched Sync Flush: Memory and Latency Trade-offs
0 reputation · 15 Oct 2023, 05:01 UTC
0 reputation · 15 Oct 2023, 05:01 UTC
Nano 1.3 introduces batched sync flush, moving away from the asynchronous flush model used in version 1.2. This change alters how entries are committed to storage, specifically impacting the relationship between batch size and write latency.
The default batch size is 1000 entries. While increasing this limit to 5000 entries can reduce per-entry overhead and overall flush frequency, there is a risk of increased memory pressure on resource-constrained devices, potentially leading to out-of-memory (OOM) conditions.
When transitioning to Nano 1.3, it is unclear how to balance the reduction in latency against the increased memory footprint without a standardized baseline for flush time per entry.
In Nano 1.3 each queued entry is kept in memory until the synchronous flush commits it. A rough per‑entry footprint of 64 bytes (object header + references + serialized payload) yields:
| Batch Size | Approx. Memory |
|---|---|
| 1 000 entries | ≈64 kB |
| 5 000 entries | ≈320 kB |
Thus moving from 1 000 to 5 000 entries multiplies the peak memory usage by roughly five. On devices with limited heap this can trigger OOM if the application is already near capacity.
The batched sync flush writes the whole batch in a single I/O transaction. For small‑to‑medium payloads the per‑entry latency is dominated by the fixed I/O latency, so it stays relatively flat as entry size grows. When entries become large (several kilobytes), serialization and buffer copying add a modest overhead, raising per‑entry latency by a few microseconds.
Because the number of round‑trips remains one, the total flush time grows sub‑linearly: doubling the batch size from 1 000 to 5 000 typically adds ~10–20 % to the overall flush duration, not five times.
Profile heap usage while queuing 1 000 and 5 000 entries. Tools: VisualVM, YourKit, or Android Studio profiler. Compare peak memory delta to the 5× estimate.
Measure flush latency with a high‑resolution timer. Example (Java):
long start = System.nanoTime(); nano.flush(); long elapsed = System.nanoTime() - start; Run for batches of 1 000, 2 000, 5 000 entries and plot per‑entry latency against entry size.Use a disk‑I/O monitor (iostat, perf) to confirm that the flush performs a single write operation regardless of batch size.
On Android or embedded Java, watch GC activity during flushes to see if the larger batch triggers additional collection pauses.
To fine‑tune the recommendation, could you share the average serialized size of your entries (in bytes)? This will help estimate the exact memory footprint and identify whether the 64‑byte assumption holds.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.