From 5bc68d09c8eea8cdb1375e303a4b7132860254e4 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 3 Apr 2017 15:49:34 +0200 Subject: stdlib: Rename ets_SUITE:run_workers run_workers/* -> run_smp_workers/* run_workers_do/4 -> run_sched_workers/4 --- lib/stdlib/test/ets_SUITE.erl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'lib/stdlib/test') diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl index ac68fdcc34..a7fe213f40 100644 --- a/lib/stdlib/test/ets_SUITE.erl +++ b/lib/stdlib/test/ets_SUITE.erl @@ -5284,7 +5284,7 @@ meta_lookup_unnamed_read(Config) when is_list(Config) -> end, FiniF = fun(Tab) -> true = ets:delete(Tab) end, - run_workers(InitF,ExecF,FiniF,10000). + run_smp_workers(InitF,ExecF,FiniF,10000). meta_lookup_unnamed_write(Config) when is_list(Config) -> InitF = fun(_) -> Tab = ets_new(unnamed,[]), @@ -5295,7 +5295,7 @@ meta_lookup_unnamed_write(Config) when is_list(Config) -> end, FiniF = fun({Tab,_}) -> true = ets:delete(Tab) end, - run_workers(InitF,ExecF,FiniF,10000). + run_smp_workers(InitF,ExecF,FiniF,10000). meta_lookup_named_read(Config) when is_list(Config) -> InitF = fun([ProcN|_]) -> Name = list_to_atom(integer_to_list(ProcN)), @@ -5308,7 +5308,7 @@ meta_lookup_named_read(Config) when is_list(Config) -> end, FiniF = fun(Tab) -> true = ets:delete(Tab) end, - run_workers(InitF,ExecF,FiniF,10000). + run_smp_workers(InitF,ExecF,FiniF,10000). meta_lookup_named_write(Config) when is_list(Config) -> InitF = fun([ProcN|_]) -> Name = list_to_atom(integer_to_list(ProcN)), @@ -5320,7 +5320,7 @@ meta_lookup_named_write(Config) when is_list(Config) -> end, FiniF = fun({Tab,_}) -> true = ets:delete(Tab) end, - run_workers(InitF,ExecF,FiniF,10000). + run_smp_workers(InitF,ExecF,FiniF,10000). meta_newdel_unnamed(Config) when is_list(Config) -> InitF = fun(_) -> ok end, @@ -5328,7 +5328,7 @@ meta_newdel_unnamed(Config) when is_list(Config) -> true = ets:delete(Tab) end, FiniF = fun(_) -> ok end, - run_workers(InitF,ExecF,FiniF,10000). + run_smp_workers(InitF,ExecF,FiniF,10000). meta_newdel_named(Config) when is_list(Config) -> InitF = fun([ProcN|_]) -> list_to_atom(integer_to_list(ProcN)) @@ -5338,7 +5338,7 @@ meta_newdel_named(Config) when is_list(Config) -> Name end, FiniF = fun(_) -> ok end, - run_workers(InitF,ExecF,FiniF,10000). + run_smp_workers(InitF,ExecF,FiniF,10000). %% Concurrent insert's on same table. smp_insert(Config) when is_list(Config) -> @@ -5347,7 +5347,7 @@ smp_insert(Config) when is_list(Config) -> ExecF = fun(_) -> true = ets:insert(smp_insert,{rand:uniform(10000)}) end, FiniF = fun(_) -> ok end, - run_workers(InitF,ExecF,FiniF,100000), + run_smp_workers(InitF,ExecF,FiniF,100000), verify_table_load(smp_insert), ets:delete(smp_insert). @@ -5370,7 +5370,7 @@ smp_fixed_delete_do() -> {Key+Increment,Increment} end, FiniF = fun(_) -> ok end, - run_workers_do(InitF,ExecF,FiniF,NumOfObjs), + run_sched_workers(InitF,ExecF,FiniF,NumOfObjs), 0 = ets:info(T,size), true = ets:info(T,fixed), Buckets = num_of_buckets(T), @@ -5611,7 +5611,7 @@ smp_select_delete(Config) when is_list(Config) -> end end, FiniF = fun(Result) -> Result end, - Results = run_workers_do(InitF,ExecF,FiniF,20000), + Results = run_sched_workers(InitF,ExecF,FiniF,20000), TotCnts = lists:foldl(fun(Diffs, Sum) -> add_lists(Sum,tuple_to_list(Diffs)) end, lists:duplicate(Mod, 0), Results), io:format("TotCnts = ~p\n",[TotCnts]), @@ -5662,7 +5662,7 @@ smp_select_replace(Config) when is_list(Config) -> State end, FiniF = fun (State) -> State end, - run_workers_do(InitF, ExecF, FiniF, WorkerCount), + run_sched_workers(InitF, ExecF, FiniF, WorkerCount), FinalCounts = ets:select(T, [{{'_', '$1'}, [], ['$1']}]), TotalIterations = WorkerCount * CounterIterations * erlang:system_info(schedulers), TotalIterations = lists:sum(FinalCounts), @@ -5734,7 +5734,7 @@ otp_9423(Config) when is_list(Config) -> end end, FiniF = fun(R) -> R end, - case run_workers(InitF, ExecF, FiniF, infinite, 1) of + case run_smp_workers(InitF, ExecF, FiniF, infinite, 1) of Pids when is_list(Pids) -> %%[P ! start || P <- Pids], repeat(fun() -> ets:new(otp_9423, [named_table, public, {write_concurrency,true}]), @@ -5886,9 +5886,9 @@ add_lists([],[],Acc) -> add_lists([E1|T1], [E2|T2], Acc) -> add_lists(T1, T2, [E1+E2 | Acc]). -run_workers(InitF,ExecF,FiniF,Laps) -> - run_workers(InitF,ExecF,FiniF,Laps, 0). -run_workers(InitF,ExecF,FiniF,Laps, Exclude) -> +run_smp_workers(InitF,ExecF,FiniF,Laps) -> + run_smp_workers(InitF,ExecF,FiniF,Laps, 0). +run_smp_workers(InitF,ExecF,FiniF,Laps, Exclude) -> case erlang:system_info(smp_support) of true -> run_workers_do(InitF,ExecF,FiniF,Laps, Exclude); @@ -5896,7 +5896,7 @@ run_workers(InitF,ExecF,FiniF,Laps, Exclude) -> {skipped,"No smp support"} end. -run_workers_do(InitF,ExecF,FiniF,Laps) -> +run_sched_workers(InitF,ExecF,FiniF,Laps) -> run_workers_do(InitF,ExecF,FiniF,Laps, 0). run_workers_do(InitF,ExecF,FiniF,Laps, Exclude) -> NumOfProcs = case erlang:system_info(schedulers) of -- cgit v1.2.3 From be959b91c655a5f7ab89034e285d17465f0912b1 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 3 Apr 2017 15:51:13 +0200 Subject: stdlib: Skip ets_SUITE:otp_9423 for single sched smp --- lib/stdlib/test/ets_SUITE.erl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/stdlib/test') diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl index a7fe213f40..f11ad01c16 100644 --- a/lib/stdlib/test/ets_SUITE.erl +++ b/lib/stdlib/test/ets_SUITE.erl @@ -5891,17 +5891,21 @@ run_smp_workers(InitF,ExecF,FiniF,Laps) -> run_smp_workers(InitF,ExecF,FiniF,Laps, Exclude) -> case erlang:system_info(smp_support) of true -> - run_workers_do(InitF,ExecF,FiniF,Laps, Exclude); + case erlang:system_info(schedulers_online) of + N when N > Exclude -> + run_workers_do(InitF,ExecF,FiniF,Laps, N - Exclude); + _ -> + {skipped, "Too few schedulers online"} + end; false -> {skipped,"No smp support"} end. run_sched_workers(InitF,ExecF,FiniF,Laps) -> - run_workers_do(InitF,ExecF,FiniF,Laps, 0). -run_workers_do(InitF,ExecF,FiniF,Laps, Exclude) -> - NumOfProcs = case erlang:system_info(schedulers) of - N when (N > Exclude) -> N - Exclude - end, + run_workers_do(InitF,ExecF,FiniF,Laps, + erlang:system_info(schedulers)). + +run_workers_do(InitF,ExecF,FiniF,Laps, NumOfProcs) -> io:format("smp starting ~p workers\n",[NumOfProcs]), Seeds = [{ProcN,rand:uniform(9999)} || ProcN <- lists:seq(1,NumOfProcs)], Parent = self(), -- cgit v1.2.3 From 781fbe4f35ef6d9281a6310a595260fdec0ed2ec Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 4 Apr 2017 15:10:16 +0200 Subject: stdlib: Limit ets_SUITE:smp_select_replace to run 3*3 seconds to avoid timeout on slow machines. --- lib/stdlib/test/ets_SUITE.erl | 73 ++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 35 deletions(-) (limited to 'lib/stdlib/test') diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl index f11ad01c16..2dfd481665 100644 --- a/lib/stdlib/test/ets_SUITE.erl +++ b/lib/stdlib/test/ets_SUITE.erl @@ -5637,40 +5637,43 @@ smp_select_delete(Config) when is_list(Config) -> ets:delete(T). smp_select_replace(Config) when is_list(Config) -> - lists:foreach( - fun (TableType) -> - T = ets_new(smp_select_replace, [TableType, named_table, public, - {write_concurrency, true}]), - WorkerCount = 20, - CounterIterations = 10000, - InitF = fun (_) -> no_state end, - ExecF = fun (State) -> - lists:foreach( - fun F(IterId) -> - CounterId = rand:uniform(WorkerCount), - Match = [{{'$1', '$2'}, - [{'=:=', '$1', CounterId}], - [{{'$1', {'+', '$2', 1}}}]}], - case ets:select_replace(T, Match) of - 1 -> ok; - 0 -> - ets:insert_new(T, {CounterId, 1}) orelse - F(IterId) - end - end, - lists:seq(1, CounterIterations)), - State - end, - FiniF = fun (State) -> State end, - run_sched_workers(InitF, ExecF, FiniF, WorkerCount), - FinalCounts = ets:select(T, [{{'_', '$1'}, [], ['$1']}]), - TotalIterations = WorkerCount * CounterIterations * erlang:system_info(schedulers), - TotalIterations = lists:sum(FinalCounts), - WorkerCount = ets:select_delete(T, [{{'_', '_'}, [], [true]}]), - 0 = ets:info(T, size), - ets:delete(T) - end, - [ordered_set, set, duplicate_bag]). + repeat_for_opts(fun smp_select_replace_do/1, + [[set,ordered_set,duplicate_bag]]). + +smp_select_replace_do(Opts) -> + T = ets_new(smp_select_replace, + [public, {write_concurrency, true} | Opts]), + ObjCount = 20, + InitF = fun (_) -> 0 end, + ExecF = fun (Cnt0) -> + CounterId = rand:uniform(ObjCount), + Match = [{{'$1', '$2'}, + [{'=:=', '$1', CounterId}], + [{{'$1', {'+', '$2', 1}}}]}], + Cnt1 = case ets:select_replace(T, Match) of + 1 -> Cnt0+1; + 0 -> + ets:insert_new(T, {CounterId, 0}), + Cnt0 + end, + receive stop -> + [end_of_work | Cnt1] + after 0 -> + Cnt1 + end + end, + FiniF = fun (Cnt) -> Cnt end, + Pids = run_sched_workers(InitF, ExecF, FiniF, infinite), + receive after 3*1000 -> ok end, + [P ! stop || P <- Pids], + Results = wait_pids(Pids), + FinalCounts = ets:select(T, [{{'_', '$1'}, [], ['$1']}]), + Total = lists:sum(FinalCounts), + Total = lists:sum(Results), + ObjCount = ets:select_delete(T, [{{'_', '_'}, [], [true]}]), + 0 = ets:info(T, size), + true = ets:delete(T), + ok. %% Test different types. types(Config) when is_list(Config) -> @@ -5906,7 +5909,7 @@ run_sched_workers(InitF,ExecF,FiniF,Laps) -> erlang:system_info(schedulers)). run_workers_do(InitF,ExecF,FiniF,Laps, NumOfProcs) -> - io:format("smp starting ~p workers\n",[NumOfProcs]), + io:format("starting ~p workers\n",[NumOfProcs]), Seeds = [{ProcN,rand:uniform(9999)} || ProcN <- lists:seq(1,NumOfProcs)], Parent = self(), Pids = [my_spawn_link(fun()-> worker(Seed,InitF,ExecF,FiniF,Laps,Parent,NumOfProcs) end) -- cgit v1.2.3