我正在使用一个带有小图的Neo4j 1.9.7数据库:
Nodes 19.806
Properties 230.175
Relationship 83.853
Relationship types 3
我已经通过Sail导入了这些数据,以使用SPARQL插件执行一些查询。我的图有3个实体,BusinessProcess,ApplicationProcess,数据库链接如下
BUS2 ----> APP4 -----> DB10
| |-------> DB9
|
|------> APP5 -----> DB11
| ^
|------> APP6 ---------|
我正在运行neo4j作为服务器并通过Advanced Rest Client for Chrome执行localhost查询,因为我只将数据库用于读取数据。 当我执行前3个查询时,一切顺利。例如,这个sparql查询
SELECT ?O
WHERE{ ?S ?P ?O. ?O ?P2 ?OO.}
GROUP BY ?O HAVING((COUNT(?P2)=1))
返回
[ {
"O" : "http://neo4j.org#ApplicationProcessI"
} ]
in 6911 ms
这对我来说是可以接受的(我不需要真实的情况,只是在Neo4j解决方案与MySQL上的同一个数据库之间进行比较,所以我不需要对两者进行完美的调整,只需要人类的耐心认可一个=))
我的查询存在问题
PREFIX bus:<http://neo4j.org#BusinessProcess>
SELECT ?bus ?db
WHERE{ bus:9 ?p1 ?app. ?app ?p2 ?db. ?bus ?p1 ?app2. ?app2 ?p2 ?db. FILTER(?bus != bus:2) }
GROUP BY ?bus ?db
应该说哪些业务流程与特定的数据库共享相同的数据库(示例中为BusinessProcess9)。在这里,我的数据库似乎没有在可接受的人类时间内得到答案(它超出了小时而没有得出结论)。阅读手册和其他类似问题我认为这个问题应该不会那么成问题。 我尝试稍微调整数据库,但事情并没有改善,所以我决定寻求帮助。
商店详情:
-rw-rw-r-- 1 ivan ivan 14M lug 1 16:12 data/EASample2.db/neostore.propertystore.db.strings
-rw-rw-r-- 1 ivan ivan 9,0M lug 1 16:12 data/EASample2.db/neostore.propertystore.db
-rw-rw-r-- 1 ivan ivan 3,0M lug 1 16:24 data/EASample2.db/neostore.relationshipstore.db
-rw-rw-r-- 1 ivan ivan 340K lug 1 16:12 data/EASample2.db/neostore.propertystore.db.arrays
-rw-rw-r-- 1 ivan ivan 175K lug 1 16:12 data/EASample2.db/neostore.nodestore.db
-rw-rw-r-- 1 ivan ivan 380 lug 1 16:12 data/EASample2.db/neostore.propertystore.db.index.keys
-rw-rw-r-- 1 ivan ivan 152 lug 1 16:12 data/EASample2.db/neostore.relationshiptypestore.db.names
-rw-rw-r-- 1 ivan ivan 81 lug 1 16:12 data/EASample2.db/neostore.propertystore.db.index
-rw-rw-r-- 1 ivan ivan 54 lug 1 16:12 data/EASample2.db/neostore
-rw-rw-r-- 1 ivan ivan 15 lug 1 16:12 data/EASample2.db/neostore.relationshiptypestore.db
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.nodestore.db.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.propertystore.db.arrays.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.propertystore.db.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.propertystore.db.index.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.propertystore.db.index.keys.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.propertystore.db.strings.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.relationshipstore.db.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.relationshiptypestore.db.id
-rw-r--r-- 1 root root 9 lug 1 16:12 data/EASample2.db/neostore.relationshiptypestore.db.names.id
使用
Neo4j 1.9.7
Java 1.7.0_55
CPU Intel Core i7-2630QM 2 Ghz / Turbo boost to 2.9 Ghz
4 GB DDR3 RAM
Ubuntu 14.04 LTS
neo4j.properties
# Default values for the low-level graph engine
#neostore.nodestore.db.mapped_memory=25M
#neostore.relationshipstore.db.mapped_memory=50M
#neostore.propertystore.db.mapped_memory=90M
#neostore.propertystore.db.strings.mapped_memory=130M
#neostore.propertystore.db.arrays.mapped_memory=130M
#add by me
use_memory_mapped_buffers=true
# Enable this to be able to upgrade a store from 1.4 -> 1.5 or 1.4 -> 1.6
#allow_store_upgrade=true
# Enable this to specify a parser other than the default one. 1.5, 1.6, 1.7 are available
#cypher_parser_version=1.6
# Keep logical logs, helps debugging but uses more disk space, enabled for
# legacy reasons To limit space needed to store historical logs use values such
# as: "7 days" or "100M size" instead of "true"
keep_logical_logs=true
# Autoindexing
# Enable auto-indexing for nodes, default is false
#node_auto_indexing=true
# The node property keys to be auto-indexed, if enabled
#node_keys_indexable=name,age
# Enable auto-indexing for relationships, default is false
#relationship_auto_indexing=true
# The relationship property keys to be auto-indexed, if enabled
#relationship_keys_indexable=name,age
的Neo4j-wrapper.conf
wrapper.java.additional=-Dorg.neo4j.server.properties=conf/neo4j-server.properties
wrapper.java.additional=-Djava.util.logging.config.file=conf/logging.properties
wrapper.java.additional=-Dlog4j.configuration=file:conf/log4j.properties
#********************************************************************
# JVM Parameters
#********************************************************************
wrapper.java.additional=-XX:+UseConcMarkSweepGC
wrapper.java.additional=-XX:+CMSClassUnloadingEnabled
# Uncomment the following lines to enable garbage collection logging
#wrapper.java.additional=-Xloggc:data/log/neo4j-gc.log
#wrapper.java.additional=-XX:+PrintGCDetails
#wrapper.java.additional=-XX:+PrintGCDateStamps
#wrapper.java.additional=-XX:+PrintGCApplicationStoppedTime
#wrapper.java.additional=-XX:+PrintPromotionFailure
#wrapper.java.additional=-XX:+PrintTenuringDistribution
# Uncomment the following lines to enable JVM startup diagnostics
#wrapper.java.additional=-XX:+PrintFlagsFinal
#wrapper.java.additional=-XX:+PrintFlagsInitial
# Java Heap Size: by default the Java heap size is dynamically
# calculated based on available system resources.
# Uncomment these lines to set specific initial and maximum
# heap size in MB.
wrapper.java.initmemory=128
wrapper.java.maxmemory=512
#********************************************************************
# Wrapper settings
#********************************************************************
# path is relative to the bin dir
wrapper.pidfile=../data/neo4j-server.pid
#********************************************************************
# Wrapper Windows NT/2000/XP Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
# using this configuration file has been installed as a service.
# Please uninstall the service before modifying this section. The
# service can then be reinstalled.
# Name of the service
wrapper.name=neo4j
# User account to be used for linux installs. Will default to current
# user if not set.
wrapper.user=
正如你所看到的,我离开了映射的默认配置(因为我的图看起来很适合它们)并且我将堆更改为128M - 512M(根据manual应该可以工作) 我注意到在查询过程中只有一个CPU核心处于完全使用状态,但我理解这是正常的,因为遍历只能在一个核心上发生。 另外,对于jvisualvm,我注意到这个过程永远不会达到完整的堆使用量(在一小时内我会离开它)。 GC似乎不是一个问题,因为它的活动率约为1.4 / 1.6%。 CPU使用率约为20%
如果我在Cypher中运行查询
,会遇到同样的问题start bus1=node(9)
match bus1-->app1-->db<--app2<--bus2
where bus1 <> bus2
return db.value, bus2.value
是硬件问题(我的笔记本电脑不是我所知道的最好)并且我应该尝试使用更多内存的东西来填充堆(我可以在开始使用交换之前将其提升到1Gb到我的笔记本电脑) )还是有一些调整要比这更多?或者可能是查询问题?
修改
在我写完之后,我试图在cypher查询中插入一个distinct子句,然后我执行了cia shell(读取这个answer我认为我可能遇到类似的问题)。查询在83118 ms之后结束,结果为374K +。所以我认为这不是数据库的调优问题,而是SPARQL查询编写得不好。
编辑Cypher查询
start bus1=node(9)
match bus1-->app1-->db<--app2<--bus2
where bus1 <> bus2
return distinct db.value, bus2.value
结果(摘录):
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess87" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess37" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess118" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess79" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess39" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess63" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess112" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess82" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess89" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess40" |
| "http://neo4j.org#Database214" | "http://neo4j.org#BusinessProcess60" |
+-------------------------------------------------------------------------+
374501 rows
13251 ms
答案 0 :(得分:1)
这似乎是一个SPARQL查询问题。将其更改为:
PREFIX bus:<http://neo4j.org#BusinessProcess>
SELECT ?bus ?db
WHERE{ bus:9 ?p1 ?app.
?app ?p2 ?db.
?db ?p2 ?app2.
?app2 ?p1 ?bus.
FILTER(?bus != bus:2) }
GROUP BY ?bus ?db
在374k +结果开始时,查询首先在〜50秒内得到一个asnwer。从select和group by子句中删除db,因为在我的情况下共享哪个数据库的信息不是主要的,这是第二次更改,使查询执行得更好,并在~5s内获得anser。
答案 1 :(得分:0)
我遇到了类似的问题,增加了
的价值wrapper.java.initmemory=128
wrapper.java.maxmemory=512
为我解决了这个问题。
还要确保
neostore.nodestore.db.mapped_memory=25M
neostore.relationshipstore.db.mapped_memory=50M
neostore.propertystore.db.mapped_memory=90M
neostore.propertystore.db.strings.mapped_memory=130M
neostore.propertystore.db.arrays.mapped_memory=130M
的大小等于或大于neo4j/data
文件夹中的相应文件。