Skip to content

[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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

craiuconstantintiberiu
Copy link

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.0

How 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

Comment on lines 107 to 108
mockWorkers.foreach(_.stop())
worker3.stop()
Copy link
Member

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?

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")
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

yes

Copy link
Member

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.

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()
Copy link
Member

Choose a reason for hiding this comment

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

We should call stopWorker?

Choose a reason for hiding this comment

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

Thanks, fixed.

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

Successfully merging this pull request may close these issues.

4 participants