Skip to content

Commit 18fa318

Browse files
committed
pipeline: input: tail: add more details about buffering and memory management
Signed-off-by: Eduardo Silva <[email protected]>
1 parent bc06cfa commit 18fa318

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

pipeline/inputs/tail.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,40 @@ The plugin supports the following configuration parameters:
3838
| `File_Cache_Advise` | Set the `posix_fadvise` in `POSIX_FADV_DONTNEED` mode. This reduces the usage of the kernel file cache. This option is ignored if not running on Linux. | `On` |
3939
| `Threaded` | Indicates whether to run this input in its own [thread](../../administration/multithreading.md#inputs). | `false` |
4040

41+
## Buffers and memory management
42+
43+
The Tail plugin uses buffers to efficiently read and process log files. Understanding how these buffers work helps optimize memory usage and performance.
44+
45+
### File buffers vs Fluent Bit chunks
46+
47+
When a file is opened for monitoring, the Tail plugin allocates a buffer in memory of `buffer_chunk_size` bytes (defaults to 32KB). This buffer is used to read data from the file. If a single record (line) is longer than `buffer_chunk_size`, the buffer will grow up to `buffer_max_size` to accommodate it.
48+
49+
> **Note:** These buffers are per-file. If you're monitoring many files, each file gets its own buffer, which can significantly increase memory usage.
50+
51+
### From buffers to chunks
52+
53+
Inside each file buffer, multiple lines/records might exist. The plugin processes these records and converts them to msgpack format (binary serialization). This msgpack data is then appended to what Fluent Bit calls a **Chunk** - a collection of serialized records that belong to the same tag.
54+
55+
While Fluent Bit has a soft limit of 2MB for chunks, input plugins like Tail can generate msgpack buffers larger than 2MB, and the final chunk can exceed this soft limit.
56+
57+
### Memory protection with `mem_buf_limit`
58+
59+
If Fluent Bit is not configured to use filesystem buffering, it needs mechanisms to protect against high memory consumption during backpressure scenarios (e.g., when destination endpoints are down or network issues occur). The `mem_buf_limit` option restricts how much memory in chunks an input plugin can use.
60+
61+
When filesystem buffering is enabled, memory management works differently. For more details, see [Buffering and Storage](../../administration/buffering-and-storage.md).
62+
63+
## Database file
64+
4165
{% hint style="info" %}
42-
If the database parameter `DB` isn't specified, by default the plugin reads each target file from the beginning. This might cause unwanted behavior. For example, when a line is bigger than `Buffer_Chunk_Size` and `Skip_Long_Lines` isn't turned on, the file will be read from the beginning of each `Refresh_Interval` until the file is rotated.
66+
**File positioning behavior:**
67+
68+
- **With database file**: The plugin restores the last known position (offset) from the database. If no previous position exists and `read_from_head` is false, it starts monitoring from the end of the file.
69+
70+
- **Without database file**:
71+
- If `read_from_head` is true: The plugin reads from the beginning of the file
72+
- If `read_from_head` is false: The plugin starts monitoring from the end of the file (classic "tail" behavior)
73+
74+
This means that without a database and with `read_from_head` set to false, only new content written after Fluent Bit starts will be monitored.
4375
{% endhint %}
4476

4577
## Monitor a large number of files

0 commit comments

Comments
 (0)