-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[SPARK-52971] [PYTHON] Limit idle Python worker queue size #51684
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
base: master
Are you sure you want to change the base?
[SPARK-52971] [PYTHON] Limit idle Python worker queue size #51684
Conversation
mockWorkers.foreach(_.stop()) | ||
worker3.stop() |
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.
Shall we surround the above with try block and put these in the final clause to make sure all the workers are cleaned up?
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.
Thanks, made this change.
@@ -33,6 +33,12 @@ import org.apache.spark.util.ThreadUtils | |||
// Tests for PythonWorkerFactory. | |||
class PythonWorkerFactorySuite extends SparkFunSuite with SharedSparkContext { | |||
|
|||
private def getIdleWorkerCount(factory: PythonWorkerFactory): Int = { | |||
val field = factory.getClass.getDeclaredField("idleWorkers") |
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.
I guess it's ok to make idleWorkers
as private[spark]
? cc @HyukjinKwon
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.
yes
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.
but let's comment that this exposed for testing purpose.
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.
Thank you, changed to private[spark]
and added comment.
if (idleWorkerPoolSize.exists(idleWorkers.size > _)) { | ||
val oldestWorker = idleWorkers.dequeue() | ||
try { | ||
oldestWorker.stop() |
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.
We should call stopWorker
?
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.
Thanks, fixed.
What changes were proposed in this pull request?
Makes the number of idle workers in the
PythonWorkerFactory
pool configurable.Why are the changes needed?
Without limiting the maximum queue size, the idle worker pool can grow unbounded. Allows better control over number of workers allowed.
Does this PR introduce any user-facing change?
Yes, adds a new optional configuration entry:
spark.python.factory.idleWorkerMaxPoolSize
, from Spark 4.1.0How was this patch tested?
This patch adds two new test to verify behavior with and without the worker limit configuration.
Was this patch authored or co-authored using generative AI tooling?
No