Networking

    A common use case is when a component or plugin needs to connect to a service to send and receive data. Despite the operational mode sounds easy to deal with, there are many factors that can make things hard like unresponsive services, networking latency or any kind of connectivity error. The networking interface aims to abstract and simplify the network I/O handling, minimize risks and optimize performance.

    Most of the time creating a new TCP connection to a remote server is straightforward and takes a few milliseconds. But there are cases where DNS resolving, slow network or incomplete TLS handshakes might create long delays, or incomplete connection statuses.

    The allows to configure the maximum time to wait for a connection to be established, note that this value already considers the TLS handshake process.

    TCP Source Address

    On environments with multiple network interfaces, might be desired to choose which interface to use for our data that will flow through the network.

    The net.source_address allows to specify which network address must be used for a TCP connection and data flow.

    Connection Keepalive

    TCP is a connected oriented channel, to deliver and receive data from a remote end-point in most of cases we use a TCP connection. This TCP connection can be created and destroyed once is not longer needed, this approach has pros and cons, here we will refer to the opposite case: keep the connection open.

    The concept of Connection Keepalive refers to the ability of the client (Fluent Bit on this case) to keep the TCP connection open in a persistent way, that means that once the connection is created and used, instead of close it, it can be recycled. This feature offers many benefits in terms of performance since communication channels are always established before hand.

    If a connection is keepalive enabled, there might be scenarios where the connection can be unused for long periods of time. Having an idle keepalive connection is not helpful and is recommendable to keep them alive if they are used.

    In order to control how long a keepalive connection can be idle, we expose the configuration property called net.keepalive_idle_timeout.

    TCP Keepalive

    An open TCP connection to a remote server is subject to be silently dropped by intermediate equipment in the network (e.g., routers) if it’s quiet for too long. What too long means depends on manufacturers and configurations outside of the control of fluentbit.

    If you’re using the Connection Keepalive feature, but not achieving the desired connectivity rates, you might want to try setting net.tcp_keepalive to on. This will configure the socket to periodically send keepalive probes if the connection is silent. These probes will be sent all the way to the server, making the equipment in between consider the connection as active. Is then expected that the server will acknowledge the probe, allowing fluentbit to detect a broken connection right away.

    TCP Keepalive Time

    If TCP keepalive is used, net.tcp_keepalive_time allows to override the OS default configuration with the desired period to wait between the last data packet is sent and TCP keepalive probing starts.

    If TCP keepalive is used, allows to override the OS default configuration with the desired period between probes if the first one fails to be acknowledged.

    TCP Keepalive Probes

    If TCP keepalive is used, net.tcp_keepalive_probes allows to override the OS default configuration with the desired number of unacknowledged probes before deeming a connection dead.

    TCP Keepalive Recycling

    For plugins that rely on networking I/O, the following section describes the network configuration properties available and how they can be used to optimize performance or adjust to different configuration needs:

    As an example, we will send 5 random messages through a TCP output connection, in the remote side we will use nc (netcat) utility to see the data.

    Put the following configuration snippet in a file called fluent-bit.conf:

    In another terminal, start nc and make it listen for messages on TCP port 9090:

    Now start Fluent Bit with the configuration file written above and you will see the data flowing to netcat:

    If the net.keepalive option is not enabled, Fluent Bit will close the TCP connection and netcat will quit, here we can see how the keepalive connection works.

    After the 5 records arrive, the connection will keep idle and after 10 seconds it will be closed due to .