Skip to content

Commit 35dcd13

Browse files
committed
CA-409482: Using computed delay for RRD loop
RRD loop is executed each 5 seconds. It delays fixed 5 seconds between each loop. But the loop self also consumes time (The time consuming depends on CPU's count. If there are many CPUs, the time consuming may be hundreds milliseconds). This implementation leads RRD will take an offset after several loops. Then one of RRD data lose and a gap can be observed on XenCenter performance graph. The solution is to use computed delay (timeslice - loop time consuming) instead of fixed delay. Signed-off-by: Bengang Yuan <[email protected]>
1 parent 18e8584 commit 35dcd13

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,17 +537,30 @@ let monitor_write_loop writers =
537537
Xenctrl.with_intf (fun xc ->
538538
while true do
539539
try
540+
let last_loop_start_time = Unix.gettimeofday () in
540541
do_monitor_write xc writers ;
541542
with_lock Rrdd_shared.last_loop_end_time_m (fun _ ->
542543
Rrdd_shared.last_loop_end_time := Unix.gettimeofday ()
543544
) ;
544-
Thread.delay !Rrdd_shared.timeslice
545+
(* Using computed delay (timeslice - loop time consuming) instead
546+
of fixed delay*)
547+
let delay =
548+
!Rrdd_shared.timeslice
549+
-. (!Rrdd_shared.last_loop_end_time -. last_loop_start_time)
550+
in
551+
if delay > 0.0 then
552+
Thread.delay delay
553+
else
554+
warn
555+
"%s: Monitor write loop took so long time that the delay \
556+
(%f) is less than 0, so skip the delay"
557+
__FUNCTION__ delay
545558
with e ->
546559
Backtrace.is_important e ;
547560
warn
548-
"Monitor/write thread caught an exception. Pausing for 10s, \
549-
then restarting: %s"
550-
(Printexc.to_string e) ;
561+
"%s: Monitor/write thread caught an exception. Pausing for \
562+
10s, then restarting: %s"
563+
__FUNCTION__ (Printexc.to_string e) ;
551564
log_backtrace e ;
552565
Thread.delay 10.
553566
done

0 commit comments

Comments
 (0)