这有点类似于Neo4j内存不足问题
但这个问题已经过时了,而且据我所知,解决方案也是过时的。
所以我试图插入大约10万个节点和550万个关系(实际上我缩小了数据集,现在更像是不到10万个节点和280万个关系)。
一段时间后,它会耗尽内存,然后我会收到以下异常:
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();