Question about speed: Weird Behavior

From: Israel Ben Guilherme Fonseca <israel(dot)bgf(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Question about speed: Weird Behavior
Date: 2011-06-13 03:14:07
Message-ID: BANLkTimTaoOnVMcuUhnhE5VodRVDSTyH0w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I'm doing some speed tests, and I noticed something very strange.

My test code:

Connection con =
DriverManager.getConnection("jdbc:postgresql://localhost:5432/tcc","postgres","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.

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.

Even when I close the connection and open a new one, the new queries still
get faster.

--

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

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2011-06-13 03:39:55 Re: Question about speed: Weird Behavior
Previous Message Craig Ringer 2011-06-09 14:24:28 Re: PGPoolingDataSource problem.