2016-03-03 91 views
1

我有一個Neo4j數據庫,有大約130K個節點,可能在17M關係之間。我的電腦運行Windows 10有16GB的RAM,其中10GB(最大)分配給Neo4j-shell堆。Neo4j:從neo4j-shell運行密碼查詢時出現OutOfMemoryError

我想在命令提示符下使用neo4j-shell運行一個查詢,並將結果重定向到一個csv文件。我使用該命令是:

Neo4jShell -v -file query.cql > results.csv 

當查詢的形式爲:

MATCH (subject)-[:type1]->(intNode1:label)<-[:type2]-(intNode2:label)<-[:type3]-(object) RETURN subject.property1, object.property1; 

的問題是,每當我運行此查詢,我得到一個OutOfMemory錯誤(見錯誤消息在底部)。

有沒有人有如何成功地運行這樣的查詢的建議?考慮到圖形數據庫的大小,我覺得10GB的RAM應該足夠用於這樣的查詢。

該錯誤消息我得到的是:

ERROR (-v for expanded information): 
     Error occurred in server thread; nested exception is: 
     java.lang.OutOfMemoryError: GC overhead limit exceeded 
java.rmi.ServerError: Error occurred in server thread; nested exception is: 
     java.lang.OutOfMemoryError: GC overhead limit exceeded 
     at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) 
     at sun.rmi.transport.Transport$2.run(Unknown Source) 
     at sun.rmi.transport.Transport$2.run(Unknown Source) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at sun.rmi.transport.Transport.serviceCall(Unknown Source) 
     at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) 
     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source) 
     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.access$400(Unknown Source) 
     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(Unknown Source) 
     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(Unknown Source) 
     at java.security.AccessController.doPrivileged(Native Method) 
     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 
     at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source) 
     at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source) 
     at sun.rmi.server.UnicastRef.invoke(Unknown Source) 
     at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source) 
     at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source) 
     at com.sun.proxy.$Proxy1.interpretLine(Unknown Source) 
     at org.neo4j.shell.impl.AbstractClient.evaluate(AbstractClient.java:149) 
     at org.neo4j.shell.impl.AbstractClient.evaluate(AbstractClient.java:133) 
     at org.neo4j.shell.StartClient.executeCommandStream(StartClient.java:393) 
     at org.neo4j.shell.StartClient.grabPromptOrJustExecuteCommand(StartClient.java:372) 
     at org.neo4j.shell.StartClient.startRemote(StartClient.java:330) 
     at org.neo4j.shell.StartClient.start(StartClient.java:196) 
     at org.neo4j.shell.StartClient.main(StartClient.java:135) 
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded 

回答

0

解決方案時,我哈德這個問題是要增加對neo4j.properties

# Default values for the low-level graph engine 

    cache_type=none 
    neostore.nodestore.db.mapped_memory=50M 
    neostore.relationshipstore.db.mapped_memory=500M 
    neostore.propertystore.db.mapped_memory=100M 
    neostore.propertystore.db.strings.mapped_memory=100M 
    neostore.propertystore.db.arrays.mapped_memory=0M 

也結束這一行嘗試增加java中的Neo4j -wrapper.conf這一行

#wrapper.java.initmemory=2048 
#wrapper.java.maxmemory=2048 

還有一件事你有索引節點上,你查詢?

+0

我只是用Neo4j的導入工具導入數據庫。我不確定這是否會創建索引,或者如果我需要手動執行它?感謝您的建議。當我到家裏的電腦時,我會嘗試他們,看看它是否有效。 – 12MonthsASlav

+0

另外,你的電腦有多少內存?所以我知道如何設置我的記憶設置。 – 12MonthsASlav

+0

我添加#wrapper.java.initmemory = 2048 #wrapper.java.maxmemory = 2048 – NKD

0

您可以爲Neo4jShell提供更多堆(使用JAVA_OPTS=-Xmx4G -Xms4G -Xmn1G環境變量)。

您是否嘗試使用配置文件運行查詢?由於您沒有任何限制,我認爲您可以跨越數十億條路徑。

您錯過了主題和對象的標籤,這會導致查詢計劃程序運行全圖掃描。

MATCH (subject:label)-[:type1]->(intNode1:label) 
       <-[:type2]-(intNode2:label) 
       <-[:type3]-(object:label) 
WITH distinct subject, object 
RETURN subject.property1, object.property1; 

您應該降低中間基數和輸出基數。

MATCH (subject:label)-[:type1]->(intNode1:label) 
       <-[:type2]-(intNode2:label) 
WITH distinct subject, intNode2 
MATCH (intNode2)<-[:type3]-(object:label) 
WITH distinct subject, object 
RETURN subject.property1, object.property1; 

更妙的是:

MATCH (subject:label)-[:type1]->(intNode1:label) 
       <-[:type2]-(intNode2:label) 
WITH intNode2, collect(distinct subject) as subjects 
MATCH (intNode2)<-[:type3]-(object:label) 
WITH distinct object, subjects 
UNWIND subjects as subject 
RETURN subject.property1, object.property1; 
+1

對,我將堆大小更改爲10GB,但是這與我的計算機相當。我故意留下標題和目標,因爲我不知道他們應該事先做些什麼。查詢的目標是找到指定模式中涉及的主體和對象的所有獨特組合,並返回它們的屬性。另外,我沒有使用配置文件運行查詢。這將如何幫助完全? – 12MonthsASlav