[vhostmd virtio PATCH v3 2/6] Fix update_interval behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Vhostmd uses the update_interval value to sleep() between the metrics updates.
But a long runtime of the metrics updates can result in a noticeable longer
time between the updates and a consumer might read 'old' data after waiting
update_interval seconds.
Fix the delay between updates, that
'runtime of metrics update' + 'sleep time' matches the update_interval value.
---
 vhostmd/vhostmd.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
index dc80345..e7ec2fc 100644
--- a/vhostmd/vhostmd.c
+++ b/vhostmd/vhostmd.c
@@ -39,6 +39,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
+#include <time.h>
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
 
@@ -918,6 +919,9 @@ static int vhostmd_run(int diskfd)
    }
    
    while (!down) {
+      time_t run_time,
+             start_time = time(NULL);
+
       vu_buffer_add(buf, "<metrics>\n", -1);
       if (metrics_host_get(buf))
          vu_log(VHOSTMD_ERR, "Failed to collect host metrics "
@@ -936,7 +940,11 @@ static int vhostmd_run(int diskfd)
 #endif
       if (ids)
           free(ids);
-      sleep(update_period);
+
+      run_time = time(NULL) - start_time;
+      if ((run_time > 0) && (run_time < update_period))
+         sleep((unsigned int) (update_period - run_time));
+
       vu_buffer_erase(buf);
    }
    vu_buffer_delete(buf);
-- 
2.17.2 (Apple Git-113)

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux