简体   繁体   English

如何解决ArangoDB Foxx死锁问题?

[英]How to resolve ArangoDB Foxx deadlocking problems?

Under testing, our Foxx app is getting into "deadlock detected" problems. 在测试中,我们的Foxx应用正在陷入“检测到死锁”的问题。 These seem to be caused by traversal queries. 这些似乎是由遍历查询引起的。 Apriori, it is difficult if not impossible to know which tables will be used during traversal. 先验的,很难甚至不是不可能知道遍历期间将使用哪些表。 However, I did take one specific case where I could determine the number of tables and wrap the AQL in a transaction for testing: 但是,我确实采用了一种特定的情况,即可以确定表的数量并将AQL包装在用于测试的事务中:

var result = db._executeTransaction({ "collections" : { "read" : [ "pmlibrary", "pmvartype", "pmvariant", "pmproject", "pmsite", "pmpath", "pmattic" ] }, "action" : "function(){var db=require(\\"@arangodb\\").db;var res=db._query(\\"FOR o IN ['pmlibrary/199340787'] FOR v,e,p IN 0..7 INBOUND o pm_child RETURN p.vertices\\");return res.toArray()}" }); var result = db._executeTransaction({“ collections”:{“ read”:[“ pmlibrary”,“ pmvartype”,“ pmvariant”,“ pmproject”,“ pmsite”,“ pmpath”,“ pmattic”]},“操作“:” function(){var db = require(\\“ @ arangodb \\”)。db; var res = db._query(\\“ FOR o IN ['pmlibrary / 199340787'] FOR v,e,p IN 0。 .7 INBOUND o pm_child返回p.vertices \\“);返回res.toArray()}”});

FYI, the list of tables in the collections do not include the edge tables. 仅供参考,集合中的表列表不包括边缘表。

However, the deadlocks on this statement continue. 但是,此语句上的僵局仍在继续。 I'm not sure what to try next. 我不确定接下来要尝试什么。 Thanks. 谢谢。

I'm not an indexing/performance expert with ArangoDB, but I recently had some issues with deadlocking too and by reconstructing and reshaping the queries had huge performance gains, sometimes queries that took 120 seconds then took 0.2 seconds. 我不是ArangoDB的索引/性能专家,但最近我也遇到了一些死锁问题,通过重构和重塑查询可以显着提高性能,有时查询花费120秒,然后花费0.2秒。

A key thing I did was try to help ArangoDB know when to use an Index, and make sure that index is there to be used. 我做的关键一件事是尝试帮助ArangoDB知道何时使用索引,并确保要使用该索引。

In your example query, there is a problem that stops ArangoDB from knowing an index occurs: 在您的示例查询中,有一个问题使ArangoDB无法知道发生了索引:

FOR o IN ['pmlibrary/199340787'] 
FOR v,e,p IN 0..7 INBOUND o pm_child 
  RETURN p.vertices

The key issue with this is that your original FOR loop is using a value out of an array, which may hinder ArangoDB identifying an index. 与此相关的关键问题是,原始的FOR循环正在使用数组中的值,这可能会阻止ArangoDB标识索引。 You could easily replace your o with a parameter, and put in your 'pmlibrary/199340787' value directly, and with the Explain button see if it identifies it can use an index. 您可以轻松地用参数替换o,然后直接输入'pmlibrary/199340787'值,并使用Explain按钮查看它是否标识它可以使用索引。

One issue I found was trying to make it super clear to use an index, which sometimes meant adding additional LET commands to allow ArangoDB to build the contents of arrays, and then it seems to know what index to use better. 我发现的一个问题是试图使使用索引变得非常清晰,这有时意味着添加其他LET命令以允许ArangoDB构建数组的内容,然后似乎知道使用哪种索引更好。

If you were to test the performance of the query above, versus something like: 如果要测试上述查询的性能,则需要执行以下操作:

LET my_targets = (FOR o IN pmlibrary FILTER o._key == '199340787' RETURN o._id)

FOR o IN my_targets
FOR v,e,p IN 0..7 INBOUND o._id pm_child 
  RETURN p.vertices

It may seem counter intuitive, but with testing I found amazing performance gains by breaking queries apart to help ArangoDB notice it could use an Index. 似乎反直观,但是通过测试,我发现通过将查询分开来帮助ArangoDB注意到它可以使用索引,从而获得了惊人的性能提升。

If any queries are against the values within Arrays or if you are using dynamic attribute names, then it won't always use an index even if one exists. 如果有任何查询针对数组中的值,或者您正在使用动态属性名称,那么即使存在索引,它也不会始终使用索引。

Also I found that the server will cache response for queries, so if you want to test changes to a long running query and want to avoid cache hits on your second + queries, I had to stop and restart the arangodb3 service. 我还发现服务器将缓存查询的响应,因此,如果您要测试对长期运行的查询所做的更改,并希望避免第二个+查询上的缓存命中,我必须停止并重新启动arangodb3服务。

I hope that helps give you a target for shuffling around your query to work with indexes. 我希望这可以为您提供一个针对查询进行改组以使用索引的目标。

Remember you already have inbuilt indexes on _id, _key, _from, _to, so you need to try and make sure it's going to use other indexes that can help speed up your query. 请记住,您已经在_id,_key,_from,_to上建立了内置索引,因此您需要尝试确保它将使用其他有助于加快查询速度的索引。

正确的解决方案是使用WITH子句而不是事务。

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

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