- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 MySQL 数据库迁移到 Neo4j 并测试了一个简单的请求。我非常惊讶地发现 Neo4j 中的同等请求比 MySql 中的时间长 10 到 100 倍。我正在开发 Neo4j 2.0.1。
在原始的 MySql 架构中,我有以下三个表:
每个属性都有一个索引。我想在几个条件下显示给定大陆的按城市划分的剧院数量。请求是:
SELECT count(*) as nb, c.name
FROM `cities` c LEFT JOIN theaters t ON c.id = t.city_id
WHERE c.country_code IN
(SELECT code FROM countries WHERE selected is true AND continent_id = 4)
AND c.status=1 AND t.public = 1
GROUP BY c.name ORDER BY nb DESC
Neo4j 中的数据库架构如下:
(:大陆)-[:包含]->(:国家/地区{选定的:bool})-[:包含]->(:城市{名称:字符串>, status:bool})-[:包含]->(:Theater{public:bool})
每个属性还定义了一个索引。密码请求是:
MATCH (:Continent{code: 4})-[:Include]->(:Country{selected:true})-[:Include]->(city:City{status:true})-[:Include]->(:Theater{public: true})
RETURN city.name, count(*) AS nb ORDER BY nb DESC
每个数据库中约有 70,000 个城市和 140,000 个剧院。
在 ID 为 4 的大陆上,MySql 请求大约花费了 0.02 秒,而 Neo4j 则花费了 0.4 秒。此外,如果我在 Cypher 请求中引入国家和城市之间的可变关系长度 (...(:Country{selected:true})-[:Ininclude*..3]->(city:City{status :true})...
) 因为我希望能够添加中间级别(例如区域),因此请求需要超过 2 秒的时间。
我知道在这种特殊情况下,使用 Neo4j 代替 MySql 没有任何好处,但我希望看到两种技术之间大致相当的性能,并且我想利用 Neo4j 地理层次结构功能。
我错过了什么还是这是 Neo4j 的限制?
感谢您的回答。
编辑:首先您会找到数据库转储文件 here 。 Neo4j server configuration是开箱即用的。我在 Ruby 环境中工作,并且使用 neography gem。我还单独运行 Neo4J 服务器因为我不在 JRuby 上,所以它通过 Rest API 发送密码请求。
该数据库包含 244 个国家、69000 个城市和 138,000 个剧院。对于 Continental_id 4,有 46,982 个城市(37,210 个状态 bool 值设置为 true)和 74,420 个剧院。
请求返回 2256 行。第三次运行花费了 338 毫秒。以下是带有分析信息的请求输出:
profile MATCH (:Continent{code: 4})-[:Include]->(country:Country{selected:true})-[:Include*..1]->(city:City{status:true})-[:Include]->(theater:Theater{public: true}) RETURN city.name, count(*) AS nb ORDER BY nb DESC;
==> ColumnFilter(symKeys=["city.name", " INTERNAL_AGGREGATE85ca19f3-9421-4c18-a449-1097e3deede2"], returnItemNames=["city.name", "nb"], _rows=2256, _db_hits=0)
==> Sort(descr=["SortItem(Cached( INTERNAL_AGGREGATE85ca19f3-9421-4c18-a449-1097e3deede2 of type Integer),false)"], _rows=2256, _db_hits=0)
==> EagerAggregation(keys=["Cached(city.name of type Any)"], aggregates=["( INTERNAL_AGGREGATE85ca19f3-9421-4c18-a449-1097e3deede2,CountStar())"], _rows=2256, _db_hits=0)
==> Extract(symKeys=["city", " UNNAMED27", " UNNAMED7", "country", " UNNAMED113", "theater", " UNNAMED72"], exprKeys=["city.name"], _rows=2257, _db_hits=2257)
==> Filter(pred="(hasLabel(theater:Theater(3)) AND Property(theater,public(5)) == true)", _rows=2257, _db_hits=2257)
==> SimplePatternMatcher(g="(city)-[' UNNAMED113']-(theater)", _rows=2257, _db_hits=4514)
==> Filter(pred="(((hasLabel(city:City(2)) AND hasLabel(city:City(2))) AND Property(city,status(4)) == true) AND Property(city,status(4)) == true)", _rows=2257, _db_hits=74420)
==> TraversalMatcher(start={"label": "Continent", "query": "Literal(4)", "identifiers": [" UNNAMED7"], "property": "code", "producer": "SchemaIndex"}, trail="( UNNAMED7)-[ UNNAMED27:Include WHERE (((hasLabel(NodeIdentifier():Country(1)) AND hasLabel(NodeIdentifier():Country(1))) AND Property(NodeIdentifier(),selected(3)) == true) AND Property(NodeIdentifier(),selected(3)) == true) AND true]->(country)-[:Include*1..1]->(city)", _rows=37210, _db_hits=37432)
最佳答案
你说得对,我自己尝试过,查询时间只降到了 100 毫秒。
MATCH (:Continent{code: 4})-[:Include]->
(country:Country{selected:true})-[:Include]->
(city:City{status:true})-[:Include]->
(theater:Theater{public: true})
RETURN city.name, count(*) AS nb
ORDER BY nb DESC;
| "Forbach" | 1 |
| "Stuttgart" | 1 |
| "Mirepoix" | 1 |
| "Bonnieux" | 1 |
| "Saint Cyprien Plage" | 1 |
| "Crissay sur Manse" | 1 |
+--------------------------------------+
2256 rows
**85 ms**
请注意,自 2.0.x 起,cypher 尚未进行性能优化,该工作从 Neo4j 2.1 开始,并将持续到 2.3。内核中还计划进行更多性能工作,这也将加快速度。
我也在 Java 中实现了该解决方案,并将其降低到 19 毫秒。它当然不是那么漂亮,但这也是我们使用 cypher 的目标:
class City {
Node city;
int count = 1;
public City(Node city) {
this.city = city;
}
public void inc() { count++; }
@Override
public String toString() {
return String.format("City{city=%s, count=%d}", city.getProperty("name"), count);
}
}
private List<?> queryJava3() {
long start = System.currentTimeMillis();
Node continent = IteratorUtil.single(db.findNodesByLabelAndProperty(CONTINENT, "code", 4));
Map<Node,City> result = new HashMap<>();
for (Relationship rel1 : continent.getRelationships(Direction.OUTGOING,Include)) {
Node country = rel1.getEndNode();
if (!(country.hasLabel(COUNTRY) && (Boolean) country.getProperty("selected", false))) continue;
for (Relationship rel2 : country.getRelationships(Direction.OUTGOING, Include)) {
Node city = rel2.getEndNode();
if (!(city.hasLabel(CITY) && (Boolean) city.getProperty("status", false))) continue;
for (Relationship rel3 : city.getRelationships(Direction.OUTGOING, Include)) {
Node theater = rel3.getEndNode();
if (!(theater.hasLabel(THEATER) && (Boolean) theater.getProperty("public", false))) continue;
City city1 = result.get(city);
if (city1==null) result.put(city,new City(city));
else city1.inc();
}
}
}
List<City> list = new ArrayList<>(result.values());
Collections.sort(list, new Comparator<City>() {
@Override
public int compare(City o1, City o2) {
return Integer.compare(o2.count,o1.count);
}
});
output("java", start, list.iterator());
return list;
}
java time = 19ms
first = City{city=Val de Meuse, count=1} total-count 22561
关于neo4j - 与带有 Neo4j 的 MySql 相比,性能较差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22900972/
我已经在 OSX 上安装了 Docker 并下载了 neo 镜像。当我运行它时(使用图像主页中的 args),一切似乎都正常,但日志的最后几行表明如下: 00:20:39.662 [main] INF
我的正则表达式在 neos 项目中不能正常工作。DD/MM/YYYY 的正则表达式(仅限 19XX-20XX) var date_regex = /^(0[1-9]|1\d|2\d|3[01])\/(
Neo 4j可以与HDFS / Hadoop集成吗?在处理涉及许多关系且每秒具有大量事务的大型数据集时,通常使用Hadoop来提高Neo 4j的处理能力。 最佳答案 这是一个非常广泛的问题。也许考虑提
我尝试在 NEO 环境中使用 TenantAccessor。TenantAccessor.getCurrentTenant().getTenantId() 生成的 TenantId 作为 GUID 返
我下载了Neoclipse Source并下载了 Neo4J source 。但是 Neo4J 源文件中找不到 Neoclipse 源文件引用的某些类。它们已被弃用吗?我可以获得 Neoclipse
进程文件: neo or neo.exe 进程名称: Price Patrol 进程类别:存在安全风险的进程 英文描述: neo.exe is the execuatble for Pric
load csv with headers from 'file:///C:/Users/user/Desktop/Neo4J' as row Create (:State_Code {state_c
如何在 SAPUI5 应用程序的运行时为 neo-app.json 文件的 routes 部分定义新条目?例如在 Component.js 内部。 例如,我想将以下条目添加到文件中,或者将一些代码添加
我最近将一台计算机变成了 Ubuntu 服务器。我已经按照下面的文章 http://neos.readthedocs.io/en/stable/GettingStarted/Installation.
我正在尝试了解如何使用 NEOS Server for SCIP .我已经阅读了有关 CPLEX LP file format 的教程.但我仍然得不到任何结果。 让我们以该教程中提供的示例为例: Ma
关于这一年Bubble Cup (完)有问题NEO (我无法解决),它要求 给定一个包含 n 个整数元素的数组。我们把它分成几个部分(可能是1个),每个部分都是一个连续的元素。这种情况下的 NEO 值
我的 Rails 应用程序必须使用 Neo4j。所以我开始安装 neo4j 服务器。我按照步骤安装 here在 Linux 上。 但是当我运行的时候 ./bin/neo4j console 它给了 E
我刚从 windows 10 切换到 arch linux我想使用 (Neo)Vim 作为我的代码编辑器我已经完成了自动编译和模糊查找器但我不知道如何在 (Neo)Vim 中调试 任何帮助! 最佳答案
我想问一下,如何使用Spring boot找到Dijkstra。 我目前使用 spring-boot-starter-data-neo4j 库将 Neo4j 与我的 java 类映射。 我现在想使用
我正在尝试创建一个可以从 U2F token (例如 Java 语言的 Yubikey Neo)检索公钥和私钥的应用程序。我尝试在控制台中使用简单的扫描仪从 Yubikey Neo 获取任何内容,但它
我想用摩托罗拉68000汇编器写一个程序,目标平台是Neo Geo(九十年代的游戏机);这个问题很严重,我有一个我想实现的特定项目并且我有编程经验(虽然我现在主要是 Perl/R 编程,但我以前只接触
我使用自定义 Web 服务作为 neo4j 的非托管扩展。 这是 Neo4j 提供的详细信息,我已遵循该详细信息并创建了自己的非托管扩展。 http://neo4j.com/docs/stable/s
Typo3 Neos 是否原生支持元素的响应行为?例如像 css 网格类(col-sm-?? 或 col-md-??)这样的 Bootstrap ,或者我可以使用 Neos 通过 hidden-xs
我是为嵌入式板构建自定义 Linux 操作系统的新手 - 所以请忽略我的无知。 我有一个名为 NanoPi NEO 的开发板,它具有定制的 Debian Linux。现在开发板附带一个 .img 文件
我正在尝试使用脚本在 NEO4j db 中导入 csv 文件: LOAD CSV FROM "file:///dataframe6.txt" AS line RETURN count(*) 但我收到以
我是一名优秀的程序员,十分优秀!