-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an optional :offload send mode (#10)
This optional mode offloads the send/2 calls to the remote Manifold nodes to one of the local `Manifold.Sender` processes. Add a new test for the :offload send mode.
- Loading branch information
Showing
7 changed files
with
287 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
defmodule Manifold.Sender do | ||
use GenServer | ||
|
||
alias Manifold.Utils | ||
|
||
@gen_module Application.get_env(:manifold, :gen_module, GenServer) | ||
|
||
## Client | ||
|
||
@spec child_spec(Keyword.t()) :: tuple | ||
def child_spec(opts \\ []) do | ||
import Supervisor.Spec, warn: false | ||
supervisor(__MODULE__, [:ok, opts], id: Keyword.get(opts, :name, __MODULE__)) | ||
end | ||
|
||
@spec start_link(:ok, Keyword.t()) :: GenServer.on_start() | ||
def start_link(:ok, opts \\ []) do | ||
GenServer.start_link(__MODULE__, :ok, opts) | ||
end | ||
|
||
@spec send(pid, atom, [pid], term) :: :ok | ||
def send(pid, partitioner, pids, message) do | ||
@gen_module.cast(pid, {:send, partitioner, pids, message}) | ||
end | ||
|
||
## Server Callbacks | ||
|
||
def init(:ok) do | ||
# Set optimal process flags | ||
Process.flag(:message_queue_data, :off_heap) | ||
schedule_next_hibernate() | ||
{:ok, nil} | ||
end | ||
|
||
def handle_cast({:send, partitioner, pids, message}, nil) do | ||
grouped_by = | ||
Utils.group_by(pids, fn | ||
nil -> nil | ||
pid -> node(pid) | ||
end) | ||
|
||
for {node, pids} <- grouped_by, node != nil do | ||
Manifold.Partitioner.send({partitioner, node}, pids, message) | ||
end | ||
|
||
{:noreply, nil} | ||
end | ||
|
||
def handle_cast(_message, nil) do | ||
{:noreply, nil} | ||
end | ||
|
||
def handle_info(:hibernate, nil) do | ||
schedule_next_hibernate() | ||
{:noreply, nil, :hibernate} | ||
end | ||
|
||
def handle_info(_message, nil) do | ||
{:noreply, nil} | ||
end | ||
|
||
defp schedule_next_hibernate() do | ||
Process.send_after(self(), :hibernate, Utils.next_hibernate_delay()) | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
%{ | ||
"benchfella": {:hex, :benchfella, "0.3.5", "b2122c234117b3f91ed7b43b6e915e19e1ab216971154acd0a80ce0e9b8c05f5", [:mix], [], "hexpm", "23f27cbc482cbac03fc8926441eb60a5e111759c17642bac005c3225f5eb809d"}, | ||
"global_flags": {:hex, :global_flags, "1.0.0", "ee6b864979a1fb38d1fbc67838565644baf632212bce864adca21042df036433", [:rebar3], [], "hexpm", "85d944cecd0f8f96b20ce70b5b16ebccedfcd25e744376b131e89ce61ba93176"}, | ||
"local_cluster": {:hex, :local_cluster, "1.2.1", "8eab3b8a387680f0872eacfb1a8bd5a91cb1d4d61256eec6a655b07ac7030c73", [:mix], [{:global_flags, "~> 1.0", [hex: :global_flags, repo: "hexpm", optional: false]}], "hexpm", "aae80c9bc92c911cb0be085fdeea2a9f5b88f81b6bec2ff1fec244bb0acc232c"}, | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
# https://github.com/whitfin/local-cluster#setup | ||
:ok = LocalCluster.start() | ||
Application.ensure_all_started(:manifold) | ||
|
||
ExUnit.start() |