Skip to content
Snippets Groups Projects
user avatar
Josh Rosen authored
## What changes were proposed in this pull request?

Spark's current task cancellation / task killing mechanism is "best effort" because some tasks may not be interruptible or may not respond to their "killed" flags being set. If a significant fraction of a cluster's task slots are occupied by tasks that have been marked as killed but remain running then this can lead to a situation where new jobs and tasks are starved of resources that are being used by these zombie tasks.

This patch aims to address this problem by adding a "task reaper" mechanism to executors. At a high-level, task killing now launches a new thread which attempts to kill the task and then watches the task and periodically checks whether it has been killed. The TaskReaper will periodically re-attempt to call `TaskRunner.kill()` and will log warnings if the task keeps running. I modified TaskRunner to rename its thread at the start of the task, allowing TaskReaper to take a thread dump and filter it in order to log stacktraces from the exact task thread that we are waiting to finish. If the task has not stopped after a configurable timeout then the TaskReaper will throw an exception to trigger executor JVM death, thereby forcibly freeing any resources consumed by the zombie tasks.

This feature is flagged off by default and is controlled by four new configurations under the `spark.task.reaper.*` namespace. See the updated `configuration.md` doc for details.

## How was this patch tested?

Tested via a new test case in `JobCancellationSuite`, plus manual testing.

Author: Josh Rosen <joshrosen@databricks.com>

Closes #16189 from JoshRosen/cancellation.
2971ae56
History
Name Last commit Last update
..
_data
_includes
_layouts
_plugins
css
img
js
README.md
_config.yml
api.md
building-spark.md
cluster-overview.md
configuration.md
contributing-to-spark.md
ec2-scripts.md
graphx-programming-guide.md
hadoop-provided.md
hardware-provisioning.md
index.md
java-programming-guide.md
job-scheduling.md
ml-advanced.md
ml-ann.md
ml-classification-regression.md
ml-clustering.md
ml-collaborative-filtering.md
ml-decision-tree.md
ml-ensembles.md
ml-features.md
ml-guide.md
ml-linear-methods.md
ml-migration-guides.md
ml-pipeline.md
ml-survival-regression.md
ml-tuning.md
mllib-classification-regression.md
mllib-clustering.md
mllib-collaborative-filtering.md
mllib-data-types.md
mllib-decision-tree.md
mllib-dimensionality-reduction.md
mllib-ensembles.md
mllib-evaluation-metrics.md
mllib-feature-extraction.md
mllib-frequent-pattern-mining.md
mllib-guide.md
mllib-isotonic-regression.md
mllib-linear-methods.md
mllib-migration-guides.md
mllib-naive-bayes.md
mllib-optimization.md
mllib-pmml-model-export.md
mllib-statistics.md
monitoring.md
programming-guide.md
python-programming-guide.md
quick-start.md
running-on-mesos.md
running-on-yarn.md
scala-programming-guide.md
security.md
spark-standalone.md
sparkr.md
sql-programming-guide.md
storage-openstack-swift.md
streaming-custom-receivers.md
streaming-flume-integration.md
streaming-kafka-0-10-integration.md
streaming-kafka-0-8-integration.md
streaming-kafka-integration.md
streaming-kinesis-integration.md
streaming-programming-guide.md
structured-streaming-kafka-integration.md
structured-streaming-programming-guide.md
submitting-applications.md
tuning.md