Giter Site home page Giter Site logo

Comments (7)

kelunik avatar kelunik commented on June 1, 2024 1

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.

trowski avatar trowski commented on June 1, 2024 1

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.

withinboredom avatar withinboredom commented on June 1, 2024

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.

withinboredom avatar withinboredom commented on June 1, 2024

That's awesome, I'll give it a go!

from parallel.

withinboredom avatar withinboredom commented on June 1, 2024

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.

trowski avatar trowski commented on June 1, 2024

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.

withinboredom avatar withinboredom commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.