Comments (7)
You'll likely want to use Future::iterate instead if you need something like that.
Instead of a new fiber (async) for every receive, you could also put the receive loop into the async call and put all items into a Queue
, but whether that makes sense depends on your logic.
from parallel.
Thus the 'controller' MUST get all items off of the channel before the worker halts. If the worker halts before this, then any data still in the channel is lost.
This wasn't the intended behavior, which I fixed several days ago. Update to v2.2.1
and you'll be able to retrieve all data sent on the channel before the child closes.
from parallel.
Thanks that was a really good suggestion and the code is quite simpler now :)
I have another related question. Basically, how does one handle the race condition where data is sent in a channel but the worker halts? The code I'm refactoring is pretty straightforward to use this library, but the biggest difference is that this library maintains the channels for you, but closes them once the worker halts. Thus the 'controller' MUST get all items off of the channel before the worker halts. If the worker halts before this, then any data still in the channel is lost.
It would be ideal if the channel were not closed until both sides are __destructed. I think I can write something like this in my code, but I wanted to get your thoughts on it before doing so.
from parallel.
That's awesome, I'll give it a go!
from parallel.
This is still throwing
while (!$execution->getChannel()->isClosed()) {
try {
$prefix[] = $execution->getChannel()->receive(new TimeoutCancellation(1));
} catch (TimeoutException) {
Logger::log('Warning: waited for event to prefix!');
}
}
Channel source closed unexpectedly
Is there anyway to tell if there is data to be read from the channel?
from parallel.
Channel
is a low-level component that makes no assumptions about the data to be transmitted. You'll want to send some message to indicate the other side is closing the channel gracefully. null
is a good candidate for this. Instead of looping on checking if the channel is closed, check if you received null.
from parallel.
null
is a valid value in my case, and I ended up using a different approach. In most cases, the worker is not ending gracefully when hitting this.
The workflow looks something like:
stateDiagram-v2
[*] --> DequeueBatch
DequeueBatch --> SendingToWorker
SendingToWorker --> CrashDetected
CrashDetected --> ReadingFinalMessages
ReadingFinalMessages --> DequeueBatch
SendingToWorker --> Complete
Complete --> ReadingFinalMessages
I ended up making a change where the worker 'acks' a message once it's been successfully processed (or 'half-ack' if it is taking longer than expected). This way, after a period of time, the 'work' can be resubmitted after the designated worker dies unexpectedly.
It seems to be pretty resilient. At least as resilient as the old parallel implementation (if a bit more complex).
Thank you for you replies, I think this can be closed.
from parallel.
Related Issues (20)
- Is there a way to output the STDOUT of the child process to STDOUT of the parent process? HOT 4
- The nested use of pools HOT 1
- Measure the running time of a thread HOT 1
- Performance degradation in v2.2.0 HOT 18
- Parallel task(s) keep on running since v2.2 HOT 3
- Migrate from parallel-function HOT 3
- Sock files are piling up in tmp folder. They are not getting cleared up automatically. HOT 2
- Under XAMPP 8.2.4 the first example program freeze HOT 2
- Expected a valid stream HOT 6
- How to await for tasks in progress? HOT 2
- Do I need to use "readonly" in "FetchTask.php" when "main.php" contains several "$urls" in my case ??? HOT 1
- Hang when using ext-uv and JIT HOT 4
- Dealing with Zombies processes HOT 9
- Parcel (or analog) to data exchange between Parent and Child processes HOT 1
- communication between parallel worker HOT 1
- The pool was shut down HOT 3
- Forwarding User Interaction and Feedback in CLI app HOT 1
- Queue-based pool HOT 8
- Despite of DeferredCancellation::cancel() call Cancellation::isRequested() is always false in tasks submitted to ContextWorkerPool HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parallel.