Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions deployment/multi-process-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,78 @@ As of Fluentd v1.4.0, `<worker N-M>` syntax has been introduced:

With this directive, you can specify multiple workers per worker directive.

### Sections inside and outside `<worker>` directives

A configuration can have `<source>`, `<filter>`, `<match>` and `<label>` sections both inside and outside `<worker>` directives. In this case, each worker loads the configuration as follows:

* The sections outside `<worker>` directives are loaded in every worker.
* The sections inside a `<worker>` directive are loaded only in the workers specified by the directive.
* The sections inside `<worker>` directives are placed **after** all the sections outside them, regardless of where the `<worker>` directives are written in the configuration file.

The last point matters because `<filter>` and `<match>` sections are evaluated in the resulting order, which can differ from the order written in the configuration file, and an event goes to the first matching `<match>` section \(see [Note on Match Order](../configuration/config-file.md#note-on-match-order)\). So, a `<match>` section outside `<worker>` directives takes precedence over a `<match>` section inside a `<worker>` directive when both of them match the tag, even if the `<worker>` directive is written first. In the same way, a `<filter>` section inside a `<worker>` directive is not applied to the events which a `<match>` section outside `<worker>` directives takes.

In the following example, the events from `in_sample` on worker 0 go to `<match app.**>`, not to `<match app.access>`:

```text
<system>
workers 2
</system>

<worker 0>
<source>
@type sample
tag app.access
</source>

# never used: <match app.**> below is evaluated first
<match app.access>
@type file
path /var/log/fluent/access
</match>
</worker>

<match app.**>
@type stdout
</match>
```

To send the events of a `<source>` inside a `<worker>` directive to a `<match>` inside the same directive, give them a tag which no `<match>` section outside `<worker>` directives matches, or route the events to a `<label>` section with `@label`:

```text
<system>
workers 2
</system>

<worker 0>
<source>
@type sample
tag app.access
@label @ACCESS
</source>

<label @ACCESS>
<match app.access>
@type file
path /var/log/fluent/access
</match>
</label>
</worker>

<match app.**>
@type stdout
</match>
```

At startup, the supervisor checks the sections of all `<worker>` directives together, although each worker runs only the sections for it. So, to copy this `<worker 0>` directive for worker 1, change the copy to `<worker 1>` and make the following changes in it. Without them, Fluentd or the copied worker fails to start.

* Change the label name in both `@label` and `<label>`, for example to `@ACCESS1`.
* Change the `path` of the file output, for example to `/var/log/fluent/access1`. In this example, the file output also uses this value as its buffer path.
* If the plugins have `@id`, change them too.

If the workers can share the same sections, use one `<worker N-M>` directive such as `<worker 0-1>` instead.

A `<source>` section outside `<worker>` directives also runs in every worker. For example, if it is an input plugin which shares its port between workers such as `in_forward`, every worker accepts events on the port. See [Input Plugin](#input-plugin) section.
Comment thread
Watson1978 marked this conversation as resolved.
Resolved

## Operation

Each worker consumes memory and disk space separately. Take care while configuring buffer spaces and monitoring memory/disk consumption.
Expand Down