From 3e1d8a27a755597f5237dd74496cfe968da3321c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Thu, 18 Apr 2024 21:49:09 +0100 Subject: [PATCH] CP-51692: Event.next: use same batching as Event.from MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Event.next is deprecated, but was allowed to use a lot more CPU in a tight loop than Event.from. No feature flag for this one, because Event.next is deprecated. Signed-off-by: Edwin Török --- ocaml/xapi/xapi_event.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ocaml/xapi/xapi_event.ml b/ocaml/xapi/xapi_event.ml index 388d6130820..3563d01a5f2 100644 --- a/ocaml/xapi/xapi_event.ml +++ b/ocaml/xapi/xapi_event.ml @@ -470,6 +470,10 @@ let unregister ~__context ~classes = (** Blocking call which returns the next set of events relevant to this session. *) let rec next ~__context = + let batching = + Throttle.Batching.make ~delay_before:Mtime.Span.zero + ~delay_between:Mtime.Span.(50 * ms) + in let session = Context.get_session_id __context in let open Next in assert_subscribed session ; @@ -489,11 +493,12 @@ let rec next ~__context = ) in (* Like grab_range () only guarantees to return a non-empty range by blocking if necessary *) - let rec grab_nonempty_range () = + let grab_nonempty_range = + Throttle.Batching.with_recursive_loop batching @@ fun self () -> let last_id, end_id = grab_range () in if last_id = end_id then let (_ : int64) = wait subscription end_id in - grab_nonempty_range () + (self [@tailcall]) () else (last_id, end_id) in