Blazer-007 commented on code in PR #4087:
URL: https://github.com/apache/gobblin/pull/4087#discussion_r1890186796


##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/ddm/activity/impl/RecommendScalingForWorkUnitsLinearHeuristicImpl.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.temporal.ddm.activity.impl;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.runtime.JobState;
+import org.apache.gobblin.temporal.GobblinTemporalConfigurationKeys;
+import org.apache.gobblin.temporal.ddm.work.TimeBudget;
+import org.apache.gobblin.temporal.ddm.work.WorkUnitsSizeSummary;
+import org.apache.gobblin.temporal.ddm.worker.WorkFulfillmentWorker;
+
+
+/**
+ * Simple config-driven linear relationship between `remainingWork` and the 
resulting `setPoint`
+ *
+ *
+ * TODO: describe algo!!!!!
+ */
+@Slf4j
+public class RecommendScalingForWorkUnitsLinearHeuristicImpl extends 
AbstractRecommendScalingForWorkUnitsImpl {
+
+  public static final String AMORTIZED_NUM_BYTES_PER_MINUTE = 
GobblinTemporalConfigurationKeys.PREFIX + 
"dynamic.scaling.reference.numBytesPerMinute";
+  public static final long DEFAULT_AMORTIZED_NUM_BYTES_PER_MINUTE = 10 * 1000L 
* 1000L * 60L; // 10MB/sec
+
+  @Override
+  protected int calcDerivationSetPoint(WorkUnitsSizeSummary remainingWork, 
String sourceClass, TimeBudget timeBudget, JobState jobState) {
+    // for simplicity, for now, consider only top-level work units (aka. 
`MultiWorkUnit`s - MWUs)
+    long numMWUs = remainingWork.getTopLevelWorkUnitsCount();
+    double meanBytesPerMWU = remainingWork.getTopLevelWorkUnitsMeanSize();
+    int numSimultaneousMWUsPerContainer = 
calcPerContainerWUCapacity(jobState); // (a worker-thread is a slot for 
top-level (MWUs) - not constituent sub-WUs)
+    long bytesPerMinuteProcRate = calcAmortizedBytesPerMinute(jobState);
+    log.info("Calculating auto-scaling (for {} remaining work units within {}) 
using: bytesPerMinuteProcRate = {}; meanBytesPerMWU = {}",
+        numMWUs, timeBudget, bytesPerMinuteProcRate, meanBytesPerMWU);
+
+    // calc how many container*minutes to process all MWUs, based on mean MWU 
size
+    double minutesProcTimeForMeanMWU = meanBytesPerMWU / 
bytesPerMinuteProcRate;
+    double meanMWUsThroughputPerContainerMinute = 
numSimultaneousMWUsPerContainer / minutesProcTimeForMeanMWU;
+    double estContainerMinutesForAllMWUs = numMWUs / 
meanMWUsThroughputPerContainerMinute;
+
+    long targetNumMinutes = timeBudget.getMaxDurationDesiredMinutes();
+    // TODO: take into account `timeBudget.getPermittedOverageMinutes()` - 
e.g. to decide whether to use `Math.ceil` vs. `Math.floor`

Review Comment:
   can we please name it something different or just a comment indicating it is 
desiredMinutes for one MWU or maybe add comment/javadoc in TImeBudget class 
itself ?



##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/ddm/activity/impl/RecommendScalingForWorkUnitsLinearHeuristicImpl.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.temporal.ddm.activity.impl;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.runtime.JobState;
+import org.apache.gobblin.temporal.GobblinTemporalConfigurationKeys;
+import org.apache.gobblin.temporal.ddm.work.TimeBudget;
+import org.apache.gobblin.temporal.ddm.work.WorkUnitsSizeSummary;
+import org.apache.gobblin.temporal.ddm.worker.WorkFulfillmentWorker;
+
+
+/**
+ * Simple config-driven linear relationship between `remainingWork` and the 
resulting `setPoint`
+ *
+ *
+ * TODO: describe algo!!!!!
+ */
+@Slf4j
+public class RecommendScalingForWorkUnitsLinearHeuristicImpl extends 
AbstractRecommendScalingForWorkUnitsImpl {
+
+  public static final String AMORTIZED_NUM_BYTES_PER_MINUTE = 
GobblinTemporalConfigurationKeys.PREFIX + 
"dynamic.scaling.reference.numBytesPerMinute";

Review Comment:
   can we please use `GobblinTemporalConfigurationKeys.DYNAMIC_SCALING_PREFIX` 
here directly ?



##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/ddm/workflow/impl/ExecuteGobblinWorkflowImpl.java:
##########
@@ -154,6 +198,35 @@ protected ProcessWorkUnitsWorkflow 
createProcessWorkUnitsWorkflow(Properties job
     return Workflow.newChildWorkflowStub(ProcessWorkUnitsWorkflow.class, 
childOpts);
   }
 
+  protected TimeBudget calcWUProcTimeBudget(Instant jobStartTime, 
WorkUnitsSizeSummary wuSizeSummary, Properties jobProps) {
+    // TODO: make configurable!  for now, aim for:
+    //  - total job runtime of 2 hours
+    //  - at least 15 minutes for the `CommitStepWorkflow`
+    //  - leave at least 1 hour for the `ProcessWorkUnitsWorkflow` (so deduct 
at most 45 minutes for WU generation thus far)
+    long totalTimeMins = 120;
+    long maxGenWUsMins = 45;
+    long commitStepMins = 15;
+    double permittedOveragePercentage = .2;
+    Duration genWUsDuration = Duration.between(jobStartTime, 
TemporalEventTimer.getCurrentTime());
+    long remainingMins = totalTimeMins - Math.min(genWUsDuration.toMinutes(), 
maxGenWUsMins) - commitStepMins;
+    return TimeBudget.withOveragePercentage(remainingMins, 
permittedOveragePercentage);
+  }
+
+  protected List<ScalingDirective> 
adjustRecommendedScaling(List<ScalingDirective> recommendedScalingDirectives) {
+    // TODO: make any adjustments - e.g. decide whether to shutdown the (often 
oversize) `GenerateWorkUnits` worker or alternatively to deduct one to count it
+    if (recommendedScalingDirectives.size() == 0) {
+      return recommendedScalingDirectives;
+    }
+    // TODO: be more robust and code more defensively, rather than presuming 
the impl of `RecommendScalingForWorkUnitsLinearHeuristicImpl`
+    ArrayList<ScalingDirective> adjustedScaling = new 
ArrayList<>(recommendedScalingDirectives);
+    ScalingDirective firstDirective = adjustedScaling.get(0);
+    // deduct one for the (already existing) `GenerateWorkUnits` worker
+    adjustedScaling.set(0, 
firstDirective.updateSetPoint(firstDirective.getSetPoint() - 1));

Review Comment:
   maybe worth adding one more line comment here something similar that this 
deduction is also based on assumption that firstDirective configs (memory size) 
are exactly equal to initial configs



##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/ddm/workflow/impl/ExecuteGobblinWorkflowImpl.java:
##########
@@ -154,6 +198,35 @@ protected ProcessWorkUnitsWorkflow 
createProcessWorkUnitsWorkflow(Properties job
     return Workflow.newChildWorkflowStub(ProcessWorkUnitsWorkflow.class, 
childOpts);
   }
 
+  protected TimeBudget calcWUProcTimeBudget(Instant jobStartTime, 
WorkUnitsSizeSummary wuSizeSummary, Properties jobProps) {
+    // TODO: make configurable!  for now, aim for:
+    //  - total job runtime of 2 hours
+    //  - at least 15 minutes for the `CommitStepWorkflow`
+    //  - leave at least 1 hour for the `ProcessWorkUnitsWorkflow` (so deduct 
at most 45 minutes for WU generation thus far)
+    long totalTimeMins = 120;
+    long maxGenWUsMins = 45;
+    long commitStepMins = 15;
+    double permittedOveragePercentage = .2;
+    Duration genWUsDuration = Duration.between(jobStartTime, 
TemporalEventTimer.getCurrentTime());
+    long remainingMins = totalTimeMins - Math.min(genWUsDuration.toMinutes(), 
maxGenWUsMins) - commitStepMins;
+    return TimeBudget.withOveragePercentage(remainingMins, 
permittedOveragePercentage);
+  }
+
+  protected List<ScalingDirective> 
adjustRecommendedScaling(List<ScalingDirective> recommendedScalingDirectives) {
+    // TODO: make any adjustments - e.g. decide whether to shutdown the (often 
oversize) `GenerateWorkUnits` worker or alternatively to deduct one to count it
+    if (recommendedScalingDirectives.size() == 0) {
+      return recommendedScalingDirectives;
+    }
+    // TODO: be more robust and code more defensively, rather than presuming 
the impl of `RecommendScalingForWorkUnitsLinearHeuristicImpl`
+    ArrayList<ScalingDirective> adjustedScaling = new 
ArrayList<>(recommendedScalingDirectives);
+    ScalingDirective firstDirective = adjustedScaling.get(0);
+    // deduct one for the (already existing) `GenerateWorkUnits` worker
+    adjustedScaling.set(0, 
firstDirective.updateSetPoint(firstDirective.getSetPoint() - 1));

Review Comment:
   maybe worth adding one more line comment here something similar that this 
deduction is also based on assumption that firstDirective configs (memory size) 
are exactly equal to initial configs



##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/ddm/activity/impl/AbstractRecommendScalingForWorkUnitsImpl.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.temporal.ddm.activity.impl;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.Properties;
+
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.runtime.JobState;
+import org.apache.gobblin.temporal.ddm.activity.RecommendScalingForWorkUnits;
+import org.apache.gobblin.temporal.ddm.work.TimeBudget;
+import org.apache.gobblin.temporal.ddm.work.WorkUnitsSizeSummary;
+import org.apache.gobblin.temporal.dynamic.ProfileDerivation;
+import org.apache.gobblin.temporal.dynamic.ProfileOverlay;
+import org.apache.gobblin.temporal.dynamic.ScalingDirective;
+import org.apache.gobblin.temporal.dynamic.WorkforceProfiles;
+
+
+/**
+ * Skeletal impl handling all foundational concerns, but leaving it to a 
concrete impl to actually choose the auto-scaling
+ * {@link ScalingDirective#getSetPoint()} for the exactly one {@link 
ScalingDirective} being recommended.
+ */
+@Slf4j
+public abstract class AbstractRecommendScalingForWorkUnitsImpl implements 
RecommendScalingForWorkUnits {
+
+  // TODO: decide whether this name ought to be configurable - or instead a 
predictable name that callers may expect (and possibly adjust)
+  public static final String DEFAULT_PROFILE_DERIVATION_NAME = "workUnitsProc";
+
+  @Override
+  public List<ScalingDirective> recommendScaling(WorkUnitsSizeSummary 
remainingWork, String sourceClass, TimeBudget timeBudget, Properties jobProps) {
+    // NOTE: no attempt to determine the current scaling - per 
`RecommendScalingForWorkUnits` javadoc, the `ScalingDirective`(s) returned must 
"stand alone",
+    // presuming nothing of the current `WorkforcePlan`'s `WorkforceStaffing`
+    JobState jobState = new JobState(jobProps);
+    ScalingDirective procWUsWorkerScaling = new ScalingDirective(
+        calcProfileDerivationName(jobState),
+        calcDerivationSetPoint(remainingWork, sourceClass, timeBudget, 
jobState),
+        System.currentTimeMillis(),
+        Optional.of(calcProfileDerivation(calcBasisProfileName(jobState), 
remainingWork, sourceClass, jobState))
+    );
+    log.info("Recommended re-scaling to process work units: {}", 
procWUsWorkerScaling);
+    return Arrays.asList(procWUsWorkerScaling);
+  }
+
+  protected abstract int calcDerivationSetPoint(WorkUnitsSizeSummary 
remainingWork, String sourceClass, TimeBudget timeBudget, JobState jobState);
+
+  protected ProfileDerivation calcProfileDerivation(String basisProfileName, 
WorkUnitsSizeSummary remainingWork, String sourceClass, JobState jobState) {
+    // TODO: implement right-sizing!!! (for now just return unchanged)
+    return new ProfileDerivation(basisProfileName, ProfileOverlay.unchanged());
+  }
+
+  protected String calcProfileDerivationName(JobState jobState) {
+    // TODO: if we ever return > 1 directive, append a monotonically 
increasing number to avoid collisions
+    return DEFAULT_PROFILE_DERIVATION_NAME;
+  }
+
+  protected String calcBasisProfileName(JobState jobState) {
+    return WorkforceProfiles.BASELINE_NAME; // always build upon baseline
+  }

Review Comment:
   Is there anything we are getting out of JobState object in place of directly 
using jobProps or not using at all in `calcBasisProfileName`



##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/ddm/worker/WorkFulfillmentWorker.java:
##########
@@ -48,14 +49,14 @@ public WorkFulfillmentWorker(Config config, WorkflowClient 
workflowClient) {
 
     @Override
     protected Class<?>[] getWorkflowImplClasses() {
-        return new Class[] { CommitStepWorkflowImpl.class, 
ExecuteGobblinWorkflowImpl.class, GenerateWorkUnitsWorkflowImpl.class,
-            NestingExecOfProcessWorkUnitWorkflowImpl.class, 
ProcessWorkUnitsWorkflowImpl.class };
+        return new Class[] { ExecuteGobblinWorkflowImpl.class, 
ProcessWorkUnitsWorkflowImpl.class, 
NestingExecOfProcessWorkUnitWorkflowImpl.class,
+            CommitStepWorkflowImpl.class, GenerateWorkUnitsWorkflowImpl.class 
};
     }
 
     @Override
     protected Object[] getActivityImplInstances() {
-        return new Object[] { new CommitActivityImpl(), new 
DeleteWorkDirsActivityImpl(),new GenerateWorkUnitsImpl(),
-            new ProcessWorkUnitImpl(), new SubmitGTEActivityImpl()};
+        return new Object[] { new SubmitGTEActivityImpl(), new 
GenerateWorkUnitsImpl(), new RecommendScalingForWorkUnitsLinearHeuristicImpl(), 
new ProcessWorkUnitImpl(),
+            new CommitActivityImpl(), new DeleteWorkDirsActivityImpl() };

Review Comment:
   is there something to do with ordering here or its just preference based 
change specially `getWorkflowImplClasses()`



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to