perf: a few retries in the pool

This commit is contained in:
Simon Cruanes 2023-06-07 21:12:37 -04:00
parent 86684c642f
commit 327045f5c5
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

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