Tina

Tina

Hello!

I have one Dynamic Supervisor with 3 Gen Server actors (call them workers), and in parallel a Load Balancer actor. The Load Balancer actor receives a stream of data and sends in round robin fashion the data to be manipulated by the workers.

Now comes the problem. Speculative execution (at least the version I try to implement) states that given a task to 2 different actors, one of them will execute it faster and the other one should be stopped from finishing it (mid-process) and told to move on to the next task.

Solution 1: kill it with Process.exit(), the worker will be respawned and continue. But the further messages in the mailbox will be lost.

Solution 2: Part the process in several steps and log the progress on shared resource (be it a database or using Agent). When trying to move to the next one, look up if the other worker has finished and stop if so. But this adds additional computation time and not every process can be parted into several steps. Smells like overhead much.

Solution 3: Use a special function that, once the Load Balancer receives the answer from an actor, will be called so the second actor stops the message execution (if started) or never execute it (if still in queue).

Has anyone any idea of such a special function for Solution 3? I’ve spent like 2 days reading the documentation but did not come close to such. Or maybe there is a method to create such function that will force the Gen Server to at least stop mid-process and consider the new high-priority message?

Thanks!

Showing Posts 1 to 6

LostKobrakai

LostKobrakai

You cannot force another process from the outside to stop what it’s doing and read a message. You can only send it a message, which will queue like any other and needs to wait for the process to check its mailbox. So the best you could do is similar to your option 2, where the worker regularly checks its mailbox to see if its supposed to stop / drop work from the queue.

D4no0

D4no0

The question is why would you give the same task to be executed to 2 different processes?

There is no concept of message priority, all messages are read from the mailbox sequentially, the only way for you to achieve this is to make your own abstraction on top of GenServers.

kwando

kwando

I’m not sure this is the bes approach but anyways, here is an idea:

Keep you worker responsive:

  • new work items should not stay in the message queue, put them in an internal queue in your workers
  • outsource the heavy work to a Task/separate process from the worker, then the worker can just cancel/kill that process when it gets the “already computed message”.
Tina

Tina OP

That was my first question too :smiley:
It’s a learning task at a Real-Time Programming university course. We are simulating a case of real time processing of streams of data and in order to achieve faster results comes the Speculative Execution solution we should implement in this particular way. The situation is that having multiple resources with performance variation and a limited time the result should be received in, send the task to multiple actors, achieve the result in the fastest time possible and tell the other ones to drop it.

Tina

Tina OP

Thanks! I think the approach will make the Solution 2 better than it looks like now. :))

D4no0

D4no0

Oh I see, the problem with your approach is that you need to guarantee that all those processes will run on a different scheduler, since each scheduler runs on a separate core, otherwise there is absolutely no gain from this approach as running them on the same core will just execute them concurrently by switching the context.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews