gobblin-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (GOBBLIN-762) Add automatic scaling for Gobblin on YARN
Date Wed, 08 May 2019 20:19:00 GMT

     [ https://issues.apache.org/jira/browse/GOBBLIN-762?focusedWorklogId=239460&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-239460
]

ASF GitHub Bot logged work on GOBBLIN-762:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/May/19 20:18
            Start Date: 08/May/19 20:18
    Worklog Time Spent: 10m 
      Work Description: htran1 commented on pull request #2626: [GOBBLIN-762] Add automatic
scaling for Gobblin on YARN
URL: https://github.com/apache/incubator-gobblin/pull/2626#discussion_r281870422
 
 

 ##########
 File path: gobblin-yarn/src/main/java/org/apache/gobblin/yarn/YarnAutoScalingManager.java
 ##########
 @@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.yarn;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import org.apache.helix.HelixManager;
+import org.apache.helix.task.JobContext;
+import org.apache.helix.task.JobDag;
+import org.apache.helix.task.TaskDriver;
+import org.apache.helix.task.TaskState;
+import org.apache.helix.task.WorkflowConfig;
+import org.apache.helix.task.WorkflowContext;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.AbstractIdleService;
+import com.typesafe.config.Config;
+
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.util.ConfigUtils;
+import org.apache.gobblin.util.ExecutorsUtils;
+
+
+/**
+ * The autoscaling manager is responsible for figuring out how many containers are required
for the workload and
+ * requesting the {@link YarnService} to request that many containers.
+ */
+@Slf4j
+public class YarnAutoScalingManager extends AbstractIdleService {
+  private final String AUTO_SCALING_PREFIX = GobblinYarnConfigurationKeys.GOBBLIN_YARN_PREFIX
+ "autoScaling.";
+  private final String AUTO_SCALING_POLLING_INTERVAL_SECS =
+      AUTO_SCALING_PREFIX + "pollingIntervalSeconds";
+  private final int DEFAULT_AUTO_SCALING_POLLING_INTERVAL_SECS = 60;
+  // Only one container will be requested for each N partitions of work
+  private final String AUTO_SCALING_PARTITIONS_PER_CONTAINER = AUTO_SCALING_PREFIX + "partitionsPerContainer";
+  private final int DEFAULT_AUTO_SCALING_PARTITIONS_PER_CONTAINER = 1;
+
+  private final Config config;
+  private final HelixManager helixManager;
+  private final ScheduledExecutorService autoScalingExecutor;
+  private final YarnService yarnService;
+  private final int partitionsPerContainer;
+
+  public YarnAutoScalingManager(GobblinApplicationMaster appMaster) {
+    this.config = appMaster.getConfig();
+    this.helixManager = appMaster.getMultiManager().getJobClusterHelixManager();
+    this.yarnService = appMaster.getYarnService();
+    this.partitionsPerContainer = ConfigUtils.getInt(this.config, AUTO_SCALING_PARTITIONS_PER_CONTAINER,
+        DEFAULT_AUTO_SCALING_PARTITIONS_PER_CONTAINER);
+
+    Preconditions.checkArgument(this.partitionsPerContainer > 0,
+        AUTO_SCALING_PARTITIONS_PER_CONTAINER + " needs to be greater than 0");
+
+    this.autoScalingExecutor = Executors.newSingleThreadScheduledExecutor(
+        ExecutorsUtils.newThreadFactory(Optional.of(log), Optional.of("AutoScalingExecutor")));
+  }
+
+  @Override
+  protected void startUp() throws Exception {
+    int scheduleInterval = ConfigUtils.getInt(this.config, AUTO_SCALING_POLLING_INTERVAL_SECS,
+        DEFAULT_AUTO_SCALING_POLLING_INTERVAL_SECS);
+    log.info("Starting the " + YarnAutoScalingManager.class.getSimpleName());
+    log.info("Scheduling the auto scaling task with an interval of {} seconds", scheduleInterval);
+
+    this.autoScalingExecutor.scheduleAtFixedRate(new YarnAutoScalingRunnable(new TaskDriver(this.helixManager),
+            this.yarnService, this.partitionsPerContainer), 0,
+        scheduleInterval, TimeUnit.SECONDS);
+  }
+
+  @Override
+  protected void shutDown() throws Exception {
+    log.info("Stopping the " + YarnAutoScalingManager.class.getSimpleName());
+
+    ExecutorsUtils.shutdownExecutorService(this.autoScalingExecutor, Optional.of(log));
+  }
+
+  /**
+   * A {@link Runnable} that figures out the number of containers required for the workload
+   * and requests those containers.
+   */
+  @VisibleForTesting
+  @AllArgsConstructor
+  static class YarnAutoScalingRunnable implements Runnable {
+    private final TaskDriver taskDriver;
+    private final YarnService yarnService;
+    private final int partitionsPerContainer;
+
+    /**
+     * Iterate through the workflows configured in Helix to figure out the number of required
partitions
+     * and request the {@link YarnService} to scale to the desired number of containers.
+     */
+    @Override
+    public void run() {
+      Set<String> inUseInstances = new HashSet<>();
+
+      int numPartitions = 0;
+      for (Map.Entry<String, WorkflowConfig> workFlowEntry : taskDriver.getWorkflows().entrySet())
{
+        WorkflowContext workflowContext = taskDriver.getWorkflowContext(workFlowEntry.getKey());
+
+        // Only allocate for active workflows
+        if (workflowContext == null || !workflowContext.getWorkflowState().equals(TaskState.IN_PROGRESS))
{
+          continue;
+        }
+
+        log.debug("Workflow name {} config {} context {}", workFlowEntry.getKey(), workFlowEntry.getValue(),
+            workflowContext);
+
+        WorkflowConfig workflowConfig = workFlowEntry.getValue();
+        JobDag jobDag = workflowConfig.getJobDag();
+
+        Set<String> jobs = jobDag.getAllNodes();
+
+        // sum up the number of partitions
+        for (String jobName : jobs) {
+          JobContext jobContext = taskDriver.getJobContext(jobName);
+
+          if (jobContext != null) {
+            log.debug("JobContext {} num partitions {}", jobContext, jobContext.getPartitionSet().size());
+
+            inUseInstances.addAll(jobContext.getPartitionSet().stream().map(jobContext::getAssignedParticipant)
 
 Review comment:
   It is already multi-lined after the .filter(...). The .filter(...) is on a new line and
the indented by 4 as a continuation line.
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 239460)

> Add automatic scaling for Gobblin on YARN
> -----------------------------------------
>
>                 Key: GOBBLIN-762
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-762
>             Project: Apache Gobblin
>          Issue Type: Task
>            Reporter: Hung Tran
>            Priority: Major
>          Time Spent: 3h
>  Remaining Estimate: 0h
>
> Gobblin on YARN needs a way to scale up and down the containers based on the workload.
> Added `YarnAutoScalingManager` which can be started by the `GobblinApplicationMaster`
by setting the `gobblin.yarn.app.master.serviceClasses` configuration. This class runs a scheduled
task with a default interval of 60 seconds to detect the number of required partitions for
the workflows submitted to Helix. It will request the `YarnService` to scale to a computed
number of containers. If the requested number of containers is higher than the YarnService
has previously requested then it will request more containers. If the requested count is less
than the current number of allocated containers then it will free any unused containers.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message