How to know when a multi-spawned process set finish its work?
Giovanni Giorgi
jj@REDACTED
Mon Apr 12 18:08:54 CEST 2021
Hi all,
a newbie question here.
I have done a small erlang server following the behavior application,
here
https://github.com/daitangio/er_zauker/blob/erlang-24-migration/src/er_zauker_app.erl
To make a long story short, my server scans a set of directories and
index files using redis as backend database.
It works well when I runs on small set of files.
But when I run it on a very huge set of files, it seems to "finish"
before indexing all the files; when it starts, the client wait until
every file is processed and the server can send him a report about the
status:
er_zauker_indexer!{self(),directory,"."},
er_zauker_app:wait_worker_done().
The relevant part seems correct (see below) but I think I have done a
stupid mistake, but I cannot understand where is it.
Where can I find an example for this use case?
wait_worker_done()->
waitAllWorkerDone(1,erlang:monotonic_time(second)).
waitAllWorkerDone(RunningWorker,StartTimestamp) when RunningWorker >0 ->
er_zauker_indexer!{self(),report},
receive
{worker,0} ->
io:format("All workers done~n~n");
{worker, RunningGuys, files_processed, TotalFilesDone} ->
if
RunningGuys /= RunningWorker ->
SecondsRunning=
erlang:monotonic_time(second)-StartTimestamp,
FilesSec=TotalFilesDone/SecondsRunning,
io:format("[~p]s Workers[~p] Files processed:~p Files/sec:
~p ~n",[SecondsRunning,RunningGuys,TotalFilesDone,FilesSec]),
timer:sleep(200);
true ->
%% Okey so nothing changed so far...sleep a bit
timer:sleep(100)
end,
%% Master sleep value
timer:sleep(990),
waitAllWorkerDone(RunningGuys,StartTimestamp)
after 5000 ->
io:format("~n-----------------------------~n"),
io:format(" Mmmm no info in the last 5 sec... when was
running:~p Workers~n",[RunningWorker]),
io:format(" ?System is stuck? "),
io:format("------------------------------~n"),
waitAllWorkerDone(RunningWorker,StartTimestamp)
end;
waitAllWorkerDone(0,_) ->
io:format("All worker Finished").
--
Giovanni Giorgi via webmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210412/81a55270/attachment.htm>
More information about the erlang-questions
mailing list