Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j C#顶点创建性能_Neo4j_Neo4jclient - Fatal编程技术网

Neo4j C#顶点创建性能

Neo4j C#顶点创建性能,neo4j,neo4jclient,Neo4j,Neo4jclient,我正在尝试使用C#在Neo4j上创建1000000个(平凡的)顶点。(Community Edition 2.3.2.)性能非常差-创建这些节点需要900秒以上的时间。我做的事情效率低下吗?为什么要花这么长时间 var client = new GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "password"); client.Connect();

我正在尝试使用C#在Neo4j上创建1000000个(平凡的)顶点。(Community Edition 2.3.2.)性能非常差-创建这些节点需要900秒以上的时间。我做的事情效率低下吗?为什么要花这么长时间

        var client = new GraphClient(new Uri("http://localhost:7474/db/data"), 
            "neo4j", "password");
        client.Connect();

        DateTime t = DateTime.Now;
        Debug.WriteLine(t);

        for (int j = 0; j < 100; j++ ) {
            using (var scope = new TransactionScope(
                TransactionScopeOption.Required,
                new TransactionOptions {IsolationLevel = IsolationLevel.ReadCommitted}
                ))
            {
                for (int i = 0; i < 10000; i++) {
                    var index = new Category { label = i.ToString() };
                            client.Cypher
                                .Create("(class:testItem {index})")
                                .WithParam("index", index)
                                .ExecuteWithoutResults();
                }
                scope.Complete();
            }
            Debug.WriteLine(j);
        }

        Debug.WriteLine(DateTime.Now.Subtract(t).Seconds);

根据Chris Skardon的说法,这些创建请求不是成批处理成几个http请求,而是每个请求发送一个单独的请求(不确定它们是否共享所有一个tx)

批处理它们更有效,例如,将10-50k值放入一个列表,并将其作为“数据”参数发送到一个cypher语句,如下所示:

UNWIND {data} as value CREATE (:TestItem {index: value});
或者,如果您有多个属性,请创建一个字典列表作为参数

UNWIND {data} as row CREATE (:TestItem {index: row.index, foo: row.foo, bar: row.bar});
对于合并操作,可以执行以下操作:

UNWIND {data} as row MERGE (t:TestItem {index: row.index}) ON CREATE SET  t.foo=row.foo, t.bar = row.bar;
甚至

UNWIND {data} as row MERGE (t:TestItem {index: row.index}) ON CREATE SET  t += row;


基于Michael的答案-您将看到的代码是:

var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();

var data = new List<Category>();
for (int i = 0; i < 20000; i++)
    data.Add(new Category { Label = i.ToString()});

DateTime t = DateTime.Now;
Debug.WriteLine(t);

for (int j = 0; j < 50; j++)
{
    client.Cypher
        .Unwind(data, "item")
        .Create("(:testItem { Label : item.Label })")
        .ExecuteWithoutResults();

    Debug.Write($"{j},");
}
Debug.WriteLine();
Debug.WriteLine($"Took {DateTime.Now.Subtract(t).Seconds} seconds");
var-client=new-GraphClient(新Uri(“http://localhost:7474/db/data"));
client.Connect();
var data=新列表();
对于(int i=0;i<20000;i++)
Add(新类别{Label=i.ToString()});
DateTime t=DateTime.Now;
Debug.WriteLine(t);
对于(int j=0;j<50;j++)
{
客户,塞弗
.展开(数据,“项目”)
.Create((:testItem{Label:item.Label})”
.ExecuteWithoutResults();
Debug.Write($“{j},”);
}
Debug.WriteLine();
Debug.WriteLine($“花费了{DateTime.Now.Subtract(t.Seconds}Seconds”);

这在21秒内创建了100000个节点,当我尝试使用10000个节点重复100次时,需要24秒,因此使用批量大小可能会产生不同的性能,我尝试一次性使用全部1000000个节点,大约需要26秒。无论哪种方式,都比900多秒要好得多

您只需离开类别分配。多少秒,只需创建1000000个类别,而不插入数据库?
UNWIND {data} as row MERGE (t:TestItem {index: row.index}) ON CREATE SET  t += row.props;
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();

var data = new List<Category>();
for (int i = 0; i < 20000; i++)
    data.Add(new Category { Label = i.ToString()});

DateTime t = DateTime.Now;
Debug.WriteLine(t);

for (int j = 0; j < 50; j++)
{
    client.Cypher
        .Unwind(data, "item")
        .Create("(:testItem { Label : item.Label })")
        .ExecuteWithoutResults();

    Debug.Write($"{j},");
}
Debug.WriteLine();
Debug.WriteLine($"Took {DateTime.Now.Subtract(t).Seconds} seconds");