--- description: Performance and data safety --- # Buffering After Fluent Bit ingests data, it temporarily stores that data in the system memory (heap) before processing and routing that data to its destination. This process is known as _buffering_. ```mermaid graph LR accTitle: Fluent Bit data pipeline accDescr: A diagram of the Fluent Bit data pipeline, which includes input, a parser, a filter, a buffer, routing, and various outputs. A[Input] --> B[Parser] B --> C[Filter] C --> D[Buffer] D --> E((Routing)) E --> F[Output 1] E --> G[Output 2] E --> H[Output 3] style D stroke:darkred,stroke-width:2px; ``` {% hint style="info" %} Buffered data uses the Fluent Bit internal binary representation, which isn't raw text. This buffered data is immutable. {% endhint %} ## Chunks When an input plugin emits records, the engine groups records together into a _chunk_. Each chunk has an average size of 2 MB. The active [buffering mode](#buffering-modes) determines where these chunks are stored. Chunks that are stored simultaneously in memory and in filesystem storage are known as `up` chunks. Chunks that are stored only in filesystem storage are known as `down` chunks. A `down` chunk becomes an `up` chunk when a copy of the `down` chunk is written to memory. After an `up` chunk is processed and routed, the associated buffered data both in memory and in the filesystem is flushed. ### Irrecoverable chunks Fluent Bit marks a chunk as irrecoverable in the following scenarios: - When Fluent Bit encounters a bad layout in a chunk. A bad layout is a chunk that doesn't conform to the [expected format](https://github.com/fluent/fluent-bit/blob/master/CHUNKS.md). - When Fluent Bit encounters an incorrect or invalid chunk header size. After marking a chunk as irrecoverable, Fluent Bit logs an error message and then discards the irrecoverable chunk. ## Buffering modes Fluent Bit offers three modes for storing buffered data. Memory-only and memory ring buffer modes store data exclusively in memory, while filesystem buffering is a hybrid method that stores an additional copy of buffered data in the filesystem. You can set the buffering mode for each active [input plugin](#per-input-settings). ### Memory-only buffering When memory-only buffering is enabled, Fluent Bit stores buffered data in memory until it's ready to process and route that data to its intended destinations. After Fluent Bit processes and routes the data, it flushes that data from memory. This buffering method is faster than filesystem buffering, and uses less system overhead, but is more prone to data loss. ### Filesystem buffering (hybrid) When filesystem buffering is enabled, Fluent Bit stores each chunk of buffered data in the filesystem through [mmap(2)](https://man7.org/linux/man-pages/man2/mmap.2.html). If Fluent Bit has enough space in memory, an identical chunk of that buffered data is also written to memory. If Fluent Bit doesn't have enough space in memory, the chunk of buffered data remains only in the filesystem until there is enough space to write an identical chunk to memory. After Fluent Bit processes and routes the data, it flushes that data from memory and from the filesystem. This buffering method is less efficient than memory-only buffering, and uses more system overhead, but is less prone to data loss. ### Memory ring buffer buffering When memory ring buffer (`memrb`) buffering is enabled, Fluent Bit stores buffered data in a fixed-size memory ring buffer. Unlike memory-only buffering, when the ring buffer is full, Fluent Bit automatically drops the oldest chunks to make room for new data instead of pausing the input plugin. Use this mode in scenarios where you want to keep the most recent data and can tolerate loss of older data. When chunks are dropped, Fluent Bit tracks the number of dropped chunks and bytes through the `memrb_dropped_chunks` and `memrb_dropped_bytes` metrics. You can monitor these metrics to understand how much data is being discarded. This buffering method prioritizes continuous data ingestion over data completeness, making it suitable for high-throughput scenarios where pausing the input isn't acceptable. ## Configuration settings {% hint style="info" %} For information about different strategies for managing backpressure, see [Backpressure](../administration/backpressure.md). {% endhint %} Use the information in this section to configure buffering settings in Fluent Bit. Global settings configure the storage layer, per-input settings define which buffering mechanism to use, and per-output settings define limits for the logical filesystem queues. ### Global settings In the [`service` section](../administration/configuring-fluent-bit/yaml/service-section.md) of Fluent Bit configuration files, several settings related to buffering are stored in the [`storage` key](../administration/configuring-fluent-bit/yaml/service-section.md#storage-configuration). These are global settings that affect all input and output plugins. To set a default buffering mode for all input plugins, configure `storage.type` and enable `storage.inherit` in the `service` section. Input plugins that don't explicitly set their own `storage.type` will inherit the global value. The following example sets filesystem buffering as the default for all inputs, while allowing individual inputs to override the default: {% tabs %} {% tab title="fluent-bit.yaml" %} ```yaml service: flush: 1 log_level: info storage.path: /var/log/flb-storage/ storage.type: filesystem storage.inherit: on storage.sync: normal storage.max_chunks_up: 128 pipeline: inputs: - name: cpu # Inherits storage.type: filesystem from service - name: mem # Overrides the inherited default storage.type: memory ``` {% endtab %} {% tab title="fluent-bit.conf" %} ```text [SERVICE] Flush 1 Log_Level info Storage.Path /var/log/flb-storage/ Storage.Type filesystem Storage.Inherit on Storage.Sync normal Storage.Max_Chunks_Up 128 [INPUT] Name cpu # Inherits storage.type: filesystem from SERVICE [INPUT] Name mem # Overrides the inherited default Storage.Type memory ``` {% endtab %} {% endtabs %} ### Per-input settings You can configure buffering settings for any input plugin by using these configuration parameters: | Key | Description | Default | | :--- | :--- | :--- | | `mem_buf_limit` | Sets a limit for how much buffered data the plugin can write to memory. With memory-only buffering, the plugin pauses until more memory becomes available after this limit is reached. With memory ring buffer (`memrb`) buffering, the oldest chunks are dropped to make room for new data instead of pausing. This value must follow [unit size](../administration/configuring-fluent-bit.md#unit-sizes) specifications. If unspecified, no limit is enforced. | `0` | | `rate_gate` | Enables input rate gate control, which pauses ingestion for this input plugin once it exceeds the byte or record rate limits set with `rate_gate.max_bytes` and `rate_gate.max_records`. | `false` | | `rate_gate.backpressure` | When `rate_gate` is enabled, factors existing retry, busy-chunk, and [throttle](../administration/scheduling-and-retries.md#throttling) cooldown pressure into the effective rate limit instead of relying only on `rate_gate.max_bytes` and `rate_gate.max_records`. | `true` | | `rate_gate.max_bytes` | When `rate_gate` is enabled, sets the maximum input byte rate per second before ingestion is paused. This value must follow [unit size](../administration/configuring-fluent-bit.md#unit-sizes) specifications. A value of `0` means no byte-rate limit. | `0` | | `rate_gate.max_records` | When `rate_gate` is enabled, sets the maximum input record rate per second before ingestion is paused. A value of `0` means no record-rate limit. | `0` | | `rate_gate.resume_ratio` | When `rate_gate` is enabled, sets the hysteresis threshold, as a ratio of the configured limits, that the measured rate must fall under before ingestion resumes. If both `rate_gate.max_bytes` and `rate_gate.max_records` are configured, both measured rates must fall under their respective resume thresholds before ingestion resumes, regardless of which limit originally triggered the pause. | `0.80` | | `rate_window` | Sets the time window used to compute this input's byte and record ingestion rate. The computed rate is always published in per-second units, regardless of the window used to measure it. | `1s` | | `storage.pause_on_chunks_overlimit` | If filesystem buffering is enabled, specifies how the input plugin should behave after the global `storage.max_chunks_up` limit is reached. When set to `off`, the plugin will stop buffering data to memory but continue buffering data to the filesystem. When set to `on`, the plugin will stop both memory buffering and filesystem buffering until more memory becomes available. Possible values: `on`, `off`. | `off` | | `storage.type` | Specifies the buffering mechanism to use for this input plugin. To enable filesystem buffering, a global [`storage.path`](../administration/configuring-fluent-bit/yaml/service-section.md#storage-configuration) value must be set in the `service` section of your configuration file. When set to `memrb`, Fluent Bit uses a memory ring buffer that automatically drops the oldest chunks when the buffer is full to make room for new data. Accepted values: `memory`, `filesystem`, `memrb`. | `memory` | `rate_gate` is available in Fluent Bit version 5.1 and greater. The following configuration example enables the rate gate on an input plugin. Ingestion pauses whenever the input exceeds 5 MB per second or 10,000 records per second, and resumes once both the byte rate and the record rate fall back to 80% of their respective limits: {% tabs %} {% tab title="fluent-bit.yaml" %} ```yaml pipeline: inputs: - name: forward rate_window: 1s rate_gate: true rate_gate.max_bytes: 5M rate_gate.max_records: 10000 rate_gate.resume_ratio: 0.80 ``` {% endtab %} {% tab title="fluent-bit.conf" %} ```text [INPUT] Name forward Rate_Window 1s Rate_Gate true Rate_Gate.Max_Bytes 5M Rate_Gate.Max_Records 10000 Rate_Gate.Resume_Ratio 0.80 ``` {% endtab %} {% endtabs %} The following configuration example sets global settings in `service` to support filesystem buffering, then configures input plugins with filesystem buffering, memory-only buffering, and memory ring buffer buffering: {% tabs %} {% tab title="fluent-bit.yaml" %} ```yaml service: flush: 1 log_level: info storage.path: /var/log/flb-storage/ storage.sync: normal storage.checksum: off storage.max_chunks_up: 128 storage.backlog.mem_limit: 5M pipeline: inputs: - name: cpu storage.type: filesystem - name: mem storage.type: memory - name: dummy storage.type: memrb mem_buf_limit: 10M ``` {% endtab %} {% tab title="fluent-bit.conf" %} ```text [SERVICE] Flush 1 Log_Level info Storage.Path /var/log/flb-storage/ Storage.Sync normal Storage.Checksum off Storage.Max_Chunks_Up 128 Storage.Backlog.Mem_Limit 5M [INPUT] Name cpu Storage.Type filesystem [INPUT] Name mem Storage.Type memory [INPUT] Name dummy Storage.Type memrb Mem_Buf_Limit 10M ``` {% endtab %} {% endtabs %} ### Per-output settings If any active input plugins use filesystem buffering, you can limit how many chunks are buffered to the filesystem based on the output plugin where Fluent Bit intends to route that chunk. To do so, use this configuration parameter: | Key | Description | Default | | :--- | :--- | :--- | | `storage.total_limit_size` | Sets the size of the queue for this output plugin. This queue is the number of chunks buffered to the filesystem with this output as the intended destination. If the output plugin reaches its `storage.total_limit_size` capacity, the oldest chunk from its queue will be discarded to make room for new data. This value must follow [unit size](../administration/configuring-fluent-bit.md#unit-sizes) specifications. | _none_ | The following configuration example creates records with CPU usage samples in the filesystem which are delivered to Google Stackdriver service while limiting the logical queue to `5M`: {% tabs %} {% tab title="fluent-bit.yaml" %} ```yaml service: flush: 1 log_level: info storage.path: /var/log/flb-storage/ storage.sync: normal storage.checksum: off storage.max_chunks_up: 128 storage.backlog.mem_limit: 5M pipeline: inputs: - name: cpu storage.type: filesystem outputs: - name: stackdriver match: '*' storage.total_limit_size: 5M ``` {% endtab %} {% tab title="fluent-bit.conf" %} ```text [SERVICE] Flush 1 Log_Level info Storage.Path /var/log/flb-storage/ Storage.Sync normal Storage.Checksum off Storage.Max_Chunks_Up 128 Storage.Backlog.Mem_Limit 5M [INPUT] Name cpu Storage.Type filesystem [OUTPUT] Name stackdriver Match * Storage.Total_Limit_Size 5M ``` {% endtab %} {% endtabs %} In this example, if Fluent Bit is offline because of a network issue, it will continue buffering CPU samples, keeping a maximum of 5 MB of the newest data.