pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedPerformance tweaks
9+ messages / 3 participants
[nested] [flat]
* Performance tweaks
@ 2005-02-22 10:19 Ken Geis <kgeis@speakeasy.net>
0 siblings, 3 replies; 9+ messages in thread
From: Ken Geis @ 2005-02-22 10:19 UTC (permalink / raw)
To: pgsql-jdbc
I'm running some tests with PostgreSQL 8.0, JDK 1.5.0, and the CVS head
JDBC driver to see if I can squeeze some performance out of it.
I'm using an old JDBCBench program
(http://developer.mimer.com/features/feature_16.htm) as a test harness.
It seems this program's major goal is to measure the server's response
to a load, but the JDBC driver will play some part in the measurement.
I was able to get over 5% increase on my setup with a few small changes.
First, in PGStream, I "unrolled" SendInteger4 and SendInteger2, like this:
private static final byte[] B4 = new byte[4];
public void SendInteger4(int val) throws IOException
{
B4[0] = (byte) ((val >> 24)&255);
B4[1] = (byte) ((val >> 16)&255);
B4[2] = (byte) ((val >> 8)&255);
B4[3] = (byte) (val&255);
pg_output.write(B4, 0, 4);
}
Between the two of these, I got a ~4% increase. The code is slightly
uglier, but it might be worth some performance. The sneakier (and less
likely to be controversial) one was also in PGStream. I changed the line
byte[][] answer = new byte[l_nf][0];
to
byte[][] answer = new byte[l_nf][];
This gave ~1% increase on the benchmark I was running.
I'll keep you posted if I find anything else to improve. On your to-do
list, I am really looking forward to the "Allow binary data transfers
for all datatypes not just bytea."
Ken Geis
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Performance tweaks
@ 2005-02-22 21:30 Oliver Jowett <oliver@opencloud.com>
parent: Ken Geis <kgeis@speakeasy.net>
2 siblings, 2 replies; 9+ messages in thread
From: Oliver Jowett @ 2005-02-22 21:30 UTC (permalink / raw)
To: Ken Geis <kgeis@speakeasy.net>; +Cc: pgsql-jdbc
Ken Geis wrote:
> I changed the line
>
> byte[][] answer = new byte[l_nf][0];
> to
> byte[][] answer = new byte[l_nf][];
>
> This gave ~1% increase on the benchmark I was running.
Gah?! What JVM? Aren't the two forms equivalent?
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Performance tweaks
@ 2005-02-22 21:48 Alan Stange <stange@rentec.com>
parent: Oliver Jowett <oliver@opencloud.com>
1 sibling, 1 reply; 9+ messages in thread
From: Alan Stange @ 2005-02-22 21:48 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: Ken Geis <kgeis@speakeasy.net>; pgsql-jdbc
Oliver Jowett wrote:
> Ken Geis wrote:
>
>> I changed the line
>>
>> byte[][] answer = new byte[l_nf][0];
>> to
>> byte[][] answer = new byte[l_nf][];
>>
>> This gave ~1% increase on the benchmark I was running.
>
>
> Gah?! What JVM? Aren't the two forms equivalent?
No. They aren't.
The first is l_nf+1 objects being created (and array of byte[] with l_nf
byte[0] entries) and the second is just a single object (an array of
byte[], with null entries).
Any JVM. It's the language definition.
-- Alan
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Performance tweaks
@ 2005-02-22 21:50 Oliver Jowett <oliver@opencloud.com>
parent: Oliver Jowett <oliver@opencloud.com>
1 sibling, 0 replies; 9+ messages in thread
From: Oliver Jowett @ 2005-02-22 21:50 UTC (permalink / raw)
To: Ken Geis <kgeis@speakeasy.net>; +Cc: pgsql-jdbc
Oliver Jowett wrote:
> Ken Geis wrote:
>
>> I changed the line
>>
>> byte[][] answer = new byte[l_nf][0];
>> to
>> byte[][] answer = new byte[l_nf][];
>>
>> This gave ~1% increase on the benchmark I was running.
>
>
> Gah?! What JVM? Aren't the two forms equivalent?
Hmm, after some experimentation, they do produce different bytecode
(multianewarray vs. anewarray):
public void testit() {
byte[][] dummy = new byte[10][0];
byte[][] dummy2 = new byte[10][];
}
public void testit();
Code:
0: bipush 10
2: iconst_0
3: multianewarray #2, 2; //class "[[B"
7: astore_1
8: bipush 10
10: anewarray #3; //class "[B"
13: astore_2
14: return
Interesting to know it makes a performance difference. What JVM did you
test on?
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Performance tweaks
@ 2005-02-22 22:00 Oliver Jowett <oliver@opencloud.com>
parent: Alan Stange <stange@rentec.com>
0 siblings, 0 replies; 9+ messages in thread
From: Oliver Jowett @ 2005-02-22 22:00 UTC (permalink / raw)
To: Alan Stange <stange@rentec.com>; +Cc: Ken Geis <kgeis@speakeasy.net>; pgsql-jdbc
Alan Stange wrote:
> Oliver Jowett wrote:
>
>> Ken Geis wrote:
>>
>>> byte[][] answer = new byte[l_nf][0];
>>> to
>>> byte[][] answer = new byte[l_nf][];
>>
>> Gah?! What JVM? Aren't the two forms equivalent?
>
> No. They aren't.
>
> The first is l_nf+1 objects being created (and array of byte[] with l_nf
> byte[0] entries) and the second is just a single object (an array of
> byte[], with null entries).
>
> Any JVM. It's the language definition.
Ah, right. The Java multidimensional-array stuff always makes my head hurt..
The change seems obviously better, then, since we promptly go and
replace all the top-level array entries with new values.
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Performance tweaks
@ 2005-02-22 22:16 Oliver Jowett <oliver@opencloud.com>
parent: Ken Geis <kgeis@speakeasy.net>
2 siblings, 2 replies; 9+ messages in thread
From: Oliver Jowett @ 2005-02-22 22:16 UTC (permalink / raw)
To: Ken Geis <kgeis@speakeasy.net>; +Cc: pgsql-jdbc
Ken Geis wrote:
> First, in PGStream, I "unrolled" SendInteger4 and SendInteger2, like this:
>
> private static final byte[] B4 = new byte[4];
> public void SendInteger4(int val) throws IOException
> {
> B4[0] = (byte) ((val >> 24)&255);
> B4[1] = (byte) ((val >> 16)&255);
> B4[2] = (byte) ((val >> 8)&255);
> B4[3] = (byte) (val&255);
> pg_output.write(B4, 0, 4);
> }
This isn't safe across multiple PGStreams. Can you try benchmarking
again with "private final" instead of "private static final"? If that's
still a win it is probably worth changing.
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Performance tweaks
@ 2005-02-22 22:36 Oliver Jowett <oliver@opencloud.com>
parent: Ken Geis <kgeis@speakeasy.net>
2 siblings, 0 replies; 9+ messages in thread
From: Oliver Jowett @ 2005-02-22 22:36 UTC (permalink / raw)
To: Ken Geis <kgeis@speakeasy.net>; +Cc: pgsql-jdbc
Ken Geis wrote:
> The sneakier (and less
> likely to be controversial) one was also in PGStream. I changed the line
>
> byte[][] answer = new byte[l_nf][0];
> to
> byte[][] answer = new byte[l_nf][];
>
> This gave ~1% increase on the benchmark I was running.
I have applied this change (and some surrounding rearrangements to avoid
an assignment in the null case, since the initial elements are already
null) to CVS HEAD.
-O
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Performance tweaks
@ 2005-02-22 23:49 Ken Geis <kgeis@speakeasy.net>
parent: Oliver Jowett <oliver@opencloud.com>
1 sibling, 0 replies; 9+ messages in thread
From: Ken Geis @ 2005-02-22 23:49 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc
Oliver Jowett wrote:
> Ken Geis wrote:
>
>> First, in PGStream, I "unrolled" SendInteger4 and SendInteger2, like
>> this:
>>
>> private static final byte[] B4 = new byte[4];
>> public void SendInteger4(int val) throws IOException
>> {
>> B4[0] = (byte) ((val >> 24)&255);
>> B4[1] = (byte) ((val >> 16)&255);
>> B4[2] = (byte) ((val >> 8)&255);
>> B4[3] = (byte) (val&255);
>> pg_output.write(B4, 0, 4);
>> }
>
>
> This isn't safe across multiple PGStreams. Can you try benchmarking
> again with "private final" instead of "private static final"? If that's
> still a win it is probably worth changing.
I missed that glaringly obvious point!
My computer is tied up right now in a computational task. I'll get back
to you tomorrow.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Performance tweaks
@ 2005-02-23 08:20 Ken Geis <kgeis@speakeasy.net>
parent: Oliver Jowett <oliver@opencloud.com>
1 sibling, 0 replies; 9+ messages in thread
From: Ken Geis @ 2005-02-23 08:20 UTC (permalink / raw)
To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc
Oliver Jowett wrote:
> Ken Geis wrote:
>
>> First, in PGStream, I "unrolled" SendInteger4 and SendInteger2, like
>> this:
>>
>> private static final byte[] B4 = new byte[4];
>> public void SendInteger4(int val) throws IOException
>> {
>> B4[0] = (byte) ((val >> 24)&255);
>> B4[1] = (byte) ((val >> 16)&255);
>> B4[2] = (byte) ((val >> 8)&255);
>> B4[3] = (byte) (val&255);
>> pg_output.write(B4, 0, 4);
>> }
>
>
> This isn't safe across multiple PGStreams. Can you try benchmarking
> again with "private final" instead of "private static final"? If that's
> still a win it is probably worth changing.
I tested it more rigorously with this change. Not a win.
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2005-02-23 08:20 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-22 10:19 Performance tweaks Ken Geis <kgeis@speakeasy.net>
2005-02-22 21:30 ` Oliver Jowett <oliver@opencloud.com>
2005-02-22 21:48 ` Alan Stange <stange@rentec.com>
2005-02-22 22:00 ` Oliver Jowett <oliver@opencloud.com>
2005-02-22 21:50 ` Oliver Jowett <oliver@opencloud.com>
2005-02-22 22:16 ` Oliver Jowett <oliver@opencloud.com>
2005-02-22 23:49 ` Ken Geis <kgeis@speakeasy.net>
2005-02-23 08:20 ` Ken Geis <kgeis@speakeasy.net>
2005-02-22 22:36 ` Oliver Jowett <oliver@opencloud.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox