Skip to content

Commit 948056a

Browse files
authored
Merge pull request #413 from daipom/1.0-add-multiple-workers-configuration
Add multiple workers config for both traditional and yaml
2 parents 611bc69 + 235285e commit 948056a

File tree

2 files changed

+130
-4
lines changed

2 files changed

+130
-4
lines changed

configuration/config-file-yaml.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Normal Fluentd configuration syntax has the following the list of directives:
2222
3. **`filter`** directives determine the event processing pipelines
2323
4. **`system`** directives set system-wide configuration
2424
5. **`label`** directives group the output and filter for internal routing
25-
6. **`@include`** directives include other files
25+
6. **`worker`** directives limit to the specific workers
26+
7. **`@include`** directives include other files
2627

2728
In YAML configuration world, we reconstructed them for YAML format.
2829

@@ -240,7 +241,68 @@ The `@ROOT` label is a builtin label used for getting root router by plugin's `e
240241

241242
This label is introduced since v1.14.0 to assign a label back to the default route. For example, timed-out event records are handled by the concat filter can be sent to the default route.
242243

243-
## 6. Reuse your config: the `!include` YAML tag
244+
## 6. Limit to specific workers: the `worker` element
245+
246+
When setting up multiple workers, you can use the **worker** element to limit plugins to run on specific workers.
247+
248+
This is useful for input and output plugins that do not support multiple workers.
249+
250+
You can use the `$arg N` or `$arg N-M` to specify workers. The number is a zero-based worker index.
251+
252+
See [Multi Process Workers](../deployment/multi-process-workers.md) article for details about multiple workers.
253+
254+
Here is a configuration example:
255+
256+
```text
257+
system:
258+
workers: 4
259+
260+
config:
261+
- source:
262+
$type: sample
263+
tag: test.allworkers
264+
sample: "{\"message\": \"Run with all workers.\"}"
265+
266+
- worker:
267+
$arg: 0
268+
config:
269+
- source:
270+
$type: sample
271+
tag: test.oneworker
272+
sample: "{\"message\": \"Run with only worker-0.\"}"
273+
274+
- worker:
275+
$arg: 0-1
276+
config:
277+
- source:
278+
$type: sample
279+
tag: test.someworkers
280+
sample: "{\"message\": \"Run with worker-0 and worker-1.\"}"
281+
282+
- filter:
283+
$type: record_transformer
284+
$tag: test.**
285+
record:
286+
worker_id: !fluent/s "#{worker_id}"
287+
288+
- match:
289+
$type: stdout
290+
$tag: test.**
291+
```
292+
293+
The outputs of this config are as follows:
294+
295+
```text
296+
... test.allworkers: {"message":"Run with all workers.","worker_id":"0"}
297+
... test.allworkers: {"message":"Run with all workers.","worker_id":"1"}
298+
... test.allworkers: {"message":"Run with all workers.","worker_id":"2"}
299+
... test.allworkers: {"message":"Run with all workers.","worker_id":"3"}
300+
... test.oneworker: {"message":"Run with only worker-0.","worker_id":"0"}
301+
... test.someworkers: {"message":"Run with worker-0 and worker-1.","worker_id":"0"}
302+
... test.someworkers: {"message":"Run with worker-0 and worker-1.","worker_id":"1"}
303+
```
304+
305+
## 7. Reuse your config: the `!include` YAML tag
244306

245307
The element in separate configuration files can be imported using the **!include** element:
246308

configuration/config-file.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ The configuration file consists of the following directives:
6060
3. **`filter`** directives determine the event processing pipelines
6161
4. **`system`** directives set system-wide configuration
6262
5. **`label`** directives group the output and filter for internal routing
63-
6. **`@include`** directives include other files
63+
6. **`worker`** directives limit to the specific workers
64+
7. **`@include`** directives include other files
6465

6566
Let's actually create a configuration file step by step.
6667

@@ -280,7 +281,70 @@ The `@ROOT` label is a builtin label used for getting root router by plugin's `e
280281

281282
This label is introduced since v1.14.0 to assign a label back to the default route. For example, timed-out event records are handled by the concat filter can be sent to the default route.
282283

283-
## 6. Reuse your config: the `@include` directive
284+
## 6. Limit to specific workers: the `worker` directive
285+
286+
When setting up multiple workers, you can use the **worker** directive to limit plugins to run on specific workers.
287+
288+
This is useful for input and output plugins that do not support multiple workers.
289+
290+
You can use the `<worker N>` or `<worker N-M>` directives to specify workers. The number is a zero-based worker index.
291+
292+
See [Multi Process Workers](../deployment/multi-process-workers.md) article for details about multiple workers.
293+
294+
Here is a configuration example:
295+
296+
```text
297+
<system>
298+
workers 4
299+
</system>
300+
301+
<source>
302+
@type sample
303+
tag test.allworkers
304+
sample {"message": "Run with all workers."}
305+
</source>
306+
307+
<worker 0>
308+
<source>
309+
@type sample
310+
tag test.oneworker
311+
sample {"message": "Run with only worker-0."}
312+
</source>
313+
</worker>
314+
315+
<worker 0-1>
316+
<source>
317+
@type sample
318+
tag test.someworkers
319+
sample {"message": "Run with worker-0 and worker-1."}
320+
</source>
321+
</worker>
322+
323+
<filter test.**>
324+
@type record_transformer
325+
<record>
326+
worker_id "#{worker_id}"
327+
</record>
328+
</filter>
329+
330+
<match test.**>
331+
@type stdout
332+
</match>
333+
```
334+
335+
The outputs of this config are as follows:
336+
337+
```text
338+
... test.allworkers: {"message":"Run with all workers.","worker_id":"0"}
339+
... test.allworkers: {"message":"Run with all workers.","worker_id":"1"}
340+
... test.allworkers: {"message":"Run with all workers.","worker_id":"2"}
341+
... test.allworkers: {"message":"Run with all workers.","worker_id":"3"}
342+
... test.oneworker: {"message":"Run with only worker-0.","worker_id":"0"}
343+
... test.someworkers: {"message":"Run with worker-0 and worker-1.","worker_id":"0"}
344+
... test.someworkers: {"message":"Run with worker-0 and worker-1.","worker_id":"1"}
345+
```
346+
347+
## 7. Reuse your config: the `@include` directive
284348

285349
The directives in separate configuration files can be imported using the **@include** directive:
286350

0 commit comments

Comments
 (0)