Created
January 8, 2023 06:09
-
-
Save devsnek/d5d1b55eade3a3d5aad07fd3675f3a22 to your computer and use it in GitHub Desktop.
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
:erlang.register(:control, self()) | |
nodes = [ | |
:"node@uhoh", | |
:"node@VAULT", | |
:"node@xone", | |
:"node@blade", | |
] | |
code = Macro.to_string(quote do | |
pids = Enum.map(1..1000, fn _ -> | |
spawn(fn -> | |
receive do | |
{:ping, from} -> send(from, {:pong, self()}) | |
end | |
end) | |
end) | |
send({:control, :"control@ferris"}, {:pids, pids}) | |
end) | |
run_test = fn sender -> | |
pids = Enum.flat_map(nodes, fn node -> | |
Node.spawn(node, Code, :eval_string, [code]) | |
receive do | |
{:pids, pids} -> pids | |
after | |
1000 -> raise "failed to get pids" | |
end | |
end) | |
{uSecs, _} = :timer.tc(sender, [pids, {:ping, self()}]) | |
Enum.each(pids, fn pid -> | |
receive do | |
{:pong, ^pid} -> :ok | |
after | |
1000 -> IO.puts "failed to get response from #{pid}" | |
end | |
end) | |
uSecs | |
end | |
uSecs = run_test.(fn pids, message -> | |
Enum.each(pids, fn pid -> | |
send(pid, message) | |
end) | |
end) | |
IO.puts "baseline #{uSecs}us" | |
uSecs = run_test.(fn pids, message -> | |
send(pids, message) | |
end) | |
IO.puts "optimized #{uSecs}us" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment