Tina

Tina

Speculative Execution implementation: how do you force an actor to stop the process and move on?

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!

Most Liked

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.

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.

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.

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”.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement