Erlang 太多的过程,为什么?
我试图解决的问题是 编写一个环基准。在环中创建N个进程。发送消息 在环上绕行M次,以便总共发送N*M条消息。 N和M的不同值所需的时间 我的尝试看起来像Erlang 太多的过程,为什么?,erlang,Erlang,我试图解决的问题是 编写一个环基准。在环中创建N个进程。发送消息 在环上绕行M次,以便总共发送N*M条消息。 N和M的不同值所需的时间 我的尝试看起来像 -module(ring). -author("harith"). %% API -export([message/2, test/0]). test() -> Max = erlang:system_info(process_limit), io:format("max processes: ~p~n", [Max]),
-module(ring).
-author("harith").
%% API
-export([message/2, test/0]).
test() ->
Max = erlang:system_info(process_limit),
io:format("max processes: ~p~n", [Max]),
Time = [timer:tc(ring, message, [N, M]) || N <- lists:seq(10, 500, 10), M <- lists:seq(1000, 100000, 1000)],
[io:format("(~p)processes, (~p) messages, (~p) microseconds~n", [N, M, T]) || {T, {N, M}} <- Time].
% create ring of N processes and
% send M messages between them
message(N, M) when is_integer(N), is_integer(M), N > 0, M > 0 ->
Ring = create_ring(N),
[Start | T] = Ring,
Start ! {T, Ring, 1, M},
{N, M}.
create_ring(N) ->
Processes = [spawn(fun() -> loop() end) || _ <- lists:seq(1, N)],
[H | _] = Processes,
lists:append(Processes, [H]).
loop() ->
receive
{[H | T], _L, CurrentMessage, M} ->
% io:format("~p received ~p~n", [self(), CurrentMessage]),
H ! {T, _L, CurrentMessage, M},
loop();
{[], Ring, CurrentMessage, M} ->
% io:format("~p received ~p with empty list~n", [self(), CurrentMessage]),
case CurrentMessage < M of
true ->
[_ | [Next | T]] = Ring,
NewMessage = CurrentMessage + 1,
% io:format("sending message ~p to ~p~n", [NewMessage, Next]),
Next ! {T, Ring, NewMessage, M};
false -> void %io:format("done sending ~p messages in ~p ring, taking rest now.~n", [M, Ring])
end,
loop()
end.
我试图从中找出整数的和
10, 20, 30, ...., 500
差异10
我试图找出序列中的n=术语数,如
对于a1=10,an=500,d=10,结果是n=50
我发现总和为
结果是(10+500)*50/2
12750,根据日志,可以创建的最大进程为
max processes: 262144
有人能帮我理解这个问题吗
谢谢你12750的数字是正确的。但您在此列表中调用ring:message/2
:
[timer:tc(ring, message, [N, M]) || N <- lists:seq(10, 500, 10), M <- lists:seq(1000, 100000, 1000)]
[timer:tc(铃声,信息,[N,M])| | N您的12750数字是正确的。但您在此列表中调用ring:message/2
:
[timer:tc(ring, message, [N, M]) || N <- lists:seq(10, 500, 10), M <- lists:seq(1000, 100000, 1000)]
[timer:tc(铃声,信息,[N,M])| | N您的12750数字是正确的。但您在此列表中调用ring:message/2
:
[timer:tc(ring, message, [N, M]) || N <- lists:seq(10, 500, 10), M <- lists:seq(1000, 100000, 1000)]
[timer:tc(铃声,信息,[N,M])| | N您的12750数字是正确的。但您在此列表中调用ring:message/2
:
[timer:tc(ring, message, [N, M]) || N <- lists:seq(10, 500, 10), M <- lists:seq(1000, 100000, 1000)]
[计时器:tc(铃声,信息,[N,M])|N