Blocking or computationally intensive operations #94
-
How Libretto would interpolate such Scala code into a Libretto program, that is blocking on IO or otherwise long-running? I suppose Libretto runtime executes a number of components in parallel on a thread pool. Is there a way to mark some components so that they get run in dedicated threads? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
I think something like that would be against the core idea here. The interface which allows using "opaque" Scala functions is meant to be used only at the input and output layers of a Libretto program, as I get it. The whole point is to not use such "opaque" functions in the first place inside your Libretto program as these functions don't compose (in a concurrent by design setting)—and you can't take advantage of Libretto's linearity when using raw Scala functions, which would make the whole concept moot. But don't take my reasoning as authoritative. I'm just a bystander… 😄 Only @TomasMikula may answer this definitively. Off-Topic note: You've started a really interesting looking project! I may come there as I'm also interested (form the engineering standpoint) in simplifying state synchronization in concurrent systems. The whole HTTP madness needs to come to an end finally! REST is the maximally biggest nonsense when all you want is building distributed apps… |
Beta Was this translation helpful? Give feedback.
-
Imagine that in the middle of your program you naturally needs to query a database. Would you like pushing that query out of the stop where you actually need it to the input/output layer of your Libretto/Scaletto program? That would require some awkward wiring. I think Libretto/Scaletto could still ensure linearity for such alien components, as long as they obey certain requirements. In particular, special care should be taken in case of long-running computations in order not to obstruct the rest of the concurrent program. It is good to start with and study the most restrictive setting, but then one often needs to carefully relax some restrictions in order to make things practical. For example, structured programming was a profoundly great idea, but initially struggled to find adoption until certain limited forms of the |
Beta Was this translation helpful? Give feedback.
-
@MateuszKowalewski Libretto is on my list of things to explore, and I'm thinking of applying some ideas from it to help solve distributed systems difficulties. Though, I plan to get Replica_IO first implemented in Rust. You're more than welcome to participate if what's written in the readme resonates with you! I invite you to start by joining the Discord chat. |
Beta Was this translation helpful? Give feedback.
To answer the question regarding a dedicated thread pool:
https://github.com/TomasMikula/libretto/blob/main/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala#L199
https://github.com/TomasMikula/libretto/blob/main/core/src/main/scala/libretto/scaletto/impl/futurebased/ExecutionImpl.scala#L207
When you trace back
blockingEC
you'll find a dedicated "ExecutionContext" (Scala speak for more or less a ThreadPool resource) of a kind that can handle potentially indefinitely blocking tasks:https://github.com/TomasMikula/libretto/blob/main/core/src/main/scala/libretto/scaletto/impl/futurebased/FutureExecutor.scala#L19
https://github.com/TomasMikula/libretto/blob/main/core/…