简体   繁体   English

通过REST的Neo4j批处理请求

[英]Neo4j batching requests via REST

I tried to make neo4j REST batching work via org.neo4j.rest.graphdb , but I have no clue, how it should work. 我试图通过org.neo4j.rest.graphdb使neo4j REST批处理工作,但是我不知道它应该如何工作。 Something I did: 我所做的事情:

final RestAPIFacade rest = new RestAPIFacade("http://localhost:7474/db/data");
BatchTransaction tx = BatchTransaction.begin(rest);
BatchRestAPI newrest = new BatchRestAPI("http://localhost:7474/db/data",rest);

try {
    for (int i = 0; i < 1000; i++) {
        newrest.createNode(null);
    }
    tx.success();
} finally {
    tx.finish();
}

I understand that I could write my own rest requests constructor but it's not appropriate solution for what I need. 我知道我可以编写自己的rest请求构造函数,但这不适用于我需要的解决方案。 Maybe someone has worked with this library and knows the right way. 也许有人使用过这个库并且知道正确的方法。 The problem is nothing changes in database, and no error appears. 问题是数据库中没有任何更改,也没有出现错误。

Update: if I use a usual RestAPIFacade transaction and set 更新:如果我使用常规的RestAPIFacade事务并设置

System.setProperty("org.neo4j.rest.batch_transaction", "true"); System.setProperty(“ org.neo4j.rest.batch_transaction”,“ true”);

I get Premature EOF error. 我收到过早的EOF错误。

Caused by: java.io.IOException: Premature EOF
    at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:565)
    at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:609)
    at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:696)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)

So, one transaction seems to be limited to some size(nearly 700 empty nodes). 因此,一笔交易似乎仅限于某种规模(将近700个空节点)。 So, is there a way increasing transaction size, or I should divide my data portions on many many transactions(so the performance, obviously, suffers)? 因此,是否有增加事务大小的方法,还是我应该将数据部分划分为许多事务(显然,性能会受到影响)?

Thank you! 谢谢!

Try changing your code to construct a RestGraphDatabase instance and then get the transactions from it instead of constructing them yourself. 尝试更改您的代码以构造RestGraphDatabase实例,然后从中获取事务,而不是自己构造它们。 The same goes for the RestAPI if you want to use it. 如果要使用RestAPI ,也是RestAPI Something like 就像是

GraphDatabaseService graphDb = new RestGraphDatabase("http://localhost:7474/db/data");
...
Transaction tx = graphDb.beginTx();
...
RestAPI restApi = graphDb.getRestAPI();

If you want the transactions to be executed in batch you should also set the corresponding system property 如果要批量执行事务,则还应该设置相应的系统属性

System.setProperty("org.neo4j.rest.batch_transaction", "true");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM