Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Created March 1, 2016 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AeroNotix/eaad66f121aaa199ca6e to your computer and use it in GitHub Desktop.
Save AeroNotix/eaad66f121aaa199ca6e to your computer and use it in GitHub Desktop.
application:ensure_all_started(cpg).
F = fun() ->
receive
ok ->
ok
end
end.
Pids = [spawn(F) || _ <- lists:seq(1,50000)].
[cpg:join(cpg_default_scope, "/foo", P) || P <- Pids].
[exit(P, kill) || P <- Pids].
sys:get_state(cpg_default_scope). %% any operation on cpg's default scope
@AeroNotix
Copy link
Author

This, on my machine, makes cpg unresponsive for multiple minutes at a time.

This is pretty terrible? @ostinelli how would syn deal with this case?

@ostinelli
Copy link

First thing to realize is that Syn allows to register individual processes per name. CPG, on the contrary, is a Process Group, which means you can add multiple processes in a single group with the same name. These are two different things.

It is not really clear what you're trying to do here :) Also, I guess you're evaluating a single node?

On comparisons between Syn and CPG, this post should be pretty self-explanatory. It also has examples and benchmarks.

That being said, if you are too lazy to do it yourself :) and what you are trying to achieve is to register 50,000 processes with their own individual name, this is Syn's somewhat equivalent to your example:

-module(test).

-export([start/0]).
-export([bench/0]).
-export([loop/0]).

start() ->
    %% start syn on node
    syn:start(),
    syn:init(),
    %% bench
    {TimeReg, _} = timer:tc(?MODULE, bench, []),
    io:format("~n~nAll took ~p sec.~n", [TimeReg/1000000]).

bench() ->
    %% spawn
    Pids = [spawn(?MODULE, loop, []) || _ <- lists:seq(1, 50000)],
    %% register
    [syn:register(P, P) || P <- Pids],
    %% kill
    [exit(P, kill) || P <- Pids],
    %% get some state
    sys:get_state(syn_consistency).

loop() ->
    receive
        _ -> ok
    end.

Running it:

2> test:start().

=INFO REPORT==== 1-Mar-2016::18:34:52 ===
syn_processes_table was successfully created

All took 1.275339 sec.
ok

Best,
r.

@AeroNotix
Copy link
Author

@ostinelli I understand the differences and I've also read your post, however, we use CPG (perhaps incorrectly) as a single and process group registry since we require both, and communication between groups and single processes is required.

My question about Syn though, is that the 'EXIT' message handlers are spawned functions, do you ever see these exit handlers pile up? Perhaps adding some folsom metrics would be a useful thing to get more insight into what's happening there.

Overall, in limited testing Syn outperforms CPG on a number of levels, I just wish there was a way to address multiple processes by a single name. I do appreciate that wasn't the goal with Syn.

I'm not evaluating a single node, I'm evaluating baseline performance for what should be a relatively simple use-case.

Did you ever think to run syn through jepsen testing? I have an old project where I compared cpg and pg2 under various netsplit conditions with interleaving operations. I do believe that more testing should be done to weed out edge-cases and a few more esoteric errors. Perhaps adding syn into the mix here along with some more rigorous testing would be insightful.

@ostinelli
Copy link

@AeroNotix I take it you're referring to the process_exit_callback callbacks? If so, I've never seen them pile up. This really depends on what you do with them, I just log the process exiting.

I've been asked by various developers if Syn could be used to manage Process Groups. It actually isn't very complicated to add this functionality so I did :) It's currently in a branch: https://github.com/ostinelli/syn/tree/pg. Please take a look at it and let me know.

I'd love to see any tests run on Syn. I never run the Jepsen tests and I'm not familiar enough to know if it is ok with eventual consistency. If you feel like giving it a go please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment