pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Performance problem with timestamps in result sets
16+ messages / 7 participants
[nested] [flat]

* Performance problem with timestamps in result sets
@ 2006-03-08 13:37  Thomas Dudziak <tomdzk@gmail.com>
  0 siblings, 3 replies; 16+ messages in thread

From: Thomas Dudziak @ 2006-03-08 13:37 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

while profiling an application of ours, I noticed a performance
problem with the PostgreSQL JDBC driver (the same for any version:
8.0, 8.1, 8.2dev-501).
In short, whenever the ResultSet contains a timestamp value, the JDBC
driver takes nearly one second to extract it (this is against a 8.0 on
Windows, database and application on the same machine; with a
non-development configuration, the number would be a bit lower).
The profiling shows that the culprit is

-> AbstractJdbc2ResultSet.getTimestamp(int) : 7130ms | 8190 calls
    -> TimestampUtils.loadCalendar(GregorianCalendar, String, String)
: 5417ms | 8190 calls
        -> TimestampUtils.firstNonDigit : 2163ms | 49140 times
        -> TimestampUtils.number(String, int, int) : 1562ms | 49140 times

Now my question is, is there something to make this faster ? Nearly
1sec for a ResulSet.getTimestamp call is too much for us.

cheers,
Tom



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 14:11  Dave Cramer <pg@fastcrypt.com>
  parent: Thomas Dudziak <tomdzk@gmail.com>
  2 siblings, 1 reply; 16+ messages in thread

From: Dave Cramer @ 2006-03-08 14:11 UTC (permalink / raw)
  To: Thomas Dudziak <tomdzk@gmail.com>; +Cc: pgsql-jdbc

Thomas,

That can't possibly be ...

Dave
On 8-Mar-06, at 8:37 AM, Thomas Dudziak wrote:

> Hi,
>
> while profiling an application of ours, I noticed a performance
> problem with the PostgreSQL JDBC driver (the same for any version:
> 8.0, 8.1, 8.2dev-501).
> In short, whenever the ResultSet contains a timestamp value, the JDBC
> driver takes nearly one second to extract it (this is against a 8.0 on
> Windows, database and application on the same machine; with a
> non-development configuration, the number would be a bit lower).
> The profiling shows that the culprit is
>
> -> AbstractJdbc2ResultSet.getTimestamp(int) : 7130ms | 8190 calls
>     -> TimestampUtils.loadCalendar(GregorianCalendar, String, String)
> : 5417ms | 8190 calls
>         -> TimestampUtils.firstNonDigit : 2163ms | 49140 times
>         -> TimestampUtils.number(String, int, int) : 1562ms | 49140  
> times
>
> Now my question is, is there something to make this faster ? Nearly
> 1sec for a ResulSet.getTimestamp call is too much for us.
>
> cheers,
> Tom
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that  
> your
>        message can get through to the mailing list cleanly
>




^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Performance problem with timestamps in result sets
@ 2006-03-08 14:15  Thomas Dudziak <tomdzk@gmail.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Thomas Dudziak @ 2006-03-08 14:15 UTC (permalink / raw)
  To: pgsql-jdbc

On 3/8/06, Dave Cramer <pg@fastcrypt.com> wrote:

> That can't possibly be ...

But it is: in profiling the getTimestamp method takes 10x longer than
the getString or getInt methods.

Tom



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 14:21  Michael Paesold <mpaesold@gmx.at>
  parent: Thomas Dudziak <tomdzk@gmail.com>
  0 siblings, 1 reply; 16+ messages in thread

From: Michael Paesold @ 2006-03-08 14:21 UTC (permalink / raw)
  To: Thomas Dudziak <tomdzk@gmail.com>; pgsql-jdbc

Thomas Dudziak wrote

> On 3/8/06, Dave Cramer <pg@fastcrypt.com> wrote:
> 
> > That can't possibly be ...
> 
> But it is: in profiling the getTimestamp method takes 10x longer than
> the getString or getInt methods.

What profiler are you using? What are the settings?
Profiling can add significant overhead...

Best Regards,
Michael Paesold





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Performance problem with timestamps in result sets
@ 2006-03-08 14:24  Thomas Dudziak <tomdzk@gmail.com>
  parent: Michael Paesold <mpaesold@gmx.at>
  0 siblings, 0 replies; 16+ messages in thread

From: Thomas Dudziak @ 2006-03-08 14:24 UTC (permalink / raw)
  To: pgsql-jdbc

On 3/8/06, Michael Paesold <mpaesold@gmx.at> wrote:

> What profiler are you using? What are the settings?
> Profiling can add significant overhead...

YourKit 5.1.1 (newest version) against Java 5 Update 6, with method
timing and invocation counting (which makes it somewhat slower, I'd
say 10-15%).
The interesting figure is that getTimestamp takes 10x more than
getString or getInt.

Tom



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 14:50  Michael Paesold <mpaesold@gmx.at>
  parent: Thomas Dudziak <tomdzk@gmail.com>
  2 siblings, 1 reply; 16+ messages in thread

From: Michael Paesold @ 2006-03-08 14:50 UTC (permalink / raw)
  To: Thomas Dudziak <tomdzk@gmail.com>; pgsql-jdbc

Thomas Dudziak wrote:

> -> AbstractJdbc2ResultSet.getTimestamp(int) : 7130ms | 8190 calls
>
> Now my question is, is there something to make this faster ? Nearly
> 1sec for a ResulSet.getTimestamp call is too much for us.

This should be 1 ms per getTimestamp call, shouldn't it? The time is the 
aggregate time for ~8000 calls. That is still rather slow, yeah, but it is 
so with profiling.

Best Regards,
Michael Paesold 





^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 14:57  Thomas Dudziak <tomdzk@gmail.com>
  parent: Michael Paesold <mpaesold@gmx.at>
  0 siblings, 2 replies; 16+ messages in thread

From: Thomas Dudziak @ 2006-03-08 14:57 UTC (permalink / raw)
  To: Michael Paesold <mpaesold@gmx.at>; +Cc: pgsql-jdbc

On 3/8/06, Michael Paesold <mpaesold@gmx.at> wrote:

> This should be 1 ms per getTimestamp call, shouldn't it? The time is the
> aggregate time for ~8000 calls. That is still rather slow, yeah, but it is
> so with profiling.

Yep, but as I said, the others are much faster. E.g. getString takes
140ms for 5460 calls, and getInt 570ms for 10920 calls, so its
probably not so much the profiler.
Also, I was merely asking whether there is something that could be
done to bring getTimestamp at least in the same region.

cheers,
Tom



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 15:01  Oliver Jowett <oliver@opencloud.com>
  parent: Thomas Dudziak <tomdzk@gmail.com>
  2 siblings, 1 reply; 16+ messages in thread

From: Oliver Jowett @ 2006-03-08 15:01 UTC (permalink / raw)
  To: Thomas Dudziak <tomdzk@gmail.com>; +Cc: pgsql-jdbc

Thomas Dudziak wrote:

> In short, whenever the ResultSet contains a timestamp value, the JDBC
> driver takes nearly one second to extract it 

> -> AbstractJdbc2ResultSet.getTimestamp(int) : 7130ms | 8190 calls

> Now my question is, is there something to make this faster ? Nearly
> 1sec for a ResulSet.getTimestamp call is too much for us.

Your profiling numbers show about 0.9 milliseconds per call, not 1 
second per call, if I am reading them right?

That's still slower than I would have expected, though. I did no 
profiling at the time I rewrote the timestamp stuff to actually work 
correctly. Perhaps you'd like to profile in more detail and submit some 
patches?

-O



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 15:04  Thomas Dudziak <tomdzk@gmail.com>
  parent: Oliver Jowett <oliver@opencloud.com>
  0 siblings, 0 replies; 16+ messages in thread

From: Thomas Dudziak @ 2006-03-08 15:04 UTC (permalink / raw)
  To: pgsql-jdbc

On 3/8/06, Oliver Jowett <oliver@opencloud.com> wrote:

> Your profiling numbers show about 0.9 milliseconds per call, not 1
> second per call, if I am reading them right?

Yep, my mistake in the formulating the sentence.

> That's still slower than I would have expected, though. I did no
> profiling at the time I rewrote the timestamp stuff to actually work
> correctly. Perhaps you'd like to profile in more detail and submit some
> patches?

Yep, I'll put together a testcase (can't give you my original
profiling data because they are against our application, and way to
complicated anyway) and give you the profiling data.

cheers,
Tom



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 15:08  mikael-aronsson <mikael-aronsson@telia.com>
  parent: Thomas Dudziak <tomdzk@gmail.com>
  1 sibling, 3 replies; 16+ messages in thread

From: mikael-aronsson @ 2006-03-08 15:08 UTC (permalink / raw)
  To: Thomas Dudziak <tomdzk@gmail.com>; +Cc: pgsql-jdbc

I do not think there is much more to do, the timestamp is just a 64 bit 
integer and you say an int takes 570ms/10920 calls and a timestamp takes 
7130ms/8190 calls, this is about twice as much to get twice as much data.

Mikael

----- Original Message ----- 
From: "Thomas Dudziak" <tomdzk@gmail.com>
To: "Michael Paesold" <mpaesold@gmx.at>
Cc: <pgsql-jdbc@postgresql.org>
Sent: Wednesday, March 08, 2006 3:57 PM
Subject: Re: [JDBC] Performance problem with timestamps in result sets


On 3/8/06, Michael Paesold <mpaesold@gmx.at> wrote:

> This should be 1 ms per getTimestamp call, shouldn't it? The time is the
> aggregate time for ~8000 calls. That is still rather slow, yeah, but it is
> so with profiling.

Yep, but as I said, the others are much faster. E.g. getString takes
140ms for 5460 calls, and getInt 570ms for 10920 calls, so its
probably not so much the profiler.
Also, I was merely asking whether there is something that could be
done to bring getTimestamp at least in the same region.

cheers,
Tom

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster 




^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 15:11  Oliver Jowett <oliver@opencloud.com>
  parent: Thomas Dudziak <tomdzk@gmail.com>
  1 sibling, 0 replies; 16+ messages in thread

From: Oliver Jowett @ 2006-03-08 15:11 UTC (permalink / raw)
  To: Thomas Dudziak <tomdzk@gmail.com>; +Cc: Michael Paesold <mpaesold@gmx.at>; pgsql-jdbc

Thomas Dudziak wrote:
> On 3/8/06, Michael Paesold <mpaesold@gmx.at> wrote:
> 
> 
>>This should be 1 ms per getTimestamp call, shouldn't it? The time is the
>>aggregate time for ~8000 calls. That is still rather slow, yeah, but it is
>>so with profiling.
> 
> 
> Yep, but as I said, the others are much faster. E.g. getString takes
> 140ms for 5460 calls, and getInt 570ms for 10920 calls, so its
> probably not so much the profiler.

getTimestamp() does many more internal method invocations than getInt() 
so the per-method overhead of your profiler will have a larger effect on 
getTimestamp(). Consider that some of the utility methods that 
getTimestamp() calls internally are very small and will be inlined by 
the JIT in normal operation..

I would try an external benchmark without profiling to get more 
comparable numbers: record start time, call getTimestamp() 1000000 
times, record end time; repeat for getInt(). A warmup loop is a good 
idea too if you want to measure the JITted performance, 8000 invocations 
is not much in terms of what the JIT does.

> Also, I was merely asking whether there is something that could be
> done to bring getTimestamp at least in the same region.

There is no simple go-faster change I know of. Then again I've not heard 
of any performance problems in this area before.

If you do come up with some performance-improving changes, by all means 
post them to the list for integration into the official driver..

-O



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 15:12  Thomas Dudziak <tomdzk@gmail.com>
  parent: mikael-aronsson <mikael-aronsson@telia.com>
  2 siblings, 0 replies; 16+ messages in thread

From: Thomas Dudziak @ 2006-03-08 15:12 UTC (permalink / raw)
  To: pgsql-jdbc

On 3/8/06, mikael-aronsson <mikael-aronsson@telia.com> wrote:

> I do not think there is much more to do, the timestamp is just a 64 bit
> integer and you say an int takes 570ms/10920 calls and a timestamp takes
> 7130ms/8190 calls, this is about twice as much to get twice as much data.

No, thats about 16x slower (and most of the time is spent in the JDBC
driver, not on the wire).

Tom



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 16:25  Steve Wampler <swampler@noao.edu>
  parent: mikael-aronsson <mikael-aronsson@telia.com>
  2 siblings, 1 reply; 16+ messages in thread

From: Steve Wampler @ 2006-03-08 16:25 UTC (permalink / raw)
  To: mikael-aronsson <mikael-aronsson@telia.com>; +Cc: Thomas Dudziak <tomdzk@gmail.com>; pgsql-jdbc

On Wed, Mar 08, 2006 at 04:08:13PM +0100, mikael-aronsson wrote:
> I do not think there is much more to do, the timestamp is just a 64 bit 
> integer and you say an int takes 570ms/10920 calls and a timestamp takes 
> 7130ms/8190 calls, this is about twice as much to get twice as much data.

Eh?  7130 / 8190.0 = 0.8705738705738706
      570 /10920.0 = 0.0521978021978022

Which is >16X difference.  While may be as much as can be done, it's
more than twice as much to get twice the data.

-- 
Steve Wampler -- swampler@noao.edu
The gods that smiled on your birth are now laughing out loud.



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-08 18:40  Thomas Dudziak <tomdzk@gmail.com>
  parent: Steve Wampler <swampler@noao.edu>
  0 siblings, 0 replies; 16+ messages in thread

From: Thomas Dudziak @ 2006-03-08 18:40 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

I've run the attached sample with these results (1.000.000 rows):

no profiler: 7.850ms for the int's, 58.902ms for the timestamp's

cpu profiling: 8.865ms for the int's, 60.357ms for the timestamp's

cpu profiling with method count: 262.802ms for the ints, 695.188ms for
the timestamps

 - getTimestamp(int) took 499.047ms for the  1.000.000 invocations
   with toTimestamp(Calendar, String) 378.854ms of that
   in contrast, getLong(int) took 169.703ms

It does not seem linear (the profiler definitely has some influence,
though a strange one).

Tom

Attachments:

  Main.java (application/octet-stream, 3.2K) download

^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-03-09 08:54  Oliver Jowett <oliver@opencloud.com>
  parent: mikael-aronsson <mikael-aronsson@telia.com>
  2 siblings, 0 replies; 16+ messages in thread

From: Oliver Jowett @ 2006-03-09 08:54 UTC (permalink / raw)
  To: mikael-aronsson <mikael-aronsson@telia.com>; +Cc: Thomas Dudziak <tomdzk@gmail.com>; pgsql-jdbc

mikael-aronsson wrote:
> I do not think there is much more to do, the timestamp is just a 64 bit 
> integer and you say an int takes 570ms/10920 calls and a timestamp takes 
> 7130ms/8190 calls, this is about twice as much to get twice as much data.

This is wrong, and not just because your maths is wrong ;-)  Timestamps 
are not "just a 64 bit integer" on the wire.

getTimestamp() is parsing a string representation of a timestamp 
(multiple numeric fields, separators, etc) and massaging it into a 
Timestamp in the right timezone (retriving the right Calendar and 
converting to a milliseconds-per-epoch value from the individual 
components and timezone info)

getInt() is parsing a string representation of a single number.

So I'd expect getTimestamp() to be noticably slower than getInt(), which 
is what we see.

Going to binary-format results would help, as then you can transfer the 
underlying value directly rather than having the backend format it all 
then have the JDBC driver parse it, but noone has done that yet. One big 
obstacle is that binary format results are somewhat all-or-nothing, it's 
tricky to do it for only a single datatype. You'd also still have to do 
some timezone conversion work, I think.

-O



^ permalink  raw  reply  [nested|flat] 16+ messages in thread

* Re: Performance problem with timestamps in result sets
@ 2006-04-03 23:24  Nicholas E. Wakefield <nwakefield@KineticNetworks.com>
  0 siblings, 0 replies; 16+ messages in thread

From: Nicholas E. Wakefield @ 2006-04-03 23:24 UTC (permalink / raw)
  To: pgsql-jdbc

I just read this thread, as I to have found timestamp processing to be a
bottleneck and maybe there is nothing that can be done about it, without
going binary. However the firstNonDigit method could be optimized,
currently it uses isDigit, which does a lot more than checking if a
character is between 0 and 9 (Though I'm not sure if this would work for
all languages). Anyway I'm going to poke around and see if I can find a
way to bring the number down from 40% in my app.  

> There is no simple go-faster change I know of. Then again I've not 
> heard of any performance problems in this area before. 
> If you do come up with some performance-improving changes, by all 
> means post them to the list for integration into the official driver..



* 40.1% - 51,652 ms - 92,028 inv. 
	org.postgresql.jdbc2.TimestampUtils.toTimestamp 
	o 37.0% - 47,598 ms - 92,028 inv. 
		org.postgresql.jdbc2.TimestampUtils.loadCalendar 
		* 19.1% - 24,538 ms - 736,224 inv. 
	
org.postgresql.jdbc2.TimestampUtils.firstNonDigit 
Nicholas



^ permalink  raw  reply  [nested|flat] 16+ messages in thread


end of thread, other threads:[~2006-04-03 23:24 UTC | newest]

Thread overview: 16+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-08 13:37 Performance problem with timestamps in result sets Thomas Dudziak <tomdzk@gmail.com>
2006-03-08 14:11 ` Dave Cramer <pg@fastcrypt.com>
2006-03-08 14:15   ` Thomas Dudziak <tomdzk@gmail.com>
2006-03-08 14:21     ` Michael Paesold <mpaesold@gmx.at>
2006-03-08 14:24       ` Thomas Dudziak <tomdzk@gmail.com>
2006-03-08 14:50 ` Michael Paesold <mpaesold@gmx.at>
2006-03-08 14:57   ` Thomas Dudziak <tomdzk@gmail.com>
2006-03-08 15:08     ` mikael-aronsson <mikael-aronsson@telia.com>
2006-03-08 15:12       ` Thomas Dudziak <tomdzk@gmail.com>
2006-03-08 16:25       ` Steve Wampler <swampler@noao.edu>
2006-03-08 18:40         ` Thomas Dudziak <tomdzk@gmail.com>
2006-03-09 08:54       ` Oliver Jowett <oliver@opencloud.com>
2006-03-08 15:11     ` Oliver Jowett <oliver@opencloud.com>
2006-03-08 15:01 ` Oliver Jowett <oliver@opencloud.com>
2006-03-08 15:04   ` Thomas Dudziak <tomdzk@gmail.com>
2006-04-03 23:24 Re: Performance problem with timestamps in result sets Nicholas E. Wakefield <nwakefield@KineticNetworks.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