1. Neo4j retrieval speed is slow
Solved by creating an index .
Neo4j index principle reference: neo4j-several optimization ideas for query efficiency
1.1 python
- Read first (https://blog.csdn.net/MaoziYa/article/details/114195824)
- 代码:graph.run(‘CREATE INDEX ON : PersonTest(name)’)
Love python, easy to operate!
1.2 neo4j-shell + cypher-shell
Because the Linux remote service is used, there is no direct access to the browser to create and modify the index.
- bin/neo4j-shell: View the currently created index and status
schema
# Indexes
# ON :企业名称(企业名称) ONLINE
# ON :企业名称(name) ONLINE
#
# No constraints
# 注意索引应当是 ONLINE 状态才生效
- bin/cypher-shell: Create index
# 输入密码后
# (1)创建
CREATE INDEX ON : 企业名称(登记机关);
# 返回信息:
# 0 rows available after 38 ms, consumed after another 0 ms
# Added 1 indexes
# (2)删除
DROP INDEX ON :企业名称(登记机关);
# 返回信息:
# 0 rows available after 5 ms, consumed after another 0 ms
# Removed 1 indexes
# 配合neo4j-shell查看索引是否创建成功
2. springCloud + Neo4j
2.1 Slow retrieval speed
When using the interface to access Neo4j query data, it takes a very long time, about 1400+ms .
I checked the database index construction several times and found that the index construction was normal .
In the local maven, a simple project was time-consuming, and it was found that the construction of the driver required 1300+ms, and the actual retrieval sentence run and retrieval result processing time was only 57ms.
12:40:07.007 [main] INFO org.test.neo.App - Neo4jDao process time:1329
12:40:07.067 [main] INFO org.test.neo.App - Neo4jDao process time:57
My damn bad coding habit, instead of encapsulating neo4jUtil as a separate class, I wrote it directly into dao. The retrieval speed is too slow...
2.3 Java Neo4j Driver&Session
- Establish connection Driver driver = GraphDatabase.driver()
- Create session Session session = driver.session()
In the project, Util returns the initial configuration of the session, and the throughput of the interface is relatively large.
2.2 Neo4j reports an error during the stress test
java.lang.IllegalStateException: Existing open connection detected
at org.neo4j.driver.internal.NetworkSession.lambda$acquireConnection$27(NetworkSession.java:447)
at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:966)
at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:940)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1975)
at org.neo4j.driver.internal.util.Futures.lambda$asCompletionStage$0(Futures.java:74)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:485)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.DefaultPromise.access$000(DefaultPromise.java:33)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.DefaultPromise$1.run(DefaultPromise.java:435)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
unsolved.