Java 实例化graphDb数据库实例耗时问题
发布于 4 个月前 作者 xiaomei208 333 次浏览 来自 问答

我用的是Java 嵌入式方式连接数据库, graphDb=new GraphDatabaseFactory() .newEmbeddedDatabase(new File(“D:\Program Files\neo4j-community-3.1.7\data\databases\graph.db”)); 现在我看了一下数据库文件夹有16G这么大,每次实例化数据库的时候都特别费时间,请问有人知道这是怎么回事吗?

9 回复

这确实有些大,耗时多少?前后加个时间戳看看

我现在的数据库文件夹是16.2G,用的电脑win7 64位,内存16G,neo4j.conf里面的两个参数设置如下: dbms.memory.heap.initial_size=1024m dbms.memory.heap.max_size=6000m 现在单纯的开启neo4j服务是可以的,但是在eclipse里面通过上面的方式实例化数据库就会抛出异常,eclipse.ini里面设置的 -Xms1024m -Xmx7000m, <Exception in thread “main” java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory, D:\Program Files\neo4j-community-3.1.7\data\databases\graph.db at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:199) at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:130) at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:101) at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$0(GraphDatabaseFactory.java:89) at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183) at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:66) at seu.lxm.neo4j.cube.LevelSG.<init><(LevelSG.java:31) at seu.lxm.neo4j.cube.LevelSG.main(LevelSG.java:493) Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component ‘org.neo4j.kernel.recovery.Recovery@ceba2c1’ failed to initialize. Please see the attached cause exception “GC overhead limit exceeded”. at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:415) at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62) at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:98) at org.neo4j.kernel.NeoStoreDataSource.start(NeoStoreDataSource.java:525) at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433) at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107) at org.neo4j.kernel.impl.transaction.state.DataSourceManager.start(DataSourceManager.java:100) at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433) at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107) at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:195) … 7 more Caused by: org.neo4j.kernel.api.exceptions.TransactionApplyKernelException: Failed to apply transaction: Transaction #13530 at log position LogPosition{logVersion=39, byteOffset=124530012} {started 2017-10-15 02:23:32.897+0000, committed 2017-10-15 02:23:33.286+0000, with 79351 commands in this transaction, authored by -1, with master id -1, lock session -1, latest committed transaction id when started was 13529, additional header bytes: 4E 6C 2C 3F B3 F0 21 BC} at org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine.apply(RecordStorageEngine.java:358) at org.neo4j.kernel.recovery.DefaultRecoverySPI.lambda$startRecovery$0(DefaultRecoverySPI.java:94) at org.neo4j.kernel.impl.api.TransactionQueue.empty(TransactionQueue.java:67) at org.neo4j.kernel.recovery.DefaultRecoverySPI.allTransactionsRecovered(DefaultRecoverySPI.java:112) at org.neo4j.kernel.recovery.Recovery.init(Recovery.java:109) at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:405) … 16 more Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded at org.neo4j.kernel.impl.locking.AbstractLockService.lock(AbstractLockService.java:63) at org.neo4j.kernel.impl.locking.AbstractLockService.acquireNodeLock(AbstractLockService.java:52) at org.neo4j.kernel.impl.locking.ReentrantLockService.acquireNodeLock(ReentrantLockService.java:35) at org.neo4j.kernel.impl.transaction.command.NeoStoreTransactionApplier.visitNodeCommand(NeoStoreTransactionApplier.java:69) at org.neo4j.kernel.impl.transaction.command.Command$NodeCommand.handle(Command.java:215) at org.neo4j.kernel.impl.api.TransactionApplierFacade.visit(TransactionApplierFacade.java:61) at org.neo4j.kernel.impl.api.TransactionApplierFacade.visit(TransactionApplierFacade.java:35) at org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation.accept(PhysicalTransactionRepresentation.java:69) at org.neo4j.kernel.impl.api.TransactionToApply.accept(TransactionToApply.java:115) at org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine.apply(RecordStorageEngine.java:350) at org.neo4j.kernel.recovery.DefaultRecoverySPI.lambda$startRecovery$0(DefaultRecoverySPI.java:94) at org.neo4j.kernel.recovery.DefaultRecoverySPI$$Lambda$135/1326162578.apply(Unknown Source) at org.neo4j.kernel.impl.api.TransactionQueue.empty(TransactionQueue.java:67) at org.neo4j.kernel.recovery.DefaultRecoverySPI.allTransactionsRecovered(DefaultRecoverySPI.java:112) at org.neo4j.kernel.recovery.Recovery.init(Recovery.java:109) at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:405) at org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62) at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:98) at org.neo4j.kernel.NeoStoreDataSource.start(NeoStoreDataSource.java:525) at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433) at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107) at org.neo4j.kernel.impl.transaction.state.DataSourceManager.start(DataSourceManager.java:100) at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433) at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107) at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:195) at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:130) at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:101) at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$0(GraphDatabaseFactory.java:89) at org.neo4j.graphdb.factory.GraphDatabaseFactory$$Lambda$1/1586600255.newDatabase(Unknown Source) at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183) at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:66) at seu.lxm.neo4j.cube.LevelSG.<init><(LevelSG.java:31) > neo4j.conf里的这两个值我是一点点加的,之前单纯开启服务一直报Java栈溢出或者GC,一直到设置为1G和6000m才正常开启服务,现在eclipse实例化这个数据库也是这样报异常,我重新设置了Xms和Xmx,仍然没用。希望知道原因的人帮忙告诉一下解决办法,或者解决思路之类的,不胜感激。

@pangguoming 现在是实例化不成功,报异常,如2楼。所以也看不了时间了。。。

@pangguoming 实例化数据库162.304s。有什么别的方法可以更快一些吗?跟嵌入式、服务器模式有关系吗?

我是在16G内存的linux服务器上用和你类似的代码初始化neo4j,没有进行任何配置都是默认的,我的数据库.db文件大约15g,首次实例化启动数据库也不会超过60s

你好,我看你用java初始化neo4j的代码是没有用到neo4j.conf的,嵌入式访问数据库是如何加载neo4j.conf文件的呢,在用java嵌入式方式使用neo4j有哪些常用配置可以让我参考下吗

@sun361504834 原因是什么我也不清楚,我也是这几天把数据导进去之后发现的这个问题。

@sun361504834 代码里没有用到neo4j.conf,但是这个貌似是默认会根据这里的设置来配置数据库的吧。常用配置的话…,我就修改了一下Java Heap Size,其他得参数看你自己吧,配置文件里对每个参数的作用都解释的很清楚,你可以根据自己的需要来修改。

@sun361504834 按照你的说法,我们两个现在的用的是类似的方法实例化一个16G的数据库,但是区别是:1,你的是16G linux,我的是16G windows;2、你没有任何的配置,我的conf文件修改了Java Heap Size(我修改的原因是内存溢出,不得不改,你的却没问题)。 你不超过60s,我的是160s…

回到顶部