Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edNY9-0006GP-Q7 for pgsql-general@arkaria.postgresql.org; Sun, 21 Jan 2018 21:53:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edNY9-0005cm-CV for pgsql-general@arkaria.postgresql.org; Sun, 21 Jan 2018 21:53:13 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1edNY9-0005cd-1F for pgsql-general@lists.postgresql.org; Sun, 21 Jan 2018 21:53:13 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1edNY3-0004xd-L5 for pgsql-general@lists.postgresql.org; Sun, 21 Jan 2018 21:53:11 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 8CDFD1687; Sun, 21 Jan 2018 22:53:04 +0100 (CET) Date: Sun, 21 Jan 2018 22:53:04 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: How to measure query time - with warm up and cached data Message-ID: <20180121215304.otzwhlcem5mphi4f@hjp.at> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7paaoxieqag5z6gm" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --7paaoxieqag5z6gm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018-01-21 12:45:54 -0800, Neto pr wrote: > I need to know the actual execution time of a query, but considering that= the > data is already cached. I also need to make sure that cached data from ot= her > queries is cleared. > I believe that in order to know the real time of a query it will be neces= sary > to "warm up" the data to be inserted in cache. >=20 > Below are the steps suggested by a DBA for me: >=20 > Step 1- run ANALYZE on all tables involved before the test; > Step 2- restart the DBMS (to clear the DBMS cache); > Step 3- erase the S.O. cache; Did you mean "OS cache" (operating system cache)?=20 > Step 4- execute at least 5 times the same query. >=20 > After the actual execution time of the query, it would have to take the t= ime of > the query that is in the "median" among all. If you do this, clearing the caches before the tests will probably have lit= tle effekt. The first query will fill the cache with the data needed for your query (possibly evicting other data) and the next 4 will work on the cached data. Whether the cache was empty or full before the first query will make little difference to the median, because the first query will almost certainly be discarded as an outlier. Flushing out caches is very useful if you want to measure performance without caches (e.g. if you want to determine what the performance impact of a server reboot is). > Example: >=20 > Execution 1: 07m 58s > Execution 2: 14m 51s > Execution 3: 17m 59s > Execution 4: 17m 55s > Execution 5: 17m 07s Are these real measurements or did you make them up? They look weird. Normally the first run is by far the slowest, then the others are very similar, sometimes with a slight improvement (especially between the 2nd and 3rd). But in your case it is just the opposite. > [cleardot] Sending Webbugs to a mailinglist? hp --=20 _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --7paaoxieqag5z6gm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlplC7sACgkQ8g5IURL+ KF2N5g/+LxOPWXiYX0pBqtdrF8WvMDYShh+mfx7T9TV9hcHeFANG4nHmRtEb5i2d ohNRMFNJncufgI48l2xBua9JAvMAmes5Qn5AC1+r6QDjAvPbn+/QWGNoyNDnUATq fYNzzbVlgo+7IX+S0uyY3k6X8EiN01HdVyl8cqtcynH+MwNI48xwFgp/QGUIpMoQ jUyJpcQEoL7leGSknYYFFtancJb9wM1I+CxK+pnoVxP7p112VSXjLPJSFF8N+HDy ftoeW0WN3w7NaUUH8+naoK3AivfOrzEQPt1IIr4tAlzCNukPJzllx0qg8BjMA8dg x+Y7PMKSKM5lzQNypF1fB9XhTqUEaMVcThkbZiNAzdAC0n4iNHNUHmp9S6cNrZZv IGAK+VCclEXcp7c4+Eqv3f4r58runV7JNHGQ2CxmL/ZbQWocfgmqfS4XmwW3J7UP e/SxMcSiyTOldP9oENelU0DpoV8PqPi/8zCROvhTP4tqA6ugOHxVr3kve++ctNH0 1QQARaTgf9y0F7MwDJ5ZZtKxK5fHQ3vKKAlkKVQVB7wqcANATBgJf/tJD8fAsPmU y5yJu17Le9Ra/C4/OtV69bI2+C0cI3mvI8m/jjFdbYvBAk9p5iPKW/FYewTbG8xJ xplNpmclhI1uGaaBy7djs78C24fbcPbTUhD76Ock0jUNUgFqn5s= =pMuN -----END PGP SIGNATURE----- --7paaoxieqag5z6gm--