From c91bdc31462daa7714a96f48ef71ed7c9d63aafc Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 1 Jul 2025 11:50:11 +0200 Subject: [PATCH] Octez_connpool: Optimize connection pool warm-up This commit optimizes the connection pool warm-up process by introducing a `pre_heat` function that establishes all connections concurrently. The previous `warm` function established connections sequentially, which could be slow if the pool size is large. This change speeds up the application startup time by parallelizing the initial connection setup. The new `pre_heat` function uses `List.iter_p` to concurrently request a connection from the pool for each available slot. This forces the `Lwt_pool` to establish all underlying connections in parallel. The original `warm` function, now renamed to `re_warm`, is called afterward to ensure all connections are ready. --- src/lib_connpool/octez_connpool.ml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib_connpool/octez_connpool.ml b/src/lib_connpool/octez_connpool.ml index 3821f420c9b4..265c602574ba 100644 --- a/src/lib_connpool/octez_connpool.ml +++ b/src/lib_connpool/octez_connpool.ml @@ -117,13 +117,20 @@ let make_uri uri ?query ?userinfo route = exception Call_failure of exn +let pre_heat t = + List.iter_p + (fun _ -> Lwt_pool.use t.pool (fun _conn -> Lwt.return_unit)) + (1 -- t.pool_len) + let warm t = + let open Lwt_syntax in Opentelemetry.Trace.with_ ~service_name:"Octez_connpool" "warm" @@ fun _ -> - let rec warm n pool = + let rec re_warm n pool = Lwt_pool.use pool @@ fun _conn -> - if n > 1 then warm (n - 1) pool else Lwt.return_unit + if n > 1 then re_warm (n - 1) pool else return_unit in - warm t.pool_len t.pool + let* () = pre_heat t in + re_warm t.pool_len t.pool let add_traceparent_header header ({trace_id; span_id; _} : Opentelemetry.Scope.t) = -- GitLab