[virt-tools-list] [vhostmd v2 5/5] Fix update_interval behaviour

Jim Fehlig jfehlig at suse.com
Tue Oct 23 21:07:15 UTC 2018


On 10/5/18 8:34 AM, Michael Trapp wrote:
> 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 | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)

Reviewed-by: Jim Fehlig <jfehlig at suse.com>

Regards,
Jim

> 
> diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
> index 1718df2..9ce43f4 100644
> --- a/vhostmd/vhostmd.c
> +++ b/vhostmd/vhostmd.c
> @@ -969,6 +969,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 "
> @@ -987,7 +990,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(update_period - run_time);
> +
>         vu_buffer_erase(buf);
>      }
>      vu_buffer_delete(buf);
> 




More information about the virt-tools-list mailing list