节点查询之间的路径永远不会完成

时间:2017-09-27 00:58:32

标签: c# gremlin azure-cosmosdb

我在CosmosDB中创建了一个图形,它有两个顶点类型,一个actor顶点和一个movie顶点。存在的唯一边缘类型是"作用于"类型。您可以将图形想象为拥有许多演员和许多电影,而且任何特定的演员都可能在任意数量的电影中扮演过角色。

我正在尝试编写一个查询,它将发现并返回两个actor之间的路径。例如,基努·里维斯与劳伦斯·菲什伯德一起在黑客帝国演出。劳伦斯·菲什伯恩(Laurence Fishburn)饰演马龙白兰度(Marlon Brando因此,Keanu Reeves和Marlon Brando之间的路径是Keanu Reeves - >矩阵 - > Laurence Fishburn - >启示录现在 - >马龙白兰度。

这是我提出的查询。

g.V('keanureeves')
.repeat(both().simplePath())
.until(hasId('marlonbrando'))
.path()
.limit(1)

该查询适用于小图。我可以查询和构建路径。但是,一旦我达到某个图表大小,查询就会超时并且永远不会完成。

我在本地使用CosmosDB模拟器,而不是Azure上真正的CosmosDB。很难说数据库中有多少文档,因为模拟器UI并没有为我提供查询计数的方法。

我可以在不更改数据模型的情况下加快查询速度吗?如果我必须更改我的数据模型,哪些可能更好?我是图表数据库和Gremlin的新手。

编辑:似乎发生在1200到1300个文档之间。在1200份文件下,结果返回。这是文档类型的细分:

540 movie vertexes
112 actor vertexes
681 actedIn edges

编辑#2:我使用的是Microsoft.Azure.Graphs NuGet包,看起来我调用的方法是抛出OutOfMemory异常。我的代码:

public async Task<IList<T>> ExecuteQueryAsync<T>(string gremlinQuery)
{
        var query = _documentClient.CreateGremlinQuery(_graph, gremlinQuery);

        var results = new List<T>();
        while (query.HasMoreResults)
        {
            var feed = await query.ExecuteNextAsync<T>();
            results.AddRange(feed.Select(x => x));
        }
        return results;
}

堆栈追踪:

System.AggregateException: One or more errors occurred. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.GetTaskForResult(TResult result)
    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetResult(TResult result)
    at Microsoft.Azure.Graphs.Runtime.Operators.ProjectOperator.<NextAsync>d__4.MoveNext()
    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
    at Microsoft.Azure.Graphs.Runtime.Operators.ProjectOperator.NextAsync()
    at Microsoft.Azure.Graphs.Runtime.ScalarSubqueryFunction.<EvaluateAsync>d__3.MoveNext()
    --- End of inner exception stack trace ---
    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
    at System.Threading.Tasks.Task`1.get_Result()
    at Microsoft.Azure.Graphs.Runtime.Operators.PathOperator.GetStepProjectionResult(FieldObject step, Int32& activeByFuncIndex)
    at Microsoft.Azure.Graphs.Runtime.Operators.PathOperator.<NextAsync>d__4.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Graphs.Runtime.Operators.SimplePathOperator.<NextAsync>d__3.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
    at Microsoft.Azure.Graphs.Runtime.Operators.PathOperator.<NextAsync>d__4.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Graphs.Runtime.Operators.ProjectOperator.<NextAsync>d__4.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
    at Microsoft.Azure.Graphs.Runtime.Operators.RepeatOperator.<NextAsync>d__18.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
    at Microsoft.Azure.Graphs.Runtime.Operators.PathOperator.<NextAsync>d__4.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Graphs.Runtime.Operators.RangeOperator.<NextAsync>d__5.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Graphs.Runtime.Operators.ProjectOperator.<NextAsync>d__4.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Graphs.GraphTraversal.GraphTraversalIterator.<CurrentOperatorNextAsync>d__14.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Graphs.GraphTraversal.GraphTraversalIterator.<MoveNextAsync>d__5.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Graphs.GraphTraversal.<MoveNextAsync>d__17.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.Azure.Graphs.GremlinDocumentQuery`1.<ExecuteNextAsync>d__15`1.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at Octogami.SixDegreesOfNetflix.Application.Data.GremlinClient.<ExecuteQueryAsync>d__3`1.MoveNext() in C:\dev\SixDegreesOfNetflix\Application\Data\GremlinClient.cs:line 28
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at Octogami.SixDegreesOfNetflix.Application.Data.ActorPathRepository.<GetPathBetweenActors>d__2.MoveNext() in C:\dev\SixDegreesOfNetflix\Application\Data\ActorPathRepository.cs:line 20
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at Octogami.SixDegreesOfNetflix.Application.Feature.GetPathBetweenActorsCommandHandler.<Handle>d__3.MoveNext() in C:\dev\SixDegreesOfNetflix\Application\Feature\GetPathBetweenActors.cs:line 42
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at Octogami.SixDegreesOfNetflix.Website.Controllers.ActorController.<DegreesOfSeparation>d__5.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
    at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
 ---> (Inner Exception #0) System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.GetTaskForResult(TResult result)
    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetResult(TResult result)
    at Microsoft.Azure.Graphs.Runtime.Operators.ProjectOperator.<NextAsync>d__4.MoveNext()
    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
    at Microsoft.Azure.Graphs.Runtime.Operators.ProjectOperator.NextAsync()
    at Microsoft.Azure.Graphs.Runtime.ScalarSubqueryFunction.<EvaluateAsync>d__3.MoveNext()<---

1 个答案:

答案 0 :(得分:0)

在0.2.4预览Nuget包中,limit()子句的行为不正确。在0.3.0预览Nuget包中,为limit()遍历步骤添加了优化。当我更新包时,我的问题就解决了。

请参阅Graph SDK page上的更改日志。