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

Do not reuse global worker pool for files #84

Open
wants to merge 5 commits into
base: 3.x
Choose a base branch
from

Conversation

trowski
Copy link
Member

@trowski trowski commented May 25, 2024

This modifies the parallel driver to create its own internal pool by default, rather than reuse the global worker pool. A specific pool can still be passed to the constructor (though I assume this use is rather rare).

The AMP_WORKER constant is no longer used to prevent the blocking driver from being used. This way, a Task may still use async file access and get the behavior expected.

/cc @azjezz

@trowski trowski requested a review from kelunik May 25, 2024 18:02
throw new \ValueError("Worker limit must be a positive integer");
}

$this->pool = $pool ?? new ContextWorkerPool($workerLimit);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we deprecate the $workerLimit parameter? We could remove the worker limit from the implementation then, because we have a dedicated pool usually. Actually... shouldn't using a subset of an existing pool be its own pool implementation if really needed?

Copy link
Member

Choose a reason for hiding this comment

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

Should we emit a deprecation notice if the parameter is passed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so, yes. I'm looking at adding the pool implementation you suggested above to parallel as well.

src/functions.php Outdated Show resolved Hide resolved
Comment on lines -65 to 54
if (\defined("AMP_WORKER")) { // Prevent spawning infinite workers.
return new BlockingFilesystemDriver;
}

return new ParallelFilesystemDriver;
Copy link
Member

Choose a reason for hiding this comment

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

How do we prevent infinite ParallelFilesystemDriver instances now?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't, so tasks can use async file access. @azjezz mentioned this was an issue.

Copy link
Member

Choose a reason for hiding this comment

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

But inside the worker we'll spawn another worker now and so on and never actually handle filesystem calls, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

No no, FileTask which handles file system calls will use the blocking driver for the call. If the worker executes a user task, then another pool of workers might be spawned. I don't see infinite workers being likely (unless someone executes a Task within a Task, but that would be strange), but each worker having its own set of workers would be a possibility. Since by default we limit the number of workers to 8, the resource usage should still be within reason even on systems without eio or uv.

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

Successfully merging this pull request may close these issues.

2 participants