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

Support profiling for specific stages on a limited number of tasks #11708

Open
wants to merge 8 commits into
base: branch-24.12
Choose a base branch
from

Conversation

thirtiseven
Copy link
Collaborator

Close #11666

In a customer use case we found that the profiling files were sometimes very large even when we enabled stage/time range limit config on a job.

This pr add support for profiling on only a limited number of tasks for specific stages.

before this pr:

Screenshot 2024-11-07 at 15 11 24

after this pr, task limit = 3:

Screenshot 2024-11-07 at 15 08 35

This nsys-rep file size dropped from 10.4 Mb to 451 Kb.

@thirtiseven thirtiseven self-assigned this Nov 7, 2024
@thirtiseven
Copy link
Collaborator Author

build

@@ -792,6 +792,12 @@ val GPU_COREDUMP_PIPE_PATTERN = conf("spark.rapids.gpu.coreDump.pipePattern")
.bytesConf(ByteUnit.BYTE)
.createWithDefault(8 * 1024 * 1024)

val PROFILE_TASK_LIMIT_PER_STAGE = conf("spark.rapids.profile.taskLimitPerStage")
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Would be nice to locate this next to the related config, PROFILE_STAGES

@@ -2603,6 +2609,8 @@ class RapidsConf(conf: Map[String, String]) extends Logging {

lazy val profileWriteBufferSize: Long = get(PROFILE_WRITE_BUFFER_SIZE)

lazy val profileTaskLimitPerStage: Int = get(PROFILE_TASK_LIMIT_PER_STAGE)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Would be nice to locate this next to the related config, profileStages.

enable()
startPollingDriver()
}
taskCtx.addTaskCompletionListener[Unit] { _ =>
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we only need to add completions on tasks in the above conditional while we are still under the task limit. Once we're beyond the limit, it's just overhead.

Comment on lines +138 to +140
val currentCount = stageTaskCount.getOrElse(stageId, 0)
if (currentCount < taskLimit) {
stageTaskCount(stageId) = currentCount + 1
Copy link
Member

Choose a reason for hiding this comment

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

This is not multithread safe. Spark guarantees the listener callbacks of a task are called serially, but makes no such guarantee across tasks.

if (currentCount < taskLimit) {
stageTaskCount(stageId) = currentCount + 1
} else {
disable()
Copy link
Member

Choose a reason for hiding this comment

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

Just because a stage has completed a task does not mean we want to disable profiling. Tasks for other stages/jobs that have been flagged for profiling could be active, and we want to keep profiling enabled in that case. See the logic in updateActiveFromDriver. Instead, this needs to do something like the following. Instead of copying this code, it should be refactored from the version in updateActiveFromDriver and reused.

                synchronized {
                  if (activeJobs.isEmpty && activeStages.isEmpty) {
                    disable()
                    stopPollingDriver()
                  }
                }

@@ -50,10 +50,13 @@ object ProfilerOnExecutor extends Logging {
private var isProfileActive = false
private var currentContextMethod: Method = null
private var getContextMethod: Method = null
private val stageTaskCount = mutable.HashMap[Int, Int]()
private var taskLimit = 0
Copy link
Member

Choose a reason for hiding this comment

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

This name is a bit too generic. Is it a task limit across all tasks being profiled? Turns out no, but from the name one cannot tell.

Suggested change
private var taskLimit = 0
private var stageTaskLimit = 0

Comment on lines +138 to +140
val currentCount = stageTaskCount.getOrElse(stageId, 0)
if (currentCount < taskLimit) {
stageTaskCount(stageId) = currentCount + 1
Copy link
Member

Choose a reason for hiding this comment

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

stageId is leaked in the map and never removed. Can solve that by storing a 0 in the map for the stage when the first task for a stage to be profiled is seen. Task completion callback would try to lookup stage in the map. If it gets nothing, there's nothing for it to do. If it gets a task count, it increments it. If we're still under the limit then it stores the updated count, otherwise it removes the count for that stage from the map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] support task limit profiling for specified stages
2 participants