Skip to content
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

[GLUTEN-8018][CORE] Introduce ApplyResourceProfileExec to apply resource profile for query stage #8195

Merged
merged 4 commits into from
Dec 17, 2024

Conversation

zjuwangg
Copy link
Contributor

What changes were proposed in this pull request?

This PR aims to add interface to GlutenPlan so that we can have the chance to set resource profile,
detailed design can be found #8018.

How was this patch tested?

To be added in the following commit.

@github-actions github-actions bot added CORE works for Gluten Core VELOX CLICKHOUSE labels Dec 10, 2024
Copy link

#8018

Copy link

Run Gluten Clickhouse CI on x86

@zjuwangg
Copy link
Contributor Author

#8209 is a follow up PR and demonstrate how the rule work with PR, please help review it when your guys have time. 🙏🏻

@zhztheplayer @FelixYBW @Yohahaha @PHILO-HE @jackylee-ch

@zhztheplayer zhztheplayer changed the title [GLUTEN-8018][CORE]Add setResourceProfile interface to provided ability to set resourceProfile [GLUTEN-8018][CORE] Add setResourceProfile interface to provided ability to set resourceProfile Dec 12, 2024
Copy link
Contributor Author

@zjuwangg zjuwangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhztheplayer Thanks for your detailed review. I will address your comments soon.

@zhztheplayer
Copy link
Member

zhztheplayer commented Dec 13, 2024

@zjuwangg Aside of the comments, I am thinking of another possible solution. Do you think we can use a rule to add a dummy unary query plan node on the input side of exchanges, to change the input RDD's query profile?

Which means, a plan

ColumnarExchange
  WholeStageTransformer
    ProjectExecTransformer
      FilterExecTransformer
        ScanExecTransformer

Can become

ColumnarExchange
  AdjustResourceProfile (or Apply/AdjustMemoryResources or something)
    WholeStageTransformer
      ProjectExecTransformer
        FilterExecTransformer
          ScanExecTransformer

When the rule applies.

Once AdjustResourceProfile's doExecute / doExecuteColumnar is called, we can set the resource profile to it's child RDD.

I feel this way is more intuitive to user and could make less code impact to other operators' code. What do you think?

@zjuwangg
Copy link
Contributor Author

@zjuwangg Aside of the comments, I am thinking of another possible solution. Do you think we can use a rule to add a dummy unary query plan node on the input side of exchanges, to change the input RDD's query profile?

Which means, a plan

ColumnarExchange
  WholeStageTransformer
    ProjectExecTransformer
      FilterExecTransformer
        ScanExecTransformer

Can become

ColumnarExchange
  AdjustResourceProfile (or Apply/AdjustMemoryResources or something)
    WholeStageTransformer
      ProjectExecTransformer
        FilterExecTransformer
          ScanExecTransformer

When the rule applies.

Once AdjustResourceProfile's doExecute / doExecuteColumnar is called, we can set the resource profile to it's child RDD.

I feel this way is more intuitive to user and could make less code impact to other operators' code. What do you think?

@zhztheplayer It's truely possible. Since I now do in this way for the whole stage fallback vanilla spark node in

/** Used to wrap a row-based child plan to have a change to setting ResourceProfile. */
case class RowBasedNodeResourceProfileWrapperExec(
child: SparkPlan,
resourceProfile: Option[ResourceProfile])
extends UnaryExecNode {
if (child.logicalLink.isDefined) {
setLogicalLink(RowBasedNodeResourProfileWrapperExecAdaptor(child.logicalLink.get))
}
override def output: Seq[Attribute] = child.output
override protected def doExecute(): RDD[InternalRow] = {
if (resourceProfile.isDefined) {
log.info(s"Use resource profile ${resourceProfile.get} for RowOperatorWrapperExec.")
child.execute.withResources(resourceProfile.get)
} else {
log.info(s"resourceProfile is empty in RowOperatorWrapperExec!")
child.execute
}
}

And the plan will be like following

image

I feel this way is more intuitive to user and could make less code impact to other operators' code. What do you think?

Good insights!
It's more elegant and can also work on whole fallback stage , will try to refactor in this way!

Copy link

Run Gluten Clickhouse CI on x86

@zjuwangg
Copy link
Contributor Author

@zhztheplayer I just revert previous commit and introduce a new ApplyResourceProfileExec node. Plz have a look when you have time.

Copy link
Member

@zhztheplayer zhztheplayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you also please fix CI error? Thanks!

* @param child
* @param resourceProfile
*/
case class ApplyResourceProfileExec(child: SparkPlan, resourceProfile: ResourceProfile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a suite case to show how this works?
The title of this pr should be changed now.

Copy link
Contributor Author

@zjuwangg zjuwangg Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a suite case to show how this works? The title of this pr should be changed now.

Right. Will change the title and address these comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackylee-ch Thanks for your detailed review, I'll add a test suite in a following MR after this get merged and just change the tile to match commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zjuwangg Would you add @Experimental to ApplyResourceProfileExec if it will be tested in the next PR? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@zjuwangg zjuwangg force-pushed the m_stageResourceProfile branch from 6bfa7e6 to 25a2d4d Compare December 16, 2024 13:57
Copy link

Run Gluten Clickhouse CI on x86

@zjuwangg zjuwangg force-pushed the m_stageResourceProfile branch from 25a2d4d to c792d03 Compare December 16, 2024 13:59
@zjuwangg zjuwangg changed the title [GLUTEN-8018][CORE] Add setResourceProfile interface to provided ability to set resourceProfile [GLUTEN-8018][CORE] Introduce ApplyResourceProfileExec to apply resource profile for the stage Dec 16, 2024
Copy link

Run Gluten Clickhouse CI on x86

@FelixYBW
Copy link
Contributor

e whole stage fallback vanilla spark n

Thank you, can you put a chart of query plan again?

Comment on lines 49 to 51
if (child.logicalLink.isDefined) {
setLogicalLink(ApplyResourceProfileExecAdaptor(child.logicalLink.get))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed a question here. Is there specific reason of setting the logical link with an ApplyResourceProfileExecAdaptor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no. Just keep consistent with FakeRowLogicAdaptor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no. Just keep consistent with FakeRowLogicAdaptor.

I see. that one may have specific reason, I am not sure.

So can we remove ApplyResourceProfileExecAdaptor? I feel ApplyResourceProfileExecAdaptor's logical link should be the same with its child's logical link. Since it and its child seem to be logically equivalent (share the same schema, output, statistics, etc.). Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed.

@zjuwangg
Copy link
Contributor Author

zjuwangg commented Dec 17, 2024

e whole stage fallback vanilla spark n

Thank you, can you put a chart of query plan again?

image

@FelixYBW
Similar to this, I will update it when following MR get ready

@zjuwangg
Copy link
Contributor Author

Run Gluten Clickhouse CI on x86

@PHILO-HE PHILO-HE changed the title [GLUTEN-8018][CORE] Introduce ApplyResourceProfileExec to apply resource profile for the stage [GLUTEN-8018][CORE] Introduce ApplyResourceProfileExec to apply resource profile for query stage Dec 17, 2024
@zjuwangg
Copy link
Contributor Author

@zhztheplayer @PHILO-HE do you know how to trigger the falling test again? The failure seems all related Network problem.

@zhztheplayer
Copy link
Member

zhztheplayer commented Dec 17, 2024

do you know how to trigger the falling test again?

@zjuwangg I know there is a way to retrigger CI by amending an empty commit and push it:

git commit --allow-empty -m "trigger ci"
git push ...

Copy link

Run Gluten Clickhouse CI on x86

@zjuwangg zjuwangg force-pushed the m_stageResourceProfile branch from 3c9aa29 to 1376cfb Compare December 17, 2024 06:46
Copy link

Run Gluten Clickhouse CI on x86

Copy link

Run Gluten Clickhouse CI on x86

Copy link
Member

@zhztheplayer zhztheplayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the code feels independent enough to merge with an @Experimental flag added. +1 from my side. We can move to #8209 then.

CC @jackylee-ch If any further comments.

@jackylee-ch
Copy link
Contributor

Now the code feels independent enough to merge with an @Experimental flag added.

Also +1 for me, thanks.

@zhztheplayer zhztheplayer merged commit e94e01d into apache:main Dec 17, 2024
43 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CORE works for Gluten Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants