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