Last active
August 29, 2015 14:23
-
-
Save prio/35fae57ce4050c5bcbc0 to your computer and use it in GitHub Desktop.
get_best_pid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Scheduler do | |
def get_best_pid(group) do | |
mems = :pg2.get_members(group) |> | |
Enum.map(fn(pid) -> | |
[message_queue_len: msgs, stack_size: ss] = :rpc.pinfo(pid, [:message_queue_len, :stack_size]) | |
{pid, msgs, ss} | |
end) |> | |
Enum.sort(fn ({_, q1, s1}, {_, q2, s2}) -> q1 < q2 or (q1 == q2 and s1 < s2) end) | |
case mems do | |
[{pid, _, _} | _] -> pid | |
[] -> {:error, :empty_process_group} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment