mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-12 14:00:41 -05:00
perf: a few retries in the pool
This commit is contained in:
parent
86684c642f
commit
327045f5c5
1 changed files with 13 additions and 9 deletions
22
src/pool.ml
22
src/pool.ml
|
|
@ -39,10 +39,12 @@ let run (self : t) (f : task) : unit =
|
|||
|
||||
try
|
||||
(* try each queue with a round-robin initial offset *)
|
||||
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
|
||||
if Bb_queue.try_push q f then raise_notrace Exit
|
||||
for _retry = 1 to 3 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
|
||||
if Bb_queue.try_push q f then raise_notrace Exit
|
||||
done
|
||||
done;
|
||||
push_wait ()
|
||||
with
|
||||
|
|
@ -67,11 +69,13 @@ let worker_thread_ ~on_exn (active : bool A.t) (qs : task Bb_queue.t array)
|
|||
|
||||
let task =
|
||||
try
|
||||
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 -> ()
|
||||
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
|
||||
done;
|
||||
pop_blocking ()
|
||||
with Got_task f -> f
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue