From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XR0Zl-0000cI-6M for qemu-devel@nongnu.org; Mon, 08 Sep 2014 11:10:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XR0Zc-0001jv-6S for qemu-devel@nongnu.org; Mon, 08 Sep 2014 11:09:53 -0400 Received: from mail-qg0-x233.google.com ([2607:f8b0:400d:c04::233]:37468) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XR0Zc-0001jr-0L for qemu-devel@nongnu.org; Mon, 08 Sep 2014 11:09:44 -0400 Received: by mail-qg0-f51.google.com with SMTP id e89so2008752qgf.38 for ; Mon, 08 Sep 2014 08:09:43 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <540DC6B2.8060704@redhat.com> Date: Mon, 08 Sep 2014 17:09:38 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1410178693-23370-1-git-send-email-benoit.canet@nodalink.com> <1410178693-23370-4-git-send-email-benoit.canet@nodalink.com> <540DBD46.7030207@redhat.com> <20140908144936.GA5723@irqsave.net> In-Reply-To: <20140908144936.GA5723@irqsave.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?windows-1252?Q?Beno=EEt_Canet?= Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, =?windows-1252?Q?Beno=EEt_Canet?= Il 08/09/2014 16:49, Benoît Canet ha scritto: >> > - create two windows, with twice the suggested expiration period, and >> > return min/avg/max from the oldest window. Example >> > >> > t=0 |t=1 |t=2 |t=3 |t=4 >> > wnd0: [0,1) |wnd0: [1,3) | |wnd0: [3,5) | >> > wnd1: [0,2) | |wnd1: [2,4) | | >> > >> > Values are returned from: >> > >> > wnd0---------|wnd1---------|wnd0---------|wnd1---------| > > This is neat. Alternatively, you can make it probabilistically correct: t=0 |t=0.66 |t=1.33 |t=2 |t=2.66 |wnd0: [0.66,2) | |wnd0: [2,3.33) | wnd1: [0,0.66) | |wnd1: [1.33,2.66) | | Return from: wnd1-----------|wnd1-------------|wnd0---------------|wnd1-------------|wnd0 So you always have 2/3 seconds worth of data, and on average exactly 1 second worth of data. The problem is the delay in getting data, which can be big for the minute- and hour-based statistics. Suppose you have a spike that lasts 10 seconds, it might not show in the minute-based statistics for as much as 30 seconds after it ends (the window switches every 40 seconds). For min/max you could return min(min0, min1) and max(max0, max1). Only the average has this problem. Exponential smoothing doesn't have this problem. IIRC uptime uses that. Paolo