NXLog Agent buffering and flow control

NXLog Agent implements several log buffering features. Two of these are particularly important and enabled by default: log queues and flow control. In addition, stream-oriented modules use read and write buffers, which you can configure with module-level directives.

See Configure log buffering for examples of setting log queues and buffer sizes, managing flow control, and using other buffering functionality.

Log queues

Every processor and output module instance has an input log queue for events the instance has not yet processed. When the preceding module processes an event, it places it in this queue. Log queues are enabled by default for all processor and output module instances; adjusting log queue sizes is the preferred way to control buffering behavior.

gv log queues

Flow control

NXLog Agent’s flow control functionality provides automatic, zero-configuration handling of many cases where buffering would otherwise be required. Flow control takes effect when the following sequence of events occurs in a route:

  1. A processor or output module instance cannot process log events at the incoming rate.

  2. That module instance’s log queue becomes full.

  3. An input, processor, or output module instance has flow control enabled (the default).

In this case, flow control will cause the input or processor module instance to suspend processing until the succeeding instance is ready to accept more logs.

gv flow control 1

You can configure flow control settings per module instance. If two succeeding module instances in a route have conflicting flow control settings, disabled flow control takes precedence.

gv flow control 2

When a route contains multiple output instances, it is possible to turn off flow control for one output instance so that it will not suspend log processing for the entire route if it is blocked. In this case, the preceding input or processor module instance will continue to process logs and forward them to the output instances. The blocked output instance will discard events until it recovers.

gv flow control 3

Read and write buffers

Stream-oriented input and output modules, i.e., those connecting over the network (UDP, TCP, and HTTP) or reading and writing to files, use read/write buffers. You can control the buffer size with the BufferSize common module directive.

It is important to note that a module instance can create multiple buffers. Modules that receive or send data over the network, like *m_tcp and *m_http, create a buffer for each active connection. On the other hand, *m_file module instances create a buffer for each open file. The size you set with the BufferSize directive applies to each buffer. For example, the diagram below illustrates an im_file module instance collecting logs from three files. Therefore, it will create three read buffers of 65,000 bytes (the default) each, totaling 195 KB.

gv buffers per module

Use caution when defining the buffer size:

  • Avoid configurations that use large chunks of memory. Network modules can create an undefined number of connections, each with a read/write buffer of the size you specify. Similarly, a wildcard that matches many files and a large buffer is not a good combination when collecting logs with im_file. In such cases, consider using the ActiveFiles directive.

  • If a module receives data larger than the buffer size, it will truncate it and record an error in the NXLog Agent log file.

In addition to the above, some modules use other buffers specific to their functionality, as shown in the following table.

Module(s) Directive Default value

im_udp
om_udp
om_udpspoof

SockBufSize

OS default

xm_zlib

CompBufSize

16,384 bytes

xm_zlib

DecompBufSize

32,768 bytes

Other buffering functionality

In addition to the abovementioned functionality, several NXLog Agent modules implement specialized buffering features, such as the ones listed below.

The following diagram shows all buffers used in a simple route. The socket buffers only apply to network-based modules.

NXLog Agent buffers in a basic route
Figure 1. NXLog Agent buffers in a basic route