Hi, I’m fairly new to Elixir, and was messing around with Tasks, GenServers and Supervisors, and had a question on scheduling.
I want to know if it’s possible to create a Task with a higher priority than default, such that it gets preference when CPU is available to run something over other processes.
I read that Erlang/Elixir uses preemptive round-robin scheduling, which lets a process run until a certain number of reductions (function calls?) are done by it, or if it calls receive and waits for input, then switches to some other process. This seems to give equal priority to all processes, and it makes sure every process gets some CPU time per round.
I want to know if I can create higher priority tasks, such that when scheduler moves on from a process and it has a choice of which process to switch to, it always chooses the process of the high priority task, even if there are other processes in the current round that haven’t gotten CPU time yet.
For example, say I have a premium API and a free API. Both APIs compute something and send the result somewhere.
The free API when called creates a task and runs its logic, and this can come under normal scheduling logic.
But the premium API should create a task such that the scheduler always gives that task process CPU and priority to run when it’s not blocked/waiting for something, even if that starves the free API task processes.
I couldn’t find any options relating to this in Task.async()
or Task.Supervisor.Async()
that are relevant to this
Please lmk if I have the right understanding of scheduling and if what I asked is possible, thanks