Created
October 1, 2016 14:12
-
-
Save x4lldux/a2d93a119cb38714a63116d17a6db3e7 to your computer and use it in GitHub Desktop.
JOBS framework test
This file contains hidden or 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
{{12, 9, 26}, 1} | |
{{12, 9, 27}, 2} | |
{{12, 9, 28}, 3} | |
{{12, 9, 29}, 2} | |
{{12, 9, 30}, 2} | |
{{12, 9, 31}, 2} | |
{{12, 9, 32}, 2} | |
{{12, 9, 33}, 2} | |
{{12, 9, 34}, 2} | |
{{12, 9, 35}, 2} | |
{{12, 9, 36}, 2} | |
{{12, 9, 37}, 2} | |
{{12, 9, 38}, 1} | |
{{12, 9, 39}, 2} | |
{{12, 9, 40}, 2} | |
{{12, 9, 41}, 2} | |
{{12, 9, 42}, 2} | |
{{12, 9, 43}, 2} | |
{{12, 9, 44}, 2} | |
{{12, 9, 45}, 2} | |
{{12, 9, 46}, 2} | |
{{12, 9, 47}, 2} | |
{{12, 9, 48}, 2} | |
{{12, 9, 49}, 1} | |
{{12, 9, 50}, 2} | |
{{12, 9, 51}, 2} | |
{{12, 9, 52}, 2} | |
{{12, 9, 53}, 2} | |
{{12, 9, 54}, 1} | |
{{12, 9, 55}, 2} | |
{{12, 9, 56}, 2} | |
{{12, 9, 57}, 2} | |
{{12, 9, 58}, 2} | |
{{12, 9, 59}, 2} | |
{{12, 10, 0}, 2} | |
{{12, 10, 1}, 2} | |
{{12, 10, 2}, 2} | |
{{12, 10, 3}, 2} | |
{{12, 10, 4}, 2} | |
{{12, 10, 5}, 1} | |
{{12, 10, 6}, 2} | |
{{12, 10, 7}, 2} | |
{{12, 10, 8}, 2} | |
{{12, 10, 9}, 2} | |
{{12, 10, 10}, 2} | |
{{12, 10, 11}, 2} | |
{{12, 10, 12}, 2} | |
{{12, 10, 13}, 2} | |
{{12, 10, 14}, 1} | |
{{12, 10, 15}, 2} | |
{{12, 10, 16}, 2} | |
{{12, 10, 17}, 2} | |
{{12, 10, 18}, 2} | |
{{12, 10, 19}, 1} | |
{{12, 10, 34}, 44} | |
{{12, 10, 40}, 13} | |
{{12, 10, 41}, 2} | |
{{12, 10, 42}, 1} | |
{{12, 10, 43}, 2} | |
{{12, 10, 44}, 2} | |
{{12, 10, 45}, 2} | |
{{12, 10, 46}, 2} | |
{{12, 10, 47}, 2} | |
{{12, 10, 48}, 2} | |
{{12, 10, 49}, 2} | |
{{12, 10, 50}, 2} | |
{{12, 10, 51}, 2} | |
{{12, 10, 52}, 2} | |
{{12, 10, 53}, 2} | |
{{12, 10, 54}, 2} | |
{{12, 10, 55}, 1} | |
{{12, 10, 56}, 2} | |
{{12, 10, 57}, 2} | |
{{12, 10, 58}, 2} | |
{{12, 10, 59}, 2} | |
{{12, 11, 0}, 2} | |
{{12, 11, 1}, 2} | |
{{12, 11, 2}, 1} |
This file contains hidden or 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
{{12, 9, 26}, [:q1]} | |
{{12, 9, 27}, [:q2, :q2]} | |
{{12, 9, 28}, [:q2, :q2, :q1]} | |
{{12, 9, 29}, [:q2, :q2]} | |
{{12, 9, 30}, [:q2, :q2]} | |
{{12, 9, 31}, [:q2, :q2]} | |
{{12, 9, 32}, [:q2, :q2]} | |
{{12, 9, 33}, [:q2, :q2]} | |
{{12, 9, 34}, [:q2, :q2]} | |
{{12, 9, 35}, [:q2, :q2]} | |
{{12, 9, 36}, [:q2, :q2]} | |
{{12, 9, 37}, [:q2, :q2]} | |
{{12, 9, 38}, [:q2]} | |
{{12, 9, 39}, [:q2, :q2]} | |
{{12, 9, 40}, [:q2, :q2]} | |
{{12, 9, 41}, [:q2, :q2]} | |
{{12, 9, 42}, [:q2, :q2]} | |
{{12, 9, 43}, [:q2, :q2]} | |
{{12, 9, 44}, [:q2, :q2]} | |
{{12, 9, 45}, [:q2, :q2]} | |
{{12, 9, 46}, [:q2, :q2]} | |
{{12, 9, 47}, [:q2, :q2]} | |
{{12, 9, 48}, [:q2, :q2]} | |
{{12, 9, 49}, [:q2]} | |
{{12, 9, 50}, [:q2, :q2]} | |
{{12, 9, 51}, [:q2, :q2]} | |
{{12, 9, 52}, [:q2, :q2]} | |
{{12, 9, 53}, [:q2, :q2]} | |
{{12, 9, 54}, [:q2]} | |
{{12, 9, 55}, [:q2, :q2]} | |
{{12, 9, 56}, [:q2, :q2]} | |
{{12, 9, 57}, [:q2, :q2]} | |
{{12, 9, 58}, [:q2, :q2]} | |
{{12, 9, 59}, [:q2, :q2]} | |
{{12, 10, 0}, [:q2, :q2]} | |
{{12, 10, 1}, [:q2, :q2]} | |
{{12, 10, 2}, [:q2, :q2]} | |
{{12, 10, 3}, [:q2, :q2]} | |
{{12, 10, 4}, [:q2, :q2]} | |
{{12, 10, 5}, [:q2]} | |
{{12, 10, 6}, [:q2, :q2]} | |
{{12, 10, 7}, [:q2, :q2]} | |
{{12, 10, 8}, [:q2, :q2]} | |
{{12, 10, 9}, [:q2, :q2]} | |
{{12, 10, 10}, [:q2, :q2]} | |
{{12, 10, 11}, [:q2, :q2]} | |
{{12, 10, 12}, [:q2, :q2]} | |
{{12, 10, 13}, [:q2, :q2]} | |
{{12, 10, 14}, [:q2]} | |
{{12, 10, 15}, [:q2, :q2]} | |
{{12, 10, 16}, [:q2, :q2]} | |
{{12, 10, 17}, [:q2, :q2]} | |
{{12, 10, 18}, [:q2, :q2]} | |
{{12, 10, 19}, [:q2]} | |
{{12, 10, 34}, | |
[:q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, | |
:q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, | |
:q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1]} | |
{{12, 10, 40}, | |
[:q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1, :q1]} | |
{{12, 10, 41}, [:q1, :q1]} | |
{{12, 10, 42}, [:q1]} | |
{{12, 10, 43}, [:q1, :q1]} | |
{{12, 10, 44}, [:q1, :q1]} | |
{{12, 10, 45}, [:q1, :q1]} | |
{{12, 10, 46}, [:q1, :q1]} | |
{{12, 10, 47}, [:q1, :q1]} | |
{{12, 10, 48}, [:q1, :q1]} | |
{{12, 10, 49}, [:q1, :q1]} | |
{{12, 10, 50}, [:q1, :q1]} | |
{{12, 10, 51}, [:q1, :q1]} | |
{{12, 10, 52}, [:q1, :q1]} | |
{{12, 10, 53}, [:q1, :q1]} | |
{{12, 10, 54}, [:q1, :q1]} | |
{{12, 10, 55}, [:q1]} | |
{{12, 10, 56}, [:q1, :q1]} | |
{{12, 10, 57}, [:q1, :q1]} | |
{{12, 10, 58}, [:q1, :q1]} | |
{{12, 10, 59}, [:q1, :q1]} | |
{{12, 11, 0}, [:q1, :q1]} | |
{{12, 11, 1}, [:q1, :q1]} | |
{{12, 11, 2}, [:q1]} |
This file contains hidden or 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 Aggregator do | |
use GenServer | |
# Client API | |
def start_link() do | |
GenServer.start_link(__MODULE__, [], name: __MODULE__) | |
end | |
def sum_up() do | |
GenServer.call(__MODULE__, :sum_up) | |
end | |
# Server callbacks | |
def init([]) do | |
{:ok, {%{}, %{}}} | |
end | |
def handle_call(:sum_up, _from, state = {counts, events}) do | |
counts = | |
counts | |
|> Enum.sort | |
|> Enum.into([]) | |
events = | |
events | |
|> Enum.sort | |
|> Enum.map(fn {t, qs} -> {t, Enum.reverse qs} end) | |
{:reply, {counts, events}, state} | |
end | |
def handle_info({q, time}, {counts, events}) do | |
counts = Map.update(counts, time, 1, fn x -> x+1 end) | |
events = Map.update(events, time, [q], fn qs -> [q|qs] end) | |
{:noreply, {counts, events}} | |
end | |
end |
This file contains hidden or 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
{:ok, pid} = GenServer.start_link Aggregator, [] | |
:jobs.add_group_rate :gq, limit: 3 | |
:jobs.add_queue :q1, regulators: [group_rate: :gq, rate: [limit: 2] ] | |
:jobs.add_queue :q2, regulators: [group_rate: :gq, rate: [limit: 2] ] | |
for _ <- 1..100 do | |
spawn fn -> :jobs.run(:q1, fn -> send pid, {:q1,:erlang.time} end) end; | |
spawn fn -> :jobs.run(:q2, fn -> send pid, {:q2,:erlang.time} end) end; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment