pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedOutOfMemory hibernate scroll with 2M records | Postgresql 8.4 DB
5+ messages / 5 participants
[nested] [flat]
* OutOfMemory hibernate scroll with 2M records | Postgresql 8.4 DB
@ 2009-12-22 04:15 Ankit Kumar <ankitk@xebia.com>
0 siblings, 4 replies; 5+ messages in thread
From: Ankit Kumar @ 2009-12-22 04:15 UTC (permalink / raw)
To: pgsql-jdbc
Hi
I am running a Criteria.scroll() on postgresql on a DB containing 2M
records. The memory keeps increasing and finally it generates an
OutOfMemoryException. Please can you advice how to fix this.
*Postgresql DB version:* 8.4
*Postgresql Driver Used:* postgresql-8.4-701.jdbc4.jar
Some forums do mention that "/scroll/" is slow on Postgresql.
Is this a known issue or we need to do something specific to make scroll
work on Postgresql?
It appears the driver class is loading all entity objects in memory and
not releasing them as expected in a scroll operation.
Appreciate any guidance/suggestion.
*Exception StackTrace*:
java.lang.OutOfMemoryError: Java heap space
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredField(Class.java:1880)
at
java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:181)
at
java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:65)
at java.sql.SQLException.<clinit>(SQLException.java:353)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1777)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
at
org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.scroll(Loader.java:2286)
at
org.hibernate.loader.criteria.CriteriaLoader.scroll(CriteriaLoader.java:89)
at org.hibernate.impl.SessionImpl.scroll(SessionImpl.java:1533)
at org.hibernate.impl.CriteriaImpl.scroll(CriteriaImpl.java:297)
at org.hibernate.impl.CriteriaImpl.scroll(CriteriaImpl.java:291)
at
com.hi.openname.dao.impl.HibernateKnowledgeItemDao.loadAllCommitted(HibernateKnowledgeItemDao.java:104)
at
com.hi.openname.dao.impl.HibernateKnowledgeItemDao.loadAllCommitted(HibernateKnowledgeItemDao.java:1)
Regards
Ankit
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: OutOfMemory hibernate scroll with 2M records | Postgresql 8.4 DB
@ 2009-12-22 04:35 Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
parent: Ankit Kumar <ankitk@xebia.com>
3 siblings, 0 replies; 5+ messages in thread
From: Mark Kirkwood @ 2009-12-22 04:35 UTC (permalink / raw)
To: Ankit Kumar <ankitk@xebia.com>; +Cc: pgsql-jdbc
Ankit Kumar wrote:
> Hi
>
> I am running a Criteria.scroll() on postgresql on a DB containing 2M
> records. The memory keeps increasing and finally it generates an
> OutOfMemoryException. Please can you advice how to fix this.
>
> *Postgresql DB version:* 8.4
> *Postgresql Driver Used:* postgresql-8.4-701.jdbc4.jar
>
> Some forums do mention that "/scroll/" is slow on Postgresql.
>
> Is this a known issue or we need to do something specific to make
> scroll work on Postgresql?
>
> It appears the driver class is loading all entity objects in memory
> and not releasing them as expected in a scroll operation.
>
>
> Appreciate any guidance/suggestion.
>
> *Exception StackTrace*:
> java.lang.OutOfMemoryError: Java heap space
>
>
This link might be useful for you to look at:
https://forums.hibernate.org/viewtopic.php?p=2398604&sid=f277fe884089594fe39272f69b68e329
It would appear that you need to encourage Hibernate to use a cursor,
instead of buffering the entire resultset in memory - I haven't looked
too much at the hibernate docs (never used it before...) so I have no
idea how to do this myself, but if I have time I'll dig a bit.
Do you have a self contained example to show us how you are setting up
the scrollable resultset?
regards
Mark
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: OutOfMemory hibernate scroll with 2M records | Postgresql 8.4 DB
@ 2009-12-22 04:49 Craig Ringer <craig@postnewspapers.com.au>
parent: Ankit Kumar <ankitk@xebia.com>
3 siblings, 0 replies; 5+ messages in thread
From: Craig Ringer @ 2009-12-22 04:49 UTC (permalink / raw)
To: Ankit Kumar <ankitk@xebia.com>; +Cc: pgsql-jdbc
On 22/12/2009 12:15 PM, Ankit Kumar wrote:
> Hi
>
> I am running a Criteria.scroll() on postgresql on a DB containing 2M
> records. The memory keeps increasing and finally it generates an
> OutOfMemoryException. Please can you advice how to fix this.
Why ask for help if you're just going to ignore the advice you get?
You were asked to, when you re-posted to the pgsql-jdbc list, include a
self-contained test case and some logging information, which I explained
how to get.
If you have no respect for the value of the time of the people on this
list, why should anybody bother helping you?
--
Craig Ringer
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: OutOfMemory hibernate scroll with 2M records | Postgresql 8.4 DB
@ 2009-12-22 07:52 Thomas Kellerer <spam_eater@gmx.net>
parent: Ankit Kumar <ankitk@xebia.com>
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Kellerer @ 2009-12-22 07:52 UTC (permalink / raw)
To: pgsql-jdbc
Ankit Kumar wrote on 22.12.2009 05:15:
> It appears the driver class is loading all entity objects in memory and
> not releasing them as expected in a scroll operation.
That's documented:
http://jdbc.postgresql.org/documentation/84/query.html#query-with-cursor
Just enable "query based retrieval" and the driver does not load everything into memory.
Thomas
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: OutOfMemory hibernate scroll with 2M records | Postgresql 8.4 DB
@ 2009-12-22 07:54 rsmogura@softperience.pl
parent: Ankit Kumar <ankitk@xebia.com>
3 siblings, 0 replies; 5+ messages in thread
From: rsmogura@softperience.pl @ 2009-12-22 07:54 UTC (permalink / raw)
To: Ankit Kumar <ankitk@xebia.com>; +Cc: pgsql-jdbc
It's not a place of such discussion, and this is not a bug of PG JDBC,
just Hibernate works in this way
Try to use -Xms4G and buy some RAM;) or try to set
hibernate.jdbc.fetch_size or
https://www.hibernate.org/hib_docs/v3/api/org/hibernate/Criteria.html#setFetchSize(int)
Bear in mind all entities are keep in memory until session end /
transaction end (JPA).
----
Radosław Smogura
On Tue, 22 Dec 2009 09:45:35 +0530, Ankit Kumar <ankitk@xebia.com> wrote:
> Hi
>
> I am running a Criteria.scroll() on postgresql on a DB containing 2M
> records. The memory keeps increasing and finally it generates an
> OutOfMemoryException. Please can you advice how to fix this.
>
> *Postgresql DB version:* 8.4
> *Postgresql Driver Used:* postgresql-8.4-701.jdbc4.jar
>
> Some forums do mention that "/scroll/" is slow on Postgresql.
>
> Is this a known issue or we need to do something specific to make scroll
> work on Postgresql?
>
> It appears the driver class is loading all entity objects in memory and
> not releasing them as expected in a scroll operation.
>
>
> Appreciate any guidance/suggestion.
>
> *Exception StackTrace*:
> java.lang.OutOfMemoryError: Java heap space
> at java.lang.Class.getDeclaredFields0(Native Method)
> at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
> at java.lang.Class.getDeclaredField(Class.java:1880)
> at
>
java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:181)
> at
>
java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:65)
> at java.sql.SQLException.<clinit>(SQLException.java:353)
> at
>
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1777)
> at
>
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
> at
>
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
> at
>
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
> at
>
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
> at
>
org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
> at
>
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
> at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
> at org.hibernate.loader.Loader.scroll(Loader.java:2286)
> at
>
org.hibernate.loader.criteria.CriteriaLoader.scroll(CriteriaLoader.java:89)
> at org.hibernate.impl.SessionImpl.scroll(SessionImpl.java:1533)
> at org.hibernate.impl.CriteriaImpl.scroll(CriteriaImpl.java:297)
> at org.hibernate.impl.CriteriaImpl.scroll(CriteriaImpl.java:291)
> at
>
com.hi.openname.dao.impl.HibernateKnowledgeItemDao.loadAllCommitted(HibernateKnowledgeItemDao.java:104)
> at
>
com.hi.openname.dao.impl.HibernateKnowledgeItemDao.loadAllCommitted(HibernateKnowledgeItemDao.java:1)
>
> Regards
> Ankit
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2009-12-22 07:54 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-12-22 04:15 OutOfMemory hibernate scroll with 2M records | Postgresql 8.4 DB Ankit Kumar <ankitk@xebia.com>
2009-12-22 04:35 ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
2009-12-22 04:49 ` Craig Ringer <craig@postnewspapers.com.au>
2009-12-22 07:52 ` Thomas Kellerer <spam_eater@gmx.net>
2009-12-22 07:54 ` rsmogura@softperience.pl
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