Build pipelines

Logstash performance tuning: workers, batch size, heap and queues

Most slow pipelines are slow for one identifiable reason. Measure first, change one setting at a time, and the defaults will rarely be what holds you back.

Updated 22 November 20269 min readWritten for Logstash 9.5

A throughput gauge beside sliders for pipeline workers, batch size, heap and queue size

Measure before you tune

The node stats API on port 9600 shows where events spend their time:

curl -s "localhost:9600/_node/stats/pipelines?pretty"

Look at the flow metrics for each pipeline and plugin. Input, filter and output throughput tell you how many events per second each stage handles; worker_utilization shows how busy the workers are; and queue_backpressure rises when inputs are being made to wait. Per-plugin duration_in_millis values point at the specific filter or output that costs the most. Give your plugins explicit id values so these numbers are readable.

Logstash 9.5 can also export its metrics to any OpenTelemetry endpoint. Set otel.metrics.enabled: true in logstash.yml to send most metrics over OTLP (flow-rate metrics are excluded), which is convenient if your monitoring stack already speaks OTLP.

The settings that matter

SettingDefaultRaise it when
pipeline.workersCPU coresCPU is idle and outputs wait on network round trips
pipeline.batch.size125Outputs benefit from bigger bulk requests
pipeline.batch.delay50 msRarely; it only affects partly filled batches
-Xms / -Xmx1 GBLarger batches, more workers or heavy filters need memory
queue.typememorySwitch to persisted for durability, not speed

Workers

Each worker runs filters and outputs on one batch at a time. If worker_utilization is close to 100% and the CPU still has headroom, outputs are probably waiting on I/O; adding workers lets more batches be in flight. If the CPU is already saturated, more workers only add contention. In containers, make sure the default is based on the CPUs you actually have: Logstash 9.5 reads cgroupv2 limits as well as cgroupv1, but setting pipeline.workers explicitly removes any doubt.

Batch size

Batches flow through the filters together and are sent to outputs as a unit, so the Elasticsearch output turns one batch into bulk requests. Raising pipeline.batch.size to a few hundred or a thousand often improves indexing throughput. The cost is memory: roughly workers × batch size events are held on the heap at once, so increase heap alongside batch size and watch garbage collection in the logs.

JVM heap

Set the heap in config/jvm.options (or LS_JAVA_OPTS in containers), with minimum and maximum equal so the JVM does not resize it under load:

-Xms4g
-Xmx4g

Leave a good share of the machine's memory for the operating system, the page cache (which persistent queues rely on) and memory used outside the heap. Signs that the heap is too small: frequent long garbage-collection pauses in the logs, throughput that sags over time, or OutOfMemoryError. A heap that is far too large wastes memory without helping.

Persistent queues and throughput

A persistent queue writes events to disk between inputs and workers. It protects against data loss when Logstash restarts and absorbs bursts larger than memory, but every event is written and read back, so expect lower peak throughput than the memory queue on the same hardware, especially on slow disks. Size it with queue.max_bytes (1 GB by default) according to how long an outage you want to ride out, and keep the data path on fast local storage.

Finding the real bottleneck

  • Slow outputs: HTTP 429 responses from Elasticsearch mean the cluster is rejecting bulk requests. Logstash retries them, but the fix is on the cluster side (more capacity or fewer shards), not more Logstash workers.
  • Expensive filters: unanchored grok patterns, ruby code, dns lookups and per-event database queries (jdbc_streaming, elasticsearch filter) dominate CPU time. Cache lookups where the plugin supports it and anchor every grok pattern.
  • Single-threaded inputs: some inputs cannot parallelise. Run several inputs (for example multiple Kafka consumer threads) or split traffic across pipelines.
  • Ordering: pipeline.ordered: true forces a single worker. The default auto only orders when you already run one worker.

A tuning routine

  1. Record a baseline from the stats API under realistic load.
  2. Change one setting, by a meaningful step (for example batch size 125 to 500).
  3. Let it run long enough for garbage collection and queues to settle, then compare.
  4. Keep the change only if throughput or latency improved without new errors.

For how pipelines and workers relate to configuration files, see pipeline configuration explained. For memory errors and stalls, see fixing common Logstash errors.