1996fanrui commented on code in PR #22985: URL: https://github.com/apache/flink/pull/22985#discussion_r1361748211
########## flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Executing.java: ########## @@ -124,23 +158,70 @@ private void handleDeploymentFailure(ExecutionVertex executionVertex, JobExcepti @Override public void onNewResourcesAvailable() { - maybeRescale(); + rescaleWhenCooldownPeriodIsOver(); } @Override public void onNewResourceRequirements() { - maybeRescale(); + rescaleWhenCooldownPeriodIsOver(); + } + + /** Force rescaling as long as the target parallelism is different from the current one. */ + private void forceRescale() { + if (context.shouldRescale(getExecutionGraph(), true)) { + getLogger() + .info( + "Added resources are still there after {} time({}), force a rescale.", + JobManagerOptions.SCHEDULER_SCALING_INTERVAL_MAX.key(), + scalingIntervalMax); + context.goToRestarting( + getExecutionGraph(), + getExecutionGraphHandler(), + getOperatorCoordinatorHandler(), + Duration.ofMillis(0L), + getFailures()); + } } + /** + * Rescale the job if {@link Context#shouldRescale} is true. Otherwise, force a rescale using + * {@link Executing#forceRescale()} after {@link + * JobManagerOptions#SCHEDULER_SCALING_INTERVAL_MAX}. + */ private void maybeRescale() { - if (context.shouldRescale(getExecutionGraph())) { - getLogger().info("Can change the parallelism of job. Restarting job."); + rescaleScheduled = false; + if (context.shouldRescale(getExecutionGraph(), false)) { + getLogger().info("Can change the parallelism of the job. Restarting the job."); context.goToRestarting( getExecutionGraph(), getExecutionGraphHandler(), getOperatorCoordinatorHandler(), Duration.ofMillis(0L), getFailures()); + } else if (scalingIntervalMax != null) { + getLogger() + .info( + "The longer the pipeline runs, the more the (small) resource gain is worth the restarting time. " + + "Last resource added does not meet {}, force a rescale after {} time({}) if the resource is still there.", + JobManagerOptions.MIN_PARALLELISM_INCREASE, + JobManagerOptions.SCHEDULER_SCALING_INTERVAL_MAX.key(), + scalingIntervalMax); + // schedule a force rescale in JobManagerOptions.SCHEDULER_SCALING_INTERVAL_MAX time + context.runIfState(this, this::forceRescale, scalingIntervalMax); + } Review Comment: Thanks for the update! ########## flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Executing.java: ########## @@ -124,23 +158,70 @@ private void handleDeploymentFailure(ExecutionVertex executionVertex, JobExcepti @Override public void onNewResourcesAvailable() { - maybeRescale(); + rescaleWhenCooldownPeriodIsOver(); } @Override public void onNewResourceRequirements() { - maybeRescale(); + rescaleWhenCooldownPeriodIsOver(); + } + + /** Force rescaling as long as the target parallelism is different from the current one. */ + private void forceRescale() { + if (context.shouldRescale(getExecutionGraph(), true)) { + getLogger() + .info( + "Added resources are still there after {} time({}), force a rescale.", + JobManagerOptions.SCHEDULER_SCALING_INTERVAL_MAX.key(), + scalingIntervalMax); + context.goToRestarting( + getExecutionGraph(), + getExecutionGraphHandler(), + getOperatorCoordinatorHandler(), + Duration.ofMillis(0L), + getFailures()); + } } + /** + * Rescale the job if {@link Context#shouldRescale} is true. Otherwise, force a rescale using + * {@link Executing#forceRescale()} after {@link + * JobManagerOptions#SCHEDULER_SCALING_INTERVAL_MAX}. + */ private void maybeRescale() { - if (context.shouldRescale(getExecutionGraph())) { - getLogger().info("Can change the parallelism of job. Restarting job."); + rescaleScheduled = false; + if (context.shouldRescale(getExecutionGraph(), false)) { + getLogger().info("Can change the parallelism of the job. Restarting the job."); context.goToRestarting( getExecutionGraph(), getExecutionGraphHandler(), getOperatorCoordinatorHandler(), Duration.ofMillis(0L), getFailures()); + } else if (scalingIntervalMax != null) { + getLogger() + .info( + "The longer the pipeline runs, the more the (small) resource gain is worth the restarting time. " + + "Last resource added does not meet {}, force a rescale after {} time({}) if the resource is still there.", + JobManagerOptions.MIN_PARALLELISM_INCREASE, + JobManagerOptions.SCHEDULER_SCALING_INTERVAL_MAX.key(), + scalingIntervalMax); + // schedule a force rescale in JobManagerOptions.SCHEDULER_SCALING_INTERVAL_MAX time + context.runIfState(this, this::forceRescale, scalingIntervalMax); + } Review Comment: Thanks for the update! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org