Hacker News new | ask | show | jobs
by WJW 1262 days ago
A conduit pulls information from earlier conduits in the same pipeline, only requesting the next item when it needs to do more work in order to process a request for a value from a conduit later in the pipeline. This means that inside the conduit itself there is perfect backpressure: you cannot overload any buffers between conduits because there aren't any.

Of course, depending on the rest of the system you could still have a bottleneck somewhere. For example: if you pull jobs from a queue in (say) Redis but don't have enough capacity to process jobs faster than they are enqueued, the queue will eventually fill up.

2 comments

Precisely. Conduits basically do everything on demand.

For parallel processing the backpressure becomes a bit more complicated, in particular if you end with a sequential consumer. If you're just doing your parallel tasks when a sequential consumer demands it, you'll find yourself still doing one task at a time. The straightforward solution is to work ahead a bit, spawning just enough parallel work to fill a small buffer that the consumer can read from. You get backpressure this way, but may have done a little bit too much if the consumer doesn't want the rest of the data. We'll show this in the third blog post of the series.

> We'll show this in the third blog post of the series.

Thanks for the pointer! Will have a look.

Thanks for the explanation!

So it's pull based and not push based like most other streams lib.

Does maybe someone know how this compares to FS2 or Iteratees than? (Both are also pull based streaming solutions).

https://fs2.io/#/

https://en.wikipedia.org/wiki/Iteratee

Looks quite similar to me. Is the Scala FS2 lib maybe even a clones of the Haskell solution? Or are they different in important aspects?

"Many of the ideas in FS2 were first tried and developed in there [Haskell]".

https://fs2.io/#/documentation?id=related-haskell-libraries

Conduit is pretty much a direct descendant of iteratee ideas in Haskell. It started about here, as far as I know: https://hackage.haskell.org/package/iteratee