pool: do some spinning in run, not in workers

This commit is contained in:
Simon Cruanes 2023-06-08 14:49:28 -04:00
parent 939c6e117c
commit 82af5497f8
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -39,7 +39,7 @@ let run (self : t) (f : task) : unit =
try
(* try each queue with a round-robin initial offset *)
for _retry = 1 to 3 do
for _retry = 1 to 10 do
for i = 0 to n_qs - 1 do
let q_idx = (i + offset) mod Array.length self.qs in
let q = self.qs.(q_idx) in
@ -69,13 +69,11 @@ let worker_thread_ ~on_exn (active : bool A.t) (qs : task Bb_queue.t array)
let task =
try
for _retry = 1 to 3 do
for i = 0 to num_qs - 1 do
let q = qs.((offset + i) mod num_qs) in
match Bb_queue.try_pop ~force_lock:false q with
| Some f -> raise_notrace (Got_task f)
| None -> ()
done
for i = 0 to num_qs - 1 do
let q = qs.((offset + i) mod num_qs) in
match Bb_queue.try_pop ~force_lock:false q with
| Some f -> raise_notrace (Got_task f)
| None -> ()
done;
pop_blocking ()
with Got_task f -> f