Skip to content

Commit

Permalink
CP-51692: Event.next: use same batching as Event.from
Browse files Browse the repository at this point in the history
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 <edwin.torok@cloud.com>
  • Loading branch information
edwintorok committed Dec 12, 2024
1 parent efaa606 commit 3e1d8a2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ocaml/xapi/xapi_event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand All @@ -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
Expand Down

0 comments on commit 3e1d8a2

Please sign in to comment.