-
-
Save jtuple/8f12ce9c21471f5d6f01 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
-module(test11). | |
-compile(export_all). | |
-define(CHAIN_SIZE, 10). | |
-define(WORKERS, 10). | |
-define(TERM_SIZE, 5000). | |
go() -> | |
io:format("*** Setting up~n"), | |
Chain = [spawn(fun init_worker/0) || _ <- lists:seq(1, ?CHAIN_SIZE)], | |
Primary = spawn(?MODULE, init_primary, [Chain]), | |
setup_chain(Chain, Primary), | |
timer:sleep(infinity). | |
setup_chain([], _Primary) -> | |
ok; | |
setup_chain([W], Primary) -> | |
W ! {setup_next, Primary}; | |
setup_chain([W|Chain], Primary) -> | |
N = hd(Chain), | |
W ! {setup_next, N}, | |
setup_chain(Chain, Primary). | |
init_worker() -> | |
receive | |
{setup_next, Next} -> | |
worker(Next) | |
end. | |
worker(Next) -> | |
receive next -> ok end, | |
lists:reverse(lists:seq(1,100)), | |
Next ! next, | |
worker(Next). | |
init_primary(Chain) -> | |
Next = hd(Chain), | |
T = erlang:make_tuple(100, erlang:make_tuple(100, undefined)), | |
Term = [T || _ <- lists:seq(1,?TERM_SIZE)], | |
erlang:send_after(5000, self(), work), | |
self() ! next, | |
io:format("*** Starting primary with compaction load~n"), | |
primary(Next, Term). | |
primary(Next, Term) -> | |
receive | |
next -> | |
Next ! next; | |
work -> | |
io:format("*** Threads should be compacted. Only one not WAITING~n"), | |
erlang:display(erlang:statistics(run_queues)), | |
erlang:system_info(thread_progress), | |
io:format("*** Switching to bad external_size load. This won't balance (sadly)~n"), | |
timer:sleep(8000), | |
spawn_n(?WORKERS, fun() -> | |
[begin | |
erlang:display(erlang:statistics(run_queues)), | |
erlang:system_info(thread_progress), | |
erlang:external_size(Term) | |
end || _ <- lists:seq(1,10)] | |
end), | |
wait(10), | |
io:format("*** Switching back to compaction load~n"), | |
erlang:send_after(5000, self(), work) | |
end, | |
primary(Next, Term). | |
spawn_n(0, _) -> | |
ok; | |
spawn_n(N, F) -> | |
Self = self(), | |
spawn_link(fun() -> | |
F(), | |
Self ! done | |
end), | |
spawn_n(N-1, F). | |
wait(0) -> | |
ok; | |
wait(N) -> | |
receive | |
done -> | |
wait(N-1) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also: Joe's commentary on a related synthetic test case at https://gist.github.com/jtuple/0d9ca553b7e58adcb6f4