You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content.zh/docs/operations/plugins.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -278,6 +278,92 @@ The following steps demonstrate how to develop and use a custom metric evaluator
278
278
o.a.f.a.s.AutoscalerUtils [INFO ] Discovered custom metric evaluator via ServiceLoader: org.apache.flink.autoscaler.custom.CustomEvaluator.
279
279
```
280
280
281
+
## Custom Parallelism Alignment Modes
282
+
283
+
The autoscaler aligns a vertex's computed target parallelism to the number of key groups (keyBy) or source partitions to reduce data skew. The built-in modes (`BALANCED`, `EVENLY_SPREAD`, `OFF`) are selected by name through `job.autoscaler.scaling.parallelism-alignment.mode`.A custom alignment mode can also be provided as a plugin by implementing the `ParallelismAlignmentMode` SPI. Custom modes are discovered through the [Plugins](https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/filesystems/plugins) mechanism when running inside the Kubernetes operator, and through the standard Java `ServiceLoader` mechanism when running with `flink-autoscaler-standalone`. In both cases the implementation class must be registered in `META-INF/services`.
284
+
285
+
All `job.autoscaler.*` keys related to custom alignment modes also support the legacy `kubernetes.operator.`-prefixed form as a fallback (for example, `kubernetes.operator.job.autoscaler.scaling.parallelism-alignment.mode`).The canonical key takes precedence on overlap.
286
+
287
+
The following steps demonstrate how to develop and use a custom alignment mode.
/** Apply to every vertex, not only the source and keyBy vertices the built-ins handle. */
297
+
@Override
298
+
publicbooleanisApplicable(Contextctx) {
299
+
returntrue;
300
+
}
301
+
302
+
@Override
303
+
publicintalign(Contextctx) {
304
+
// Number of key groups, or source partitions for a partitioned source.
305
+
int n = ctx.getNumSourcePartitions() >0
306
+
? ctx.getNumSourcePartitions()
307
+
: ctx.getMaxParallelism();
308
+
// Optional mode-specific parameter, read from the per-mode configuration.
309
+
int minParallelism = ctx.getModeConfiguration().getInteger("min-parallelism", 1);
310
+
for (int p = ctx.getNewParallelism(); p >= minParallelism; p--) {
311
+
if (n % p ==0) {
312
+
return p;
313
+
}
314
+
}
315
+
return ctx.getNewParallelism();
316
+
}
317
+
}
318
+
```
319
+
The `Context` exposes the current and computed target parallelism, the number of key groups or source partitions, the input ship strategies, the `JobAutoScalerContext`, the per-vertex evaluated metrics, the job topology, and the prefix-stripped per-mode `Configuration` (`getModeConfiguration()`).The autoscaler calls `align` only when `isApplicable(Context)` returns true. That method defaults to keyBy (hash) vertices and to partitioned sources that report a partition count (Kafka and Pulsardo by default), and a custom mode can override it to widen the scope, for example to align custom partitioned vertices.
320
+
321
+
2.Create the service definition file `org.apache.flink.autoscaler.alignment.ParallelismAlignmentMode` in `META-INF/services`:
3.Use the Maven tool to package the project and generate the custom alignment mode JAR.
327
+
328
+
4.Select the custom mode by name and point it at your implementation class. Any other `job.autoscaler.scaling.parallelism-alignment.mode.<name>.*` entries are passed to the mode (prefix-stripped) through `Context#getModeConfiguration()`:
The `<name>` is any identifier you choose. `custom-mode` is used here, but `CUSTOM_MODE` or any other style works just as well. It is matched exactly, including case, so the value of `scaling.parallelism-alignment.mode` and the `<name>` in `scaling.parallelism-alignment.mode.<name>.class` must be identical. As a result, `CUSTOM_MODE` and `custom-mode` are two different modes, not aliases. The only reserved names are the built-ins (`BALANCED`, `EVENLY_SPREAD`, `OFF`), which always resolve to the built-in modes regardless of any configured class.
336
+
{{</hint >}}
337
+
338
+
5.Deploy the mode.
339
+
340
+
-**Operator deployment**- create a Dockerfile to build a custom image from the `apache/flink-kubernetes-operator` official image and copy the generated JAR to a custom alignment mode plugin directory under `/opt/flink/plugins` (the value of the `FLINK_PLUGINS_DIR` environment variable in the flink-kubernetes-operator helm chart).The structure of the custom alignment mode directory under `/opt/flink/plugins` is as follows:
341
+
```text
342
+
/opt/flink/plugins
343
+
├── custom-alignment-mode
344
+
│ ├── custom-alignment-mode.jar
345
+
└── ...
346
+
```
347
+
348
+
With the custom alignment mode directory location, the Dockerfile is defined as follows:
Install the flink-kubernetes-operator helm chart with the custom image and verify the `deploy/flink-kubernetes-operator` log has:
358
+
```text
359
+
o.a.f.k.o.u.AutoscalerUtils [INFO ] Discovered custom alignment mode for autoscaler from plugin directory[/opt/flink/plugins]:org.apache.flink.autoscaler.alignment.CustomAlignmentMode.
360
+
```
361
+
362
+
-**Standalone autoscaler**- simply place the custom alignment mode JAR on the classpath of the `flink-autoscaler-standalone` process. It will be picked up automatically via Java's `ServiceLoader` and discovery will be logged:
363
+
```text
364
+
o.a.f.a.s.AutoscalerUtils [INFO ] Discovered custom alignment mode via ServiceLoader: org.apache.flink.autoscaler.alignment.CustomAlignmentMode.
365
+
```
366
+
281
367
## Custom Scaling Executors
282
368
283
369
`ScalingExecutorPlugin` is a pluggable component that allows users to intercept, modify, or veto computed scaling decisions before they are applied. Custom scaling executors are discovered through the [Plugins](https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/filesystems/plugins) mechanism when running inside the Kubernetes operator, and through the standard Java `ServiceLoader` mechanism when running with `flink-autoscaler-standalone`. In both cases the implementation class must be registered in `META-INF/services`.
Copy file name to clipboardExpand all lines: docs/content/docs/operations/plugins.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -278,6 +278,92 @@ The following steps demonstrate how to develop and use a custom metric evaluator
278
278
o.a.f.a.s.AutoscalerUtils [INFO ] Discovered custom metric evaluator via ServiceLoader: org.apache.flink.autoscaler.custom.CustomEvaluator.
279
279
```
280
280
281
+
## Custom Parallelism Alignment Modes
282
+
283
+
The autoscaler aligns a vertex's computed target parallelism to the number of key groups (keyBy) or source partitions to reduce data skew. The built-in modes (`BALANCED`, `EVENLY_SPREAD`, `OFF`) are selected by name through `job.autoscaler.scaling.parallelism-alignment.mode`.A custom alignment mode can also be provided as a plugin by implementing the `ParallelismAlignmentMode` SPI. Custom modes are discovered through the [Plugins](https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/filesystems/plugins) mechanism when running inside the Kubernetes operator, and through the standard Java `ServiceLoader` mechanism when running with `flink-autoscaler-standalone`. In both cases the implementation class must be registered in `META-INF/services`.
284
+
285
+
All `job.autoscaler.*` keys related to custom alignment modes also support the legacy `kubernetes.operator.`-prefixed form as a fallback (for example, `kubernetes.operator.job.autoscaler.scaling.parallelism-alignment.mode`).The canonical key takes precedence on overlap.
286
+
287
+
The following steps demonstrate how to develop and use a custom alignment mode.
/** Apply to every vertex, not only the source and keyBy vertices the built-ins handle. */
297
+
@Override
298
+
publicbooleanisApplicable(Contextctx) {
299
+
returntrue;
300
+
}
301
+
302
+
@Override
303
+
publicintalign(Contextctx) {
304
+
// Number of key groups, or source partitions for a partitioned source.
305
+
int n = ctx.getNumSourcePartitions() >0
306
+
? ctx.getNumSourcePartitions()
307
+
: ctx.getMaxParallelism();
308
+
// Optional mode-specific parameter, read from the per-mode configuration.
309
+
int minParallelism = ctx.getModeConfiguration().getInteger("min-parallelism", 1);
310
+
for (int p = ctx.getNewParallelism(); p >= minParallelism; p--) {
311
+
if (n % p ==0) {
312
+
return p;
313
+
}
314
+
}
315
+
return ctx.getNewParallelism();
316
+
}
317
+
}
318
+
```
319
+
The `Context` exposes the current and computed target parallelism, the number of key groups or source partitions, the input ship strategies, the `JobAutoScalerContext`, the per-vertex evaluated metrics, the job topology, and the prefix-stripped per-mode `Configuration` (`getModeConfiguration()`).The autoscaler calls `align` only when `isApplicable(Context)` returns true. That method defaults to keyBy (hash) vertices and to partitioned sources that report a partition count (Kafka and Pulsardo by default), and a custom mode can override it to widen the scope, for example to align custom partitioned vertices.
320
+
321
+
2.Create the service definition file `org.apache.flink.autoscaler.alignment.ParallelismAlignmentMode` in `META-INF/services`:
3.Use the Maven tool to package the project and generate the custom alignment mode JAR.
327
+
328
+
4.Select the custom mode by name and point it at your implementation class. Any other `job.autoscaler.scaling.parallelism-alignment.mode.<name>.*` entries are passed to the mode (prefix-stripped) through `Context#getModeConfiguration()`:
The `<name>` is any identifier you choose. `custom-mode` is used here, but `CUSTOM_MODE` or any other style works just as well. It is matched exactly, including case, so the value of `scaling.parallelism-alignment.mode` and the `<name>` in `scaling.parallelism-alignment.mode.<name>.class` must be identical. As a result, `CUSTOM_MODE` and `custom-mode` are two different modes, not aliases. The only reserved names are the built-ins (`BALANCED`, `EVENLY_SPREAD`, `OFF`), which always resolve to the built-in modes regardless of any configured class.
336
+
{{</hint >}}
337
+
338
+
5.Deploy the mode.
339
+
340
+
-**Operator deployment**- create a Dockerfile to build a custom image from the `apache/flink-kubernetes-operator` official image and copy the generated JAR to a custom alignment mode plugin directory under `/opt/flink/plugins` (the value of the `FLINK_PLUGINS_DIR` environment variable in the flink-kubernetes-operator helm chart).The structure of the custom alignment mode directory under `/opt/flink/plugins` is as follows:
341
+
```text
342
+
/opt/flink/plugins
343
+
├── custom-alignment-mode
344
+
│ ├── custom-alignment-mode.jar
345
+
└── ...
346
+
```
347
+
348
+
With the custom alignment mode directory location, the Dockerfile is defined as follows:
Install the flink-kubernetes-operator helm chart with the custom image and verify the `deploy/flink-kubernetes-operator` log has:
358
+
```text
359
+
o.a.f.k.o.u.AutoscalerUtils [INFO ] Discovered custom alignment mode for autoscaler from plugin directory[/opt/flink/plugins]:org.apache.flink.autoscaler.alignment.CustomAlignmentMode.
360
+
```
361
+
362
+
-**Standalone autoscaler**- simply place the custom alignment mode JAR on the classpath of the `flink-autoscaler-standalone` process. It will be picked up automatically via Java's `ServiceLoader` and discovery will be logged:
363
+
```text
364
+
o.a.f.a.s.AutoscalerUtils [INFO ] Discovered custom alignment mode via ServiceLoader: org.apache.flink.autoscaler.alignment.CustomAlignmentMode.
365
+
```
366
+
281
367
## Custom Scaling Executors
282
368
283
369
`ScalingExecutorPlugin` is a pluggable component that allows users to intercept, modify, or veto computed scaling decisions before they are applied. Custom scaling executors are discovered through the [Plugins](https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/filesystems/plugins) mechanism when running inside the Kubernetes operator, and through the standard Java `ServiceLoader` mechanism when running with `flink-autoscaler-standalone`. In both cases the implementation class must be registered in `META-INF/services`.
Copy file name to clipboardExpand all lines: docs/layouts/shortcodes/generated/auto_scaler_configuration.html
+18-6Lines changed: 18 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -218,6 +218,24 @@
218
218
<td>List<String></td>
219
219
<td>List of named custom scaling executors instances to register with the autoscaler. For each <name> entry, the implementation class to instantiate must be set via 'job.autoscaler.scaling.custom-executor.<name>.class', and additional per-instance options live under 'job.autoscaler.scaling.custom-executor.<name>.<parameter>'. Custom executors are executed in ascending order of their ScalingExecutorPlugin#priority() value, regardless of the order in which they appear in this list.</td>
<td>How the autoscaler aligns the parallelism of source vertices and keyBy (hash) vertices to the number of key groups or source partitions. One of the built-in modes (BALANCED reduces per-subtask load above the target, EVENLY_SPREAD aligns to an exact divisor for even data distribution, OFF disables alignment), or the name of a custom alignment mode whose class is configured via 'job.autoscaler.scaling.parallelism-alignment.mode.<name>.class'. Supersedes the deprecated scaling.key-group.partitions.adjust.mode.</td>
<td>An arbitrary parameter passed to the custom alignment mode named <name>. All such parameters are made available to the mode (with the prefix stripped) through Context.getModeConfiguration().</td>
<td>The fully-qualified class name of the custom alignment mode named <name>, discovered as a plugin and selectable via scaling.parallelism-alignment.mode=<name>.</td>
<td>How to adjust the parallelism of Source vertex or upstream shuffle is keyBy<br/><br/>Possible values:<ul><li>"EVENLY_SPREAD": This mode ensures that the parallelism adjustment attempts to evenly distribute data across subtasks. It is particularly effective for source vertices that are aware of partition counts or vertices after 'keyBy' operation. The goal is to have the number of key groups or partitions be divisible by the set parallelism, ensuring even data distribution and reducing data skew.</li><li>"MAXIMIZE_UTILISATION": This model is to maximize resource utilization. In this mode, an attempt is made to set the parallelism that meets the current consumption rate requirements. It is not enforced that the number of key groups or partitions is divisible by the parallelism.</li></ul></td>
Copy file name to clipboardExpand all lines: flink-autoscaler-standalone/src/main/java/org/apache/flink/autoscaler/standalone/StandaloneAutoscalerEntrypoint.java
0 commit comments