neo4j - Commits are slowing down -
neo4j writes slow down after few thousand records written.
two indexes exist speed query up. also, using explain know each query constant time process.
indexorder = schema.indexfor(order) .on("id") .create(); indexshop = schema.indexfor(shop) .on("domain") this query use:
{json} log log.order order, log.shop shop merge (s:shop {domain:shop.domain}) on create set s=shop merge (s)-[:scored]->(r:order {id:order.id}) on create set r=order here how commit store db:
private void log() { try (transaction tx = graphdb.begintx()) { (map map : list) { graphdb.execute(query, singletonmap("json", map)); } list = new arraylist<>(); tx.success(); } } and call above when have 1k logs.
list.add(map); count++; if (count % 1000 == 0) { log(); system.out.println(count); } additional info: use these config settings:
.setconfig(graphdatabasesettings.pagecache_memory, "512m") .setconfig(graphdatabasesettings.string_block_size, "60") .setconfig(graphdatabasesettings.array_block_size, "300") this system works 200k entries if done within 1 transaction runs memory issues.
so, why 1k entries/transaction approach grind halt after 5 transactions (5k entries) commited database?
how fix problem?
you should
mergeonordernode itself, allow cypher planner use:order(id)index. (besides, shouldmergenodes in path pattern before doingmergeon path pattern anyway, avoid creating duplicate nodes in circumstances.) change, query (but not yet ideal):with {json} log log.order order, log.shop shop merge (s:shop {domain:shop.domain}) on create set s=shop merge (r:order {id:order.id}) on create set r=order merge (s)-[:scored]->(r)you should minimize number of calls
execute(), each call has lot of overhead. in fact, can make single query handle entirelistof 1000 items. so, can changelog()code following (i assumelistdefinedlist<map<string, object>>or that):private void log() { try (transaction tx = graphdb.begintx()) { graphdb.execute(query, singletonmap("loglist", list)); list = new arraylist<map<string, object>>(); tx.success(); } }and here corresponding cypher query:
unwind {loglist} log log.order order, log.shop shop merge (s:shop {domain:shop.domain}) on create set s=shop merge (r:order {id:order.id}) on create set r=order merge (s)-[:scored]->(r)
Comments
Post a Comment