Neo4j OutOfMemory问题

这是我的Main.java的源代码。 它是从neo4j-apoc-1.0例子中抓取的。 修改的目的是存储2个节点和1个关系的1Mlogging:

package javaapplication2; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.kernel.EmbeddedGraphDatabase; public class Main { private static final String DB_PATH = "neo4j-store-1M"; private static final String NAME_KEY = "name"; private static enum ExampleRelationshipTypes implements RelationshipType { EXAMPLE } public static void main(String[] args) { GraphDatabaseService graphDb = null; try { System.out.println( "Init database..." ); graphDb = new EmbeddedGraphDatabase( DB_PATH ); registerShutdownHook( graphDb ); System.out.println( "Start of creating database..." ); int valIndex = 0; for(int i=0; i<1000; ++i) { for(int j=0; j<1000; ++j) { Transaction tx = graphDb.beginTx(); try { Node firstNode = graphDb.createNode(); firstNode.setProperty( NAME_KEY, "Hello" + valIndex ); Node secondNode = graphDb.createNode(); secondNode.setProperty( NAME_KEY, "World" + valIndex ); firstNode.createRelationshipTo( secondNode, ExampleRelationshipTypes.EXAMPLE ); tx.success(); ++valIndex; } finally { tx.finish(); } } } System.out.println("Ok, client processing finished!"); } finally { System.out.println( "Shutting down database ..." ); graphDb.shutdown(); } } private static void registerShutdownHook( final GraphDatabaseService graphDb ) { // Registers a shutdown hook for the Neo4j instance so that it // shuts down nicely when the VM exits (even if you "Ctrl-C" the // running example before it's completed) Runtime.getRuntime().addShutdownHook( new Thread() { @Override public void run() { graphDb.shutdown(); } } ); } } 

经过几次迭代(大约150K)后,我得到了错误信息:

“java.lang.OutOfMemoryError:java.nio.HeapByteBuffer上的Java空间(HeapByteBuffer.java:39)在org.neo4j.kernel.impl.nioneo上的java.nio.ByteBuffer.allocate(ByteBuffer.java:312)上。 store.PlainPersistenceWindow。(PlainPersistenceWindow.java:30)at org.neo4j.kernel.impl.nioneo.store.PersistenceWindowPool.allocateNewWindow(PersistenceWindowPool.java:534)at org.neo4j.kernel.impl.nioneo.store.PersistenceWindowPool.refreshBricks (PersistenceWindowPool.java:430)at org.neo4j.kernel.impl.nioneo.store.PersistenceWindowPool.acquire(PersistenceWindowPool.java:122)at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.acquireWindow(CommonAbstractStore.java :459)at org.neo4j.kernel.impl.nioneo.store.AbstractDynamicStore.updateRecord(AbstractDynamicStore.java:240)at org.neo4j.kernel.impl.nioneo.store.PropertyStore.updateRecord(PropertyStore.java:209)at org.neo4j.kernel.impl.nioneo.xa.Command $ PropertyCommand.execute(Command.java:513)at org.neo4j.kernel.impl.nioneo.xa.NeoTransaction.doCommit(Ne (org.neo4j.kernel.impl.transaction.xaframework.XaTransaction.commit(XaTransaction.java:316)at org.neo4j.kernel.impl.transaction.xaframework.XaResourceManager.commit(XaResourceManager.java:oTransaction.java:443) 399)at org.neo4j.kernel.impl.transaction.xaframework.XaResourceHelpImpl.commit(XaResourceHelpImpl.java:64)at org.neo4j.kernel.impl.transaction.TransactionImpl.doCommit(TransactionImpl.java:514)at org.neo4j .kernel.impl.transaction.TxManager.commit(TxManager.java:571)at org.neo4j.kernel.impl.transaction.TxManager.commit(TxManager.java:543)at org.neo4j.kernel.impl.transaction.TransactionImpl .commit(TransactionImpl.java:102)at org.neo4j.kernel.EmbeddedGraphDbImpl $ TransactionImpl.finish(EmbeddedGraphDbImpl.java:329)at javaapplication2.Main.main(Main.java:62)28.05.2010 9:52:14 org .neo4j.kernel.impl.nioneo.store.PersistenceWindowPool logWarn警告:[neo4j-store-1M \ neostore.propertystore.db.strings]无法分配直接缓冲区“

伙计们! 帮助我plzzz,我做错了什么,我怎么修复它? 在平台上testingWindows XP 32bit SP3。 也许解决scheme创build自定义configuration?

thnx 4每个build议!

Solutions Collecting From Web of "Neo4j OutOfMemory问题"

这是Windows上的配置问题,其中Neo4j不能使用内存映射缓冲区。 而是创建堆上的Java缓冲区。 在1.0中,这个缓冲区是默认的470MB,比Windows JVM的默认堆大。 你有两个选择:

  1. 在具有自动配置的pom.xml中切换到APOC 1.1-SNAPSHOT而不是1.0,将最多50%的可用JVM堆分配给Neo4j

  2. 通过运行Java调整JVM堆到更多(例如512Mb)

    java -Xmx512m ….

    您甚至可以在Eclipse的“运行配置”中将其插入到JVM参数下

让我们知道这是否有帮助!

另外,为每个节点对做一个完整的交易将需要很长时间。 尝试在第一个循环中打开一个事务,并只提交每1000个节点对?

/彼得