-
Notifications
You must be signed in to change notification settings - Fork 104
feat(amber): Add Basic Ramen Support for UDF Operators #3674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yunyad
wants to merge
2
commits into
apache:main
Choose a base branch
from
yunyad:yunyad-basic-ramen-pr-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
197 changes: 197 additions & 0 deletions
197
...i/ics/amber/engine/architecture/scheduling/resourcePolicies/GreedyResourceAllocator.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| /* | ||
| * 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 edu.uci.ics.amber.engine.architecture.scheduling.resourcePolicies | ||
|
|
||
| import edu.uci.ics.amber.config.ApplicationConfig | ||
| import edu.uci.ics.amber.core.storage.DocumentFactory | ||
| import edu.uci.ics.amber.core.tuple.Tuple | ||
| import edu.uci.ics.amber.core.workflow._ | ||
| import edu.uci.ics.amber.engine.architecture.scheduling.Region | ||
| import edu.uci.ics.amber.engine.architecture.scheduling.config._ | ||
| import edu.uci.ics.amber.util.VirtualIdentityUtils | ||
| import edu.uci.ics.texera.dao.SqlServer | ||
| import edu.uci.ics.texera.dao.SqlServer.withTransaction | ||
| import edu.uci.ics.texera.dao.jooq.generated.Tables.{WORKFLOW_EXECUTIONS, WORKFLOW_VERSION} | ||
|
|
||
| import java.net.URI | ||
| import scala.collection.mutable | ||
|
|
||
| class GreedyResourceAllocator( | ||
| physicalPlan: PhysicalPlan, | ||
| executionClusterInfo: ExecutionClusterInfo, | ||
| workflowSettings: WorkflowSettings, | ||
| workflowContext: WorkflowContext | ||
| ) extends ResourceAllocator { | ||
|
|
||
| // a map of a physical link to the partition info of the upstream/downstream of this link | ||
| private val linkPartitionInfos = new mutable.HashMap[PhysicalLink, PartitionInfo]() | ||
|
|
||
| private val operatorConfigs = new mutable.HashMap[PhysicalOpIdentity, OperatorConfig]() | ||
| private val linkConfigs = new mutable.HashMap[PhysicalLink, LinkConfig]() | ||
|
|
||
| /** | ||
| * Allocates resources for a given region and its operators. | ||
| * | ||
| * This method calculates and assigns worker configurations for each operator | ||
| * in the region. | ||
| * For the operators that are parallelizable, it respects the | ||
| * suggested worker number if provided. | ||
| * Non-parallelizable operators are assigned a single worker. | ||
| * For parallelizable operators without suggestions, the slowest operator | ||
| * is assigned with one more worker. | ||
| * Automatic adjustment will not result the total number of workers exceeds | ||
| * configured core to worker ratio * configured cpu cores. | ||
| * @param region The region for which to allocate resources. | ||
| * @return A tuple containing: | ||
| * 1) A new Region instance with new resource configuration. | ||
| * 2) An estimated cost of the workflow with the new resource configuration, | ||
| * represented as a Double value (currently set to 0, but will be | ||
| * updated in the future). | ||
| */ | ||
| def allocate( | ||
| region: Region | ||
| ): (Region, Double) = { | ||
| val statsOpt = getOperatorExecutionStats(this.workflowContext.workflowId.id) | ||
| val maxWorkerUpperBound = executionClusterInfo.availableNumberOfCores * executionClusterInfo.coreToWorkerRatio | ||
| val operatorList = region.getOperators | ||
|
|
||
| val opToOperatorConfigMapping: Map[PhysicalOpIdentity, OperatorConfig] = statsOpt match { | ||
|
|
||
| case Some(stats) => | ||
| val opToWorkerList = mutable.HashMap[PhysicalOpIdentity, List[WorkerConfig]]() | ||
|
|
||
| val greedyCandidates = operatorList.filter(op => | ||
| op.parallelizable && op.suggestedWorkerNum.isEmpty && stats.contains(op.id.logicalOpId.id) | ||
| ) | ||
|
|
||
| val slowestOpIdStrOpt = | ||
| greedyCandidates | ||
| .flatMap(op => stats.get(op.id.logicalOpId.id).map { case (rt, _) => op.id.logicalOpId.id -> rt }) | ||
| .maxByOption(_._2) | ||
| .map(_._1) | ||
|
|
||
| val basicWorkerCounts: Map[PhysicalOpIdentity, Int] = operatorList.map { op => | ||
| val opIdStr = op.id.logicalOpId.id | ||
| val baseCount = | ||
| if (!op.parallelizable) 1 | ||
| else if (op.suggestedWorkerNum.isDefined) op.suggestedWorkerNum.get | ||
| else if (stats.contains(opIdStr)) stats(opIdStr)._2 | ||
| else ApplicationConfig.numWorkerPerOperatorByDefault | ||
| op.id -> baseCount | ||
| }.toMap | ||
|
|
||
| val currentTotal = basicWorkerCounts.values.sum | ||
|
|
||
| val addingAllowed = slowestOpIdStrOpt.isDefined && currentTotal + 1 <= maxWorkerUpperBound | ||
|
|
||
| operatorList.foreach { op => | ||
| val opIdStr = op.id.logicalOpId.id | ||
| val basicWorkerCount = basicWorkerCounts(op.id) | ||
| val updatedWorkerCount = | ||
| if (addingAllowed && slowestOpIdStrOpt.contains(opIdStr)) basicWorkerCount + 1 else basicWorkerCount | ||
| val workers = (0 until updatedWorkerCount).map { idx => | ||
| WorkerConfig( | ||
| VirtualIdentityUtils.createWorkerIdentity(op.workflowId, op.id, idx) | ||
| ) | ||
| }.toList | ||
| opToWorkerList(op.id) = workers | ||
| } | ||
|
|
||
| opToWorkerList.map { | ||
| case (opId, workerList) => opId -> OperatorConfig(workerList) | ||
| }.toMap | ||
|
|
||
| case None => | ||
| region.getOperators | ||
| .map(op => op.id -> OperatorConfig(WorkerConfig.generateDefaultWorkerConfigs(op))) | ||
| .toMap | ||
| } | ||
|
|
||
| operatorConfigs ++= opToOperatorConfigMapping | ||
|
|
||
| val updatedLinkPartitionInfos = propagatePartitionRequirement(region, physicalPlan, operatorConfigs.toMap, linkPartitionInfos.toMap) | ||
|
|
||
| linkPartitionInfos ++= updatedLinkPartitionInfos | ||
|
|
||
| val linkToLinkConfigMapping = | ||
| getLinkConfigs(region, operatorConfigs.toMap, linkPartitionInfos.toMap, workflowSettings) | ||
|
|
||
| linkConfigs ++= linkToLinkConfigMapping | ||
|
|
||
| val portConfigs: Map[GlobalPortIdentity, PortConfig] = getPortConfigs(region, operatorConfigs.toMap, workflowSettings) | ||
|
|
||
| val resourceConfig = ResourceConfig( | ||
| opToOperatorConfigMapping, | ||
| linkToLinkConfigMapping, | ||
| portConfigs | ||
| ) | ||
|
|
||
| (region.copy(resourceConfig = Some(resourceConfig)), 0) | ||
| } | ||
|
|
||
| private def getOperatorExecutionStats(wid: Long): Option[Map[String, (Double, Int)]] = { | ||
| val uriOpt: Option[String] = | ||
| withTransaction(SqlServer.getInstance().createDSLContext()) { context => | ||
| val row = context | ||
| .select(WORKFLOW_EXECUTIONS.RUNTIME_STATS_URI) | ||
| .from(WORKFLOW_EXECUTIONS) | ||
| .join(WORKFLOW_VERSION) | ||
| .on(WORKFLOW_EXECUTIONS.VID.eq(WORKFLOW_VERSION.VID)) | ||
| .where( | ||
| WORKFLOW_VERSION.WID.eq(wid.toInt) | ||
| .and(WORKFLOW_EXECUTIONS.STATUS.eq(3.toByte)) // 成功状态 | ||
| ) | ||
| .orderBy(WORKFLOW_EXECUTIONS.STARTING_TIME.desc()) | ||
| .limit(1) | ||
| .fetchOne() | ||
|
|
||
| Option(row).map(_.get(WORKFLOW_EXECUTIONS.RUNTIME_STATS_URI)) | ||
| } | ||
|
|
||
| uriOpt.flatMap { uriStr => | ||
| if (uriStr == null || uriStr.trim.isEmpty) { | ||
| None | ||
| } else { | ||
| val stats = readStatsFromUri(uriStr) | ||
| if (stats.isEmpty) None else Some(stats) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private def readStatsFromUri(uriStr: String): Map[String, (Double, Int)] = { | ||
| val uri = new URI(uriStr) | ||
| val document = DocumentFactory.openDocument(uri) | ||
|
|
||
| document._1.get().foldLeft(Map.empty[String, (Double, Int)]) { (acc, tuple) => | ||
| val record = tuple.asInstanceOf[Tuple] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is a |
||
| val operatorId = record.getField(0).asInstanceOf[String] | ||
| val dataProcessingTime = record.getField(6).asInstanceOf[Long] | ||
| val controlProcessingTime = record.getField(7).asInstanceOf[Long] | ||
| val workerNum = record.getField(9).asInstanceOf[Int] | ||
| val execTime = (dataProcessingTime + controlProcessingTime) / 1e9 / workerNum | ||
|
|
||
| acc.get(operatorId) match { | ||
| case Some((prevTime, _)) => acc + (operatorId -> (Math.max(prevTime, execTime), workerNum)) | ||
| case None => acc + (operatorId -> (execTime, workerNum)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method is not clear at all. what stats? what is the uri pointing to? please clarify by renaming and add comments.