为什么Neo4j(客户端)内存不足?

时间:2015-07-13 11:31:43

标签: neo4j neo4jclient

我正在创建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; }
    }
}

2 个答案:

答案 0 :(得分:0)

这个问题似乎只存在于社区版中。企业版的30天试用期正常。

答案 1 :(得分:0)

你的话有关系吗?

否则您也可以简单地批量处理它。

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

与你有关系

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