수평 자동 확장을 사용하면 Dataflow가 작업에 적절한 작업자 인스턴스 수를 선택하고 필요에 따라 작업자를 추가하거나 삭제합니다.
Dataflow는 작업자의 평균 CPU 사용률과 파이프라인 동시 로드에 따라 확장됩니다. 파이프라인 동시 로드는 지정된 시간에 데이터를 가장 효율적으로 처리하는 데 필요한 스레드 예측 수입니다.
수평 자동 확장은 일괄 파이프라인과 스트리밍 파이프라인 모두에서 지원됩니다.
일괄 자동 확장
기본적으로 수평 자동 확장은 모든 일괄 파이프라인에서 사용 설정되어 있습니다.
Dataflow는 파이프라인의 각 단계에서 예상되는 총 작업량을 기반으로 작업자 수를 자동으로 선택합니다. 이 예상치는 입력 크기와 현재 처리량에 따라 달라집니다. Dataflow는 30초마다 실행 진행 상황에 따라 작업량을 재평가합니다. 총 예상 작업량이 증가하거나 감소하게 되면 Dataflow는 작업자 수를 동적으로 확장하거나 축소합니다.
작업자 수는 작업량에 저선형적입니다. 예를 들어 작업량은 두 배인데 작업자 수는 두 배보다 적은 작업입니다.
다음과 같은 조건이 발생하면 Dataflow는 유휴 리소스를 절약하기 위해 작업자 수를 유지하거나 줄입니다.
평균 작업자 CPU 사용량이 5% 미만입니다.
동시 로드는 압축 파일로 인한 분할할 수 없는 데이터 또는 분할되지 않은 I/O 모듈과 같은 동시 로드할 수 없는 작업으로 제한됩니다.
동시 로드 수는 고정되어 있습니다(예: Cloud Storage의 기존 파일에 쓰는 경우).
수평 자동 확장을 사용 중지하면 Dataflow는 --numWorkers 옵션에 따라 작업자 수를 설정합니다.
Python
--autoscaling_algorithm=NONE
수평 자동 확장을 사용 중지하면 Dataflow는 --num_workers 옵션에 따라 작업자 수를 설정합니다.
Go
--autoscaling_algorithm=NONE
수평 자동 확장을 사용 중지하면 Dataflow는 --num_workers 옵션에 따라 작업자 수를 설정합니다.
커스텀 소스
커스텀 데이터 소스를 만드는 경우 수평 자동 확장 알고리즘에 더 많은 정보를 제공하는 메서드를 구현하면 성능을 향상시킬 수 있습니다.
Java
제한된 소스
BoundedSource 서브클래스에서 getEstimatedSizeBytes 메서드를 구현합니다.
Dataflow 서비스는 파이프라인에 사용할 초기 작업자 수를 계산할 때 getEstimatedSizeBytes을 사용합니다.
BoundedReader 서브클래스에서 getFractionConsumed 메서드를 구현합니다.
Dataflow 서비스는 getFractionConsumed를 사용하여 읽기 진행 상황을 추적하고 읽는 중에 사용할 올바른 작업자 수를 수렴합니다.
바인딩되지 않은 소스
소스는 Dataflow 서비스에 백로그에 대한 정보를 제공해야 합니다.
백로그는 소스에서 아직 처리하지 않은 입력 추정치(바이트 단위)입니다. 서비스에 백로그에 관한 정보를 제공하려면 UnboundedReader 클래스에서 다음 메서드 두 개 중 하나를 구현합니다.
getSplitBacklogBytes() - 현재 소스 분할에 대한 백로그입니다. 서비스는 모든 분할에 걸쳐 백로그를 집계합니다.
getTotalBacklogBytes() - 모든 분할에 걸친 전체 백로그입니다. 각 분할에 대한 백로그가 제공되지 않고 모든 분할에 대해서만 계산할 수 있는 경우도 있습니다. 첫 번째 분할(분할 ID '0')만 전체 백로그를 제공해야 합니다.
Apache Beam 저장소에는 UnboundedReader 클래스를 구현하는 여러 가지 커스텀 소스 예시가 있습니다.
Python
제한된 소스
BoundedSource 서브클래스에서 estimate_size 메서드를 구현합니다. Dataflow 서비스는 파이프라인에 사용할 초기 작업자 수를 계산할 때 estimate_size을 사용합니다.
RangeTracker 서브클래스에서 fraction_consumed 메서드를 구현합니다.
Dataflow 서비스는 fraction_consumed를 사용하여 읽기 진행 상황을 추적하고 읽는 중에 사용할 올바른 작업자 수를 수렴합니다.
Go
제한된 소스
RangeTracker에서 GetProgress() 메서드를 구현합니다. Dataflow 서비스는 GetProgress을 사용하여 읽기 진행 상황을 추적하고 읽기 작업에 사용할 올바른 작업자 수를 수렴합니다.
제한사항
Dataflow Prime을 실행하는 작업에서 수평 자동 확장은 수직 자동 확장을 수행하는 동안 그리고 그 이후 최대 10분 동안 비활성화됩니다. 자세한 내용은 수평 자동 확장에 대한 영향을 참조하세요.
Dataflow Shuffle을 사용하지 않는 파이프라인의 경우 작업자가 로컬 디스크에 저장된 데이터를 셔플했을 수 있으므로 Dataflow가 작업자를 효과적으로 축소하지 못할 수 있습니다.
PeriodicImpulse 변환은 Apache Beam SDK 버전 2.60.0 이상에서 스트리밍 자동 확장과 함께 지원됩니다. 파이프라인에서 이전 SDK 버전과 함께 PeriodicImpulse를 사용하는 경우 Dataflow 작업자가 예상한 대로 축소되지 않습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-06-03(UTC)"],[[["\u003cp\u003eHorizontal Autoscaling in Dataflow dynamically adjusts the number of worker instances for both batch and streaming pipelines based on CPU utilization and pipeline parallelism.\u003c/p\u003e\n"],["\u003cp\u003eBatch pipelines have Horizontal Autoscaling enabled by default, where Dataflow automatically re-evaluates work and scales workers every 30 seconds, sublinearly to the amount of work needed, with limitations to save idle resources.\u003c/p\u003e\n"],["\u003cp\u003eFor streaming jobs, Horizontal Autoscaling is enabled by default for pipelines using Streaming Engine, but for those that do not, the \u003ccode\u003e--autoscalingAlgorithm=THROUGHPUT_BASED\u003c/code\u003e and \u003ccode\u003e--maxNumWorkers\u003c/code\u003e pipeline options need to be set to enable the feature.\u003c/p\u003e\n"],["\u003cp\u003eCustom data sources can improve Horizontal Autoscaling performance by implementing specific methods to provide the Dataflow service with information about estimated size, progress, or backlog.\u003c/p\u003e\n"],["\u003cp\u003eHorizontal Autoscaling can be disabled by using the \u003ccode\u003e--autoscalingAlgorithm=NONE\u003c/code\u003e pipeline option, which will cause the number of workers to be based on the \u003ccode\u003e--numWorkers\u003c/code\u003e option, additionally there are limitations when it comes to the Dataflow Prime, Dataflow Shuffle and PeriodicImpulse.\u003c/p\u003e\n"]]],[],null,["# Horizontal Autoscaling enables Dataflow to choose the appropriate\nnumber of worker instances for your job, adding or removing workers as needed.\nDataflow scales based on the average CPU utilization of the\nworkers and on the parallelism of a pipeline. The parallelism of a pipeline is\nan estimate of the number of threads needed to most efficiently process data at\nany given time.\n\nHorizontal Autoscaling is supported in both batch and streaming pipelines.\n\nBatch autoscaling\n-----------------\n\nHorizontal Autoscaling is enabled by default on all batch pipelines.\nDataflow automatically chooses the number of workers based on the\nestimated total amount of work in each stage of your pipeline. This estimate\ndepends on the input size and the current throughput. Every 30 seconds,\nDataflow re-evaluates the amount of work according to the\nexecution progress. As the estimated total amount of work increases or\ndecreases, Dataflow dynamically scales the number of workers up or\ndown.\n\nThe number of workers is sublinear to the amount of work. For example, a job\nwith twice the work has fewer than twice the workers.\n\nIf any of the following conditions occur, Dataflow either\nmaintains or decreases the number of workers, in order to save idle resources:\n\n- The average worker CPU usage is lower than 5%.\n- Parallelism is limited due to unparallelizable work, such as un-splittable data caused by compressed files or I/O modules that don't split.\n- The degree of parallelism is fixed, for example when writing to existing files in Cloud Storage.\n\nTo set an upper bound on the number of workers, set the\n[`--maxNumWorkers` pipeline option](/dataflow/docs/reference/pipeline-options).\nThe default value is `2,000`.\nTo set a lower bound on the number of workers, set the\n[`--dataflow-service-options=min_num_workers` service option](/dataflow/docs/reference/service-options).\nThese flags are optional.\n\nStreaming autoscaling\n---------------------\n\nFor streaming jobs, Horizontal Autoscaling allows Dataflow to\nadaptively change the number of workers in response to changes in load and\nresource utilization.\n\nHorizontal Autoscaling is enabled by default for streaming jobs that use\n[Streaming Engine](/dataflow/docs/streaming-engine).\nTo enable Horizontal Autoscaling for streaming jobs that don't use\nStreaming Engine, set the following\n[pipeline options](/dataflow/docs/reference/pipeline-options) when you start\nyour pipeline: \n\n### Java\n\n --autoscalingAlgorithm=THROUGHPUT_BASED\n --maxNumWorkers=\u003cvar translate=\"no\"\u003eMAX_WORKERS\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eMAX_WORKERS\u003c/var\u003e with the maximum number of worker\ninstances.\n\n### Python\n\n --autoscaling_algorithm=THROUGHPUT_BASED\n --max_num_workers=\u003cvar translate=\"no\"\u003eMAX_WORKERS\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eMAX_WORKERS\u003c/var\u003e with the maximum number of worker\ninstances.\n\n### Go\n\n --autoscaling_algorithm=THROUGHPUT_BASED\n --max_num_workers=\u003cvar translate=\"no\"\u003eMAX_WORKERS\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eMAX_WORKERS\u003c/var\u003e with the maximum number of worker\ninstances.\n\nTo set a lower bound on the number of workers, set the\n[`--dataflow-service-options=min_num_workers` service option](/dataflow/docs/reference/service-options).\nWhen you set this value, horizontal autoscaling doesn't scale below the number\nof workers specified. This flag is optional.\n\nWhile a streaming job is running, you can update the minimum and maximum workers\nby using an\n[in-flight job update](/dataflow/docs/guides/updating-a-pipeline#in-flight-updates).\nTo adjust the settings, set the `min-num-workers` and `max-num-workers` flags.\nFor more information, see\n[Update the autoscaling range](/dataflow/docs/guides/tune-horizontal-autoscaling#update-range).\n\nDisable Horizontal Autoscaling\n------------------------------\n\nTo disable Horizontal Autoscaling, set the following\n[pipeline option](/dataflow/docs/reference/pipeline-options) when you run\nthe job. \n\n### Java\n\n --autoscalingAlgorithm=NONE\n\nIf you disable Horizontal Autoscaling, then Dataflow sets\nthe number of workers based on the `--numWorkers` option.\n\n### Python\n\n --autoscaling_algorithm=NONE\n\nIf you disable Horizontal Autoscaling, then Dataflow sets\nthe number of workers based on the `--num_workers` option.\n\n### Go\n\n --autoscaling_algorithm=NONE\n\nIf you disable Horizontal Autoscaling, then Dataflow sets\nthe number of workers based on the `--num_workers` option.\n\nCustom sources\n--------------\n\nIf you create a custom data source, you can potentially improve performance by\nimplementing methods that provide more information to the Horizontal Autoscaling\nalgorithm: \n\n### Java\n\n#### Bounded sources\n\n- In your `BoundedSource` subclass, implement the method `getEstimatedSizeBytes`. The Dataflow service uses `getEstimatedSizeBytes` when calculating the initial number of workers to use for your pipeline.\n- In your `BoundedReader` subclass, implement the method `getFractionConsumed`. The Dataflow service uses `getFractionConsumed` to track read progress and converge on the correct number of workers to use during a read.\n\n#### Unbounded sources\n\nThe source must inform the Dataflow service about backlog.\nBacklog is an estimate of the input in bytes that has not yet been processed\nby the source. To inform the service about backlog, implement either one of\nthe following methods in your `UnboundedReader` class.\n\n- `getSplitBacklogBytes()` - Backlog for the current split of the source. The service aggregates backlog across all the splits.\n- `getTotalBacklogBytes()` - The global backlog across all the splits. In some cases the backlog is not available for each split and can only be calculated across all the splits. Only the first split (split ID '0') needs to provide total backlog.\n\nThe Apache Beam repository contains several\n[examples](https://github.com/apache/beam/blob/master/sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaUnboundedReader.java)\nof custom sources that implement the `UnboundedReader` class.\n\n### Python\n\n#### Bounded sources\n\n- In your `BoundedSource` subclass, implement the method `estimate_size`. The Dataflow service uses `estimate_size` when calculating the initial number of workers to use for your pipeline.\n- In your `RangeTracker` subclass, implement the method `fraction_consumed`. The Dataflow service uses `fraction_consumed` to track read progress and converge on the correct number of workers to use during a read.\n\n### Go\n\n#### Bounded sources\n\n- In your `RangeTracker`, implement the method `GetProgress()`. The Dataflow service uses `GetProgress` to track read progress and converge on the correct number of workers to use during a read.\n\nLimitations\n-----------\n\n- In jobs running Dataflow Prime, Horizontal Autoscaling is deactivated during and up to 10 minutes after Vertical Autoscaling. For more information, see [Effect on Horizontal Autoscaling](/dataflow/docs/vertical-autoscaling#horizontal-autoscaling).\n- For pipelines not using [Dataflow Shuffle](/dataflow/docs/shuffle-for-batch), Dataflow might not be able to scale down the workers effectively because the workers might have shuffled data stored in local disks.\n- The [PeriodicImpulse](https://beam.apache.org/releases/javadoc/current/org/apache/beam/sdk/transforms/PeriodicImpulse.html) transform is supported with streaming autoscaling in the Apache Beam SDK versions 2.60.0 and later. If your pipeline uses `PeriodicImpulse` with an earlier SDK version, then Dataflow workers don't scale down as expected.\n\nWhat's next\n-----------\n\n- [Tune Horizontal Autoscaling for streaming pipelines](/dataflow/docs/guides/tune-horizontal-autoscaling)\n- [Monitor Dataflow autoscaling](/dataflow/docs/guides/autoscaling-metrics)\n- [Troubleshoot Dataflow autoscaling](/dataflow/docs/guides/troubleshoot-autoscaling)"]]