From 5b4cb893de07877a02e6e8c8f8e418da24441d2f Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Fri, 17 May 2019 02:02:02 -0700 Subject: [PATCH] [processpool] schedule work to idle workers once per refresh cycle Reviewed By: mbouaziz Differential Revision: D15373840 fbshipit-source-id: 77359a243 --- infer/src/base/ProcessPool.ml | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/infer/src/base/ProcessPool.ml b/infer/src/base/ProcessPool.ml index d6e8774f4..c5765d9b1 100644 --- a/infer/src/base/ProcessPool.ml +++ b/infer/src/base/ProcessPool.ml @@ -162,24 +162,21 @@ let process_updates pool buffer = has_dead_child pool |> Option.iter ~f:(fun (slot, status) -> killall pool ~slot (Unix.Exit_or_signal.to_string_hum status) ) ; - match wait_for_updates pool buffer with - | Some (UpdateStatus (slot, t, status)) -> - TaskBar.update_status pool.task_bar ~slot t status - | Some (Crash slot) -> - let {pid} = pool.slots.(slot) in - (* clean crash, give the child process a chance to cleanup *) - Unix.wait (`Pid pid) |> ignore ; - killall pool ~slot "see backtrace above" - | Some (Ready slot) -> - TaskBar.tasks_done_add pool.task_bar 1 ; - send_work_to_child pool slot - | None -> ( - (* no updates, so try to schedule more work if there is an idle worker *) - match Array.findi pool.pending_items ~f:(fun _idx item -> Option.is_none item) with - | None -> - () - | Some (idle_slot, _) -> - send_work_to_child pool idle_slot ) + (* try to schedule more work if there is an idle worker *) + Array.findi pool.pending_items ~f:(fun _idx item -> Option.is_none item) + |> Option.iter ~f:(fun (idle_slot, _) -> send_work_to_child pool idle_slot) ; + wait_for_updates pool buffer + |> Option.iter ~f:(function + | UpdateStatus (slot, t, status) -> + TaskBar.update_status pool.task_bar ~slot t status + | Crash slot -> + let {pid} = pool.slots.(slot) in + (* clean crash, give the child process a chance to cleanup *) + Unix.wait (`Pid pid) |> ignore ; + killall pool ~slot "see backtrace above" + | Ready slot -> + TaskBar.tasks_done_add pool.task_bar 1 ; + send_work_to_child pool slot ) (** terminate all worker processes *)