【问题标题】:Why is Neo4j(Client) running out of memory?为什么 Neo4j(Client) 内存不足?
【发布时间】:2015-07-13 11:31:42
【问题描述】:

我正在创建 100 万个节点。我必须以较小的批次创建这些以避免内存不足。现在我正在尝试删除现有节点,但我再次遇到内存不足异常。我真的应该能够删除这个级别的数据而不会耗尽内存并且不必围绕这个限制编写代码。我在这里做错了吗?

我知道我可以增加 Java 堆大小,但我觉得这只是将真正的问题推迟到稍后我有更多数据要创建/删除的时间点。

using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Neo4jClient;

    namespace Neo4JWontDelete
    {
        class Program
        {
            private const int MaximumNumberOfWordsToCreate = 1000*1000;
            private const int BatchSize = 5 * 1000;

            static void Main(string[] args)
            {
                var client = new GraphClient(new Uri("http://neo4j:Xxxxxx1@localhost:7474/db/data"));
                client.Connect();

                Console.WriteLine("Starting with a clean database");
                DeleteAllObjects(client);

                Console.WriteLine("Creating data");
                int currentWordNumber = 1;
                while (currentWordNumber < MaximumNumberOfWordsToCreate)
                {
                    int numberOfWordsToCreate = MaximumNumberOfWordsToCreate - currentWordNumber;
                    if (numberOfWordsToCreate > BatchSize)
                        numberOfWordsToCreate = BatchSize;
                    var words = Enumerable.Range(currentWordNumber, BatchSize).Select(x => new Word {Value = x.ToString()});
                    client.Cypher
                        .Create("(w:Word {words})")
                        .WithParam("words", words)
                        .ExecuteWithoutResults();
                    currentWordNumber += numberOfWordsToCreate;
                    Console.WriteLine(currentWordNumber - 1);
                }

                Console.WriteLine("Deleting data");
                DeleteAllObjects(client);
            }

            private static void DeleteAllObjects(GraphClient client)
            {
                client.Cypher
                    .Match("(w :Word)")
                    .Delete("w")
                    .ExecuteWithoutResults();
            }
    }

    class Word
    {
        public string Value { get; set; }
    }
}

【问题讨论】:

  • 为什么要将 BatchSize 和 MaximumNumberOfWordsToCreate 设置为乘法的结果,而不仅仅是 1000000 和 5000?
  • 嗨彼得,我注意到了 - 你想要一个干净的数据库还是只是删除“单词”?干净的数据库将是.Match("n").OptionalMatch("n-[r]-()").Delete(n,r).ExecuteWithoutResults()

标签: neo4j neo4jclient


【解决方案1】:

这个问题似乎只存在于社区版。企业版的 30 天试用版运行良好。

【讨论】:

    【解决方案2】:

    你的话有关系吗?

    否则,您也可以简单地对其进行批处理。

    MATCH (w:Word) with w limit 500000 delete w

    你会做的关系

    MATCH (w:Word) with w limit 50000 optional match (w)-[r]-() delete w,r

    【讨论】:

      猜你喜欢
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多