Tuning a Spark Load (via the StarRocks Spark Conne...
# questions-and-troubleshooting
r
Tuning a Spark Load (via the StarRocks Spark Connector) is primarily about balancing loading throughput, memory usage on Spark executors, and avoiding the "small file" problem in StarRocks. The Spark connector accumulates data in memory and flushes it to StarRocks using the Stream Load protocol. Here is the best way to tune these parameters: 1. Understand the Flush Trigger Policy Data is flushed from a Spark executor to StarRocks whenever any of these three conditions are met first: *
starrocks.write.buffer.size
: Memory threshold (Default: 100MB). *
starrocks.write.buffer.rows
: Row count threshold (Default:
Integer.MAX_VALUE
). *
<http://starrocks.write.flush.interval.ms|starrocks.write.flush.interval.ms>
: Time threshold (Default: 300,000ms / 5 mins). 2. Tuning for High Throughput & Large Datasets If you are doing a large batch load, the goal is to send fewer, larger batches to reduce the overhead on StarRocks BEs. * Increase
starrocks.write.buffer.size
: Set this to 200MB - 500MB (e.g.,
524288000
). Larger buffers mean fewer HTTP requests and better compression efficiency. * Increase
<http://starrocks.write.flush.interval.ms|starrocks.write.flush.interval.ms>
: If you don't care about real-time visibility, increase this to prevent premature flushes for slow-moving data streams. * Enable Transaction Interface: Ensure
starrocks.write.enable.transaction-stream-load
is
true
(default in newer versions). This uses the Stream Load transaction interface (SR v2.5+), which is more memory-efficient and stable for large volumes. * Note: For this to work,
starrocks.write.max.retries
must be set to
0
(or a non-positive value) because the transaction interface does not support internal retries. 3. Avoiding "Small Files" & Segment Issues StarRocks performance degrades if you create too many small versions (tablets). * Decrease
starrocks.write.num.partitions
: If Spark has 1000 partitions, it will attempt 1000 parallel stream loads. Even with a 100MB buffer, this creates 1000 files in one go. Reduce this number to align better with your StarRocks tablet count (usually *Parallelism = BE Nodes * 1 to 2*). * Balance Buffer vs. Parallelism: It is better to have 20 tasks with 500MB buffers than 200 tasks with 50MB buffers. 4. Spark Executor Memory Management When you increase the buffer size, you must ensure your Spark executors have enough heap space. * The Math:
Memory Usage ≈ starrocks.write.num.partitions_per_executor * starrocks.write.buffer.size
. * If you set a 500MB buffer and an executor runs 4 tasks, it will use ~2GB just for the StarRocks write buffers. Adjust
spark.executor.memory
accordingly to avoid
OutOfMemoryError
. 5. Summary Recommendation For a standard high-volume production job, start with these settings: Parameter | Recommended Value | Why?
starrocks.write.buffer.size
|
209715200
(200MB) | Good balance between throughput and memory.
starrocks.write.num.partitions
|
(Number of BEs * 2)
| Reduces the number of concurrent "small" versions.
starrocks.write.max.retries
|
0
| Enables the high-performance Transaction Interface.
starrocks.write.enable.transaction-stream-load
|
true
| Required for optimized large-scale loads. Pro Tip: If you see the error
"Too many versions"
or
"TabletWriter add batch with unknown id"
, it is almost always a sign that your
starrocks.write.buffer.size
is too small or your
starrocks.write.num.partitions
is too high. Referencesloading/Spark-connector-starrocks.mdunloading/Spark_connector.mdloading/Flink-connector-starrocks.md