From a2f087181e3d54032cbee45512f954543d65651c Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Tue, 4 Nov 2014 18:02:10 +0900 Subject: [PATCH] Change C210's sleep time to be proportional/ranked to member's rank --- prototype/poc-machi/src/machi_chain_manager1.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/prototype/poc-machi/src/machi_chain_manager1.erl b/prototype/poc-machi/src/machi_chain_manager1.erl index 7b92b64..bb3b646 100644 --- a/prototype/poc-machi/src/machi_chain_manager1.erl +++ b/prototype/poc-machi/src/machi_chain_manager1.erl @@ -745,10 +745,10 @@ react_to_env_C200(Retries, P_latest, S) -> end, react_to_env_C210(Retries, S). -react_to_env_C210(Retries, S) -> +react_to_env_C210(Retries, #ch_mgr{myflu=MyFLU, proj=Proj} = S) -> put(react, [c210|get(react)]), %% TODO: implement the ranked sleep thingie? - timer:sleep(100), + sleep_ranked_order(10, 100, MyFLU, Proj#projection.all_members), react_to_env_C220(Retries, S). react_to_env_C220(Retries, S) -> @@ -926,6 +926,14 @@ find_common_prefix([H|L1], [H|L2]) -> find_common_prefix(_, _) -> []. +sleep_ranked_order(MinSleep, MaxSleep, FLU, FLU_list) -> + Front = lists:takewhile(fun(X) -> X /=FLU end, FLU_list), + Index = length(Front) + 1, + NumNodes = length(FLU_list), + SleepIndex = NumNodes - Index, + SleepChunk = MaxSleep div NumNodes, + timer:sleep(MinSleep + (SleepChunk * SleepIndex)). + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% perhaps_call_t(S, Partitions, FLU, DoIt) ->