这有点像:Neo4j OutOfMemory 问题
但它已经过时了,据我所知,解决方案显然也是如此。
所以我试图插入大约 10 万个具有 550 万关系的节点(我实际上削减了我的数据集,所以它现在更像是具有 280 万关系的 <100K 节点)。
过了一会儿,它的内存用完了,我得到一个像这样的异常:
Exception in thread "GC-Monitor" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at java.lang.StringBuilder.toString(Unknown Source)
at org.neo4j.kernel.impl.util.StringLogger$ActualStringLogger.logMessage(StringLogger.java:276)
at org.neo4j.kernel.impl.cache.MeasureDoNothing.run(MeasureDoNothing.java:85)
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.LinkedList.addBefore(Unknown Source)
at java.util.LinkedList.add(Unknown Source)
at org.neo4j.kernel.impl.nioneo.store.IdGeneratorImpl.freeId(IdGeneratorImpl.java:291)
at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.freeId(CommonAbstractStore.java:382)
at org.neo4j.kernel.impl.nioneo.xa.WriteTransaction.doRollback(WriteTransaction.java:315)
at org.neo4j.kernel.impl.transaction.xaframework.XaTransaction.rollback(XaTransaction.java:278)
at org.neo4j.kernel.impl.transaction.xaframework.XaResourceManager.rollback(XaResourceManager.java:518)
at org.neo4j.kernel.impl.transaction.xaframework.XaResourceHelpImpl.rollback(XaResourceHelpImpl.java:111)
at org.neo4j.kernel.impl.transaction.TransactionImpl.doRollback(TransactionImpl.java:558)
at org.neo4j.kernel.impl.transaction.TxManager.rollback(TxManager.java:610)
at org.neo4j.kernel.impl.transaction.TransactionImpl.rollback(TransactionImpl.java:129)
at org.neo4j.kernel.TopLevelTransaction.finish(TopLevelTransaction.java:119)
at sqlToGraph.SqlToGraph.main(SqlToGraph.java:81)
我已经尝试将 -Xmx1500m 传递给 java,这大约是我可以通过的限制,因为在它抱怨无法分配堆空间之前。它持续的时间明显更长,但仍然没有完成。
这是(略微编辑的)代码:
/* Postgres query and setup stuff cut */
Transaction tx = graphDb.beginTx();
try {
while (rs.next()) {
user_lo = rs.getInt(1);
user_hi = rs.getInt(2);
n_lo = getOrCreate(user_lo, graphDb);
n_lo.setProperty("user_id", user_lo);
n_lo.setProperty("total", rs.getInt(3));
n_hi = getOrCreate(user_hi, graphDb);
n_hi.setProperty("user_id", user_hi);
n_hi.setProperty("total", rs.getInt(4));
relationship = n_lo.createRelationshipTo(n_hi, RelTypes.PLAYED_WITH);
relationship.setProperty("mean_percent", rs.getDouble(5));
}
tx.success();
} finally {
tx.finish();
}
graphDb.shutdown();