I’ve created an elixir app wich creates a set of processes (about 900) with a lot of calculation distributed among all theese processes. I need to calculate the time spent between the started time and the last calculation (wich can occurr in any process). What’s the best way to calculate the execution time of my distributed application?
But in this case, the run() function ends up prior than the other 900 processes. I will have only the time spent for the mains process, not the others. I need to capture the moment the last process (in a known list) finished his job.
Got it! I’ll need to change my code a litle bit but I’ve got the idea! The goal is send a message to the main process when each sub-process finish his hob. God idea! Thank you!
I’ve created a different way to check if the processes ended up their jobs. The main idea here is create a process wich will inspect all processes (I have all PIDs in a list) and check if they have message to be processed and their status is different from “waiting”. When all processes finished their message queue and set their status to “waiting” I will understand the job is done. The code is something like this:
#---------------------------------------------------------
def wait_up_to_end_all_process() do
# wait until all process have message queue empty and status is waiting
elements = get_element_list_total()
check_message_queue_loop(elements)
end
defp check_message_queue_loop(elements) do
if check_message_queue(elements) > 0 do
:timer.sleep(10)
check_message_queue_loop(elements)
end
defp check_message_queue([]) do
0 #List empty - all elements are queue empty
end
defp check_message_queue([ pid | elements]) do
info = Process.info(pid)
count =
if info[:message_queue_len] == 0 and info[:status] == :waiting do
0
else
1
end
count + check_message_queue(elements)
end