2014-07-09 24 views
0

我試圖從Twitter上的用戶和追隨者的50MB文本文件導入數據到Neo4j。但是我的代碼只運行到達到大約10000個節點並拋出錯誤:「java.lang.OutOfMemoryError:超出GC開銷限制」。這是我的代碼,我不知道我在哪裏做錯了?Neo4j中無法導入超過10000個節點

 BufferedReader br = new BufferedReader(new FileReader(inputFile)); 
    String currentLine; 
    String token[] = null; 

    try (Transaction tx = graphDb.beginTx()) { 
     Label userLabel = DynamicLabel.label("User"); 

     while((currentLine = br.readLine()) != null) { 
      if(!currentLine.equals("\n")) token = currentLine.split("\t"); 
      if(token.length > 2) { 

       userNode = graphDb.createNode(userLabel); 
       userNode.setProperty("username", token[2]); 
       userNode.setProperty("id", token[1]); 
       userNode.setProperty("cookie", token[0]); 
       System.out.println("Insert user: " + token[0] + " " + token[1] + " " + token[2]); 
       System.out.println("Insert follower..."); 

       for(int i=3;i<token.length;i++) { 
        followerNode = graphDb.createNode(userLabel); 
        followerNode.setProperty("id", token[i]); 
        relationship = userNode.createRelationshipTo(followerNode, RelTypes.FOLLOWED_BY); 

       } 
       System.out.println("Insert follower: done! - " + (token.length-3)); 

      } 
     } 

     tx.success(); 
    } 

    br.close(); 
+0

批量處理您的交易,例如每10K用戶提交一次tx,然後創建一個新的tx。 –

回答

1

你的問題是與neo4j,它與java。具體來說,你的堆超過了最大尺寸。

您可以:

一)優化您的代碼,以便爲它讓你堆沒有得到大(我通常不是一個談論的優化,直到發展的後期階段,但你」如果你的輸入文件只有50 MB)

b)用下面的命令行參數運行java,它允許你覆蓋最大堆大小:-Xmx1024m。這將它設置爲1024 MB,但您可以用您所需的任何東西替換1024

+0

感謝您的幫助,但在我提出之前,我已將它設置爲1024 MB,並且仍會引發相同的錯誤。也許問題出在我的代碼中。 – user3798030