Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 78819B5DBBE for ; Mon, 13 Jun 2011 02:18:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 62332-06 for ; Mon, 13 Jun 2011 05:17:59 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.softperience.eu (static-ip-217-118-26-141.inaddr.intergenia.de [217.118.26.141]) by mail.postgresql.org (Postfix) with ESMTP id 6E99AB5D80A for ; Mon, 13 Jun 2011 02:17:58 -0300 (ADT) Received: from radek.localnet (cbs235.neoplus.adsl.tpnet.pl [83.30.116.235]) by mail.softperience.eu (Postfix) with ESMTPA id 42E10C000C2; Mon, 13 Jun 2011 07:17:47 +0200 (CEST) From: =?utf-8?q?Rados=C5=82aw_Smogura?= To: pgsql-jdbc@postgresql.org Subject: Re: Question about speed: Weird Behavior Date: Mon, 13 Jun 2011 07:17:51 +0200 User-Agent: KMail/1.13.7 (Linux/2.6.38-gentoo-r6; KDE/4.6.3; x86_64; ; ) Cc: Israel Ben Guilherme Fonseca References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201106130717.51752.rsmogura@softperience.eu> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/25 X-Sequence-Number: 21949 Israel Ben Guilherme Fonseca Monday 13 of June 2011 05:14:07 > I'm doing some speed tests, and I noticed something very strange. > > My test code: > > Connection con = > DriverManager.getConnection("jdbc:postgresql://localhost:5432/tcc","postgre > s","postgres"); PreparedStatement pst; > ResultSet rs; > Timer timer = new Timer(); > > timer.start(); > pst = con.prepareStatement("select count(*) from Curso"); > rs = pst.executeQuery(); > rs.next(); > timer.stop(); > > timer.start(); > pst = con.prepareStatement("select * from Curso"); > rs = pst.executeQuery(); > rs.next(); > timer.stop(); > > At every stop, I print the milliseconds occurred between the begin and the > end of the operation. The results were basically > > 1st operation: 0.05 miliseconds > 2nd operation: 0.1 miliseconds > > That's ok, the strange thing is: When I comment the first operation and > re-execute the test, the execution time of the 2nd operations increases by > 50% (going to 0.15 miliseconds) > > If i inverse the order of operations, the speed is changed again, the 2nd > (now 1st) get the 50% percent increase and the count(*) get even faster > going to 0.005 miliseconds. It's not stranga, server may keep some data in buffers or in system cache. Compare your times on only 1st operations, but invoke select * in terminal. > At first glance, I thought that it could be the statement pre-compiled but > the two statements are different so it doesn't apply (i think). Using the > Wireshark tool i could notice that the package sizes get bigger > automatically (going from 8258 to 16450 and finally to 49218). From my > readings, the Java Sockets have some configurations about buffer size that > maybe is doing this. This is system autotuning - a good solution. > Even when I close the connection and open a new one, the new queries still > get faster. System cache. > -- > > Anyway, that speed increases is definitely a good thing, but why this > happens it's a mystery for me. The problem is that my benchmark tests are > influenced with this, cause the order of the tests can influence the > outcome of the total time. > > Does someone know what's is this? And how could I disable this (if > possible)? > > Thanks in advance, > > Israel