pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
getFastLong gets longs slowly
3+ messages / 3 participants
[nested] [flat]

* getFastLong gets longs slowly
@ 2014-05-28 21:54 Joshua Engel <postgres@purgo.net>
  2014-05-29 08:46 ` Re: getFastLong gets longs slowly Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Joshua Engel @ 2014-05-28 21:54 UTC (permalink / raw)
  To: pgsql-jdbc

I tracked down a performance problem to the JDBC driver's getFastLong
function.

For very large long values (in particular, Long.MAX_VALUE and MIN_VALUE), a
special case in getFastLong throws an exception (FAST_NUMBER_FAILED)
because it's 19 digits rather than 18. It's then caught and reprocessed
using the regular long processing code (mostly, deferring to Long.getLong).

In the JVMs I'm using (JDK 6 and 7), the delay introduced by that exception
is substantial. It's not large on a per-instance basis but I'm sorting
through a great many records, many of which are MAX_VALUE. Several
different performance measurement tools all put the blame right there.

I compiled the code myself with larger values for that cutoff, and get a
huge performance increase.

So... is there a way I can check that change in?

And incidentally, while I'm at it... is there any reason it's storing my
long values as binary coded decimal? Can I get it to stop doing that? The
whole point of using a long rather than a string value was presumably to
have it work faster.

Thanks,
Joshua Engel

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

* Re: getFastLong gets longs slowly
  2014-05-28 21:54 getFastLong gets longs slowly Joshua Engel <postgres@purgo.net>
@ 2014-05-29 08:46 ` Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
  2014-05-29 10:25   ` Re: getFastLong gets longs slowly Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Mikko Tiihonen @ 2014-05-29 08:46 UTC (permalink / raw)
  To: Joshua Engel <postgres@purgo.net>; pgsql-jdbc

If you use prepared statements the long is transferred as the raw 8 byte representation, not as numeric ascii that needs to be formatted and parsed. By default the n-th (3-5 depending on jdbc driver version) invocation of the prepared statement will switch to the binary representation.


If you do not reuse prepared statements you can set the prepareThreshold to -1 to force the binary transfers from the start (at the cost of extra initial round-trip to figure out the exact in/out parameter types).

The above setting works at in latest git code. In latest released driver you have to use -Dorg.postgresql.forcebinary=true instead.


-Mikko

________________________________
From: pgsql-jdbc-owner@postgresql.org <pgsql-jdbc-owner@postgresql.org> on behalf of Joshua Engel <postgres@purgo.net>
Sent: 29 May 2014 00:54
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] getFastLong gets longs slowly

I tracked down a performance problem to the JDBC driver's getFastLong function.

For very large long values (in particular, Long.MAX_VALUE and MIN_VALUE), a special case in getFastLong throws an exception (FAST_NUMBER_FAILED) because it's 19 digits rather than 18. It's then caught and reprocessed using the regular long processing code (mostly, deferring to Long.getLong).

In the JVMs I'm using (JDK 6 and 7), the delay introduced by that exception is substantial. It's not large on a per-instance basis but I'm sorting through a great many records, many of which are MAX_VALUE. Several different performance measurement tools all put the blame right there.

I compiled the code myself with larger values for that cutoff, and get a huge performance increase.

So... is there a way I can check that change in?

And incidentally, while I'm at it... is there any reason it's storing my long values as binary coded decimal? Can I get it to stop doing that? The whole point of using a long rather than a string value was presumably to have it work faster.

Thanks,
Joshua Engel

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

* Re: getFastLong gets longs slowly
  2014-05-28 21:54 getFastLong gets longs slowly Joshua Engel <postgres@purgo.net>
  2014-05-29 08:46 ` Re: getFastLong gets longs slowly Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
@ 2014-05-29 10:25   ` Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Dave Cramer @ 2014-05-29 10:25 UTC (permalink / raw)
  To: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>; +Cc: Joshua Engel <postgres@purgo.net>; pgsql-jdbc

You can send me a patch or create a pull request on github to get the patch
put in

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On 29 May 2014 04:46, Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
wrote:

>  If you use prepared statements the long is transferred as the raw 8 byte
> representation, not as numeric ascii that needs to be formatted and parsed.
> By default the n-th (3-5 depending on jdbc driver version) invocation of
> the prepared statement will switch to the binary representation.
>
>
>  If you do not reuse prepared statements you can set the prepareThreshold
> to -1 to force the binary transfers from the start (at the cost of extra
> initial round-trip to figure out the exact in/out parameter types).
>
> The above setting works at in latest git code. In latest released driver
> you have to use -Dorg.postgresql.forcebinary=true instead.
>
>
>  -Mikko
>  ------------------------------
> *From:* pgsql-jdbc-owner@postgresql.org <pgsql-jdbc-owner@postgresql.org>
> on behalf of Joshua Engel <postgres@purgo.net>
> *Sent:* 29 May 2014 00:54
> *To:* pgsql-jdbc@postgresql.org
> *Subject:* [JDBC] getFastLong gets longs slowly
>
>  I tracked down a performance problem to the JDBC driver's getFastLong
> function.
>
>  For very large long values (in particular, Long.MAX_VALUE and
> MIN_VALUE), a special case in getFastLong throws an exception
> (FAST_NUMBER_FAILED) because it's 19 digits rather than 18. It's then
> caught and reprocessed using the regular long processing code (mostly,
> deferring to Long.getLong).
>
>  In the JVMs I'm using (JDK 6 and 7), the delay introduced by that
> exception is substantial. It's not large on a per-instance basis but I'm
> sorting through a great many records, many of which are MAX_VALUE. Several
> different performance measurement tools all put the blame right there.
>
>  I compiled the code myself with larger values for that cutoff, and get a
> huge performance increase.
>
>  So... is there a way I can check that change in?
>
>  And incidentally, while I'm at it... is there any reason it's storing my
> long values as binary coded decimal? Can I get it to stop doing that? The
> whole point of using a long rather than a string value was presumably to
> have it work faster.
>
>  Thanks,
> Joshua Engel
>

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


end of thread, other threads:[~2014-05-29 10:25 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-05-28 21:54 getFastLong gets longs slowly Joshua Engel <postgres@purgo.net>
2014-05-29 08:46 ` Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com>
2014-05-29 10:25   ` Dave Cramer <pg@fastcrypt.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