Neptune 中的 Gremlin profile API - Amazon Neptune

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Neptune 中的 Gremlin profile API

Neptune Gremlin profile API 可运行指定的 Gremlin 遍历、收集有关运行的各种指标并生成分析报告作为输出。

注意

它与 TinkerPop .profile () 步骤的不同之处在于能够报告特定于 Neptune 引擎的信息。

分析报告包括有关查询计划的以下信息:

  • 物理运算符管道

  • 查询执行和序列化的索引操作

  • 结果大小

profile API 使用的是 HTTP API 查询语法的扩展版本,以 /gremlin/profile 而不是 /gremlin 作为终端节点。

Neptune Gremlin profile 特定的参数

  • profile.resultsboolean,允许的值:TRUEFALSE,默认值:TRUE

    如果为 true,则收集查询结果并显示为 profile 报告的一部分。如果为 false,则仅显示结果计数。

  • profile.chopint,默认值:250。

    如果不为零,结果字符串将在该字符数处截断。这不影响捕获所有结果。它只是限制了分析报告中字符串的大小。如果设置为零,字符串将包含所有结果。

  • profile.serializerstring,默认值:<null>

    如果不为空,则在以该参数指定的格式序列化的响应消息中返回收集的结果。将报告生成该响应消息所需的索引操作数以及要发送到客户端的字节大小。

    允许的值是<null>或任何有效的 MIME 类型或 TinkerPop 驱动程序 “序列化器” 枚举值。

    "application/json" or "GRAPHSON" "application/vnd.gremlin-v1.0+json" or "GRAPHSON_V1" "application/vnd.gremlin-v1.0+json;types=false" or "GRAPHSON_V1_UNTYPED" "application/vnd.gremlin-v2.0+json" or "GRAPHSON_V2" "application/vnd.gremlin-v2.0+json;types=false" or "GRAPHSON_V2_UNTYPED" "application/vnd.gremlin-v3.0+json" or "GRAPHSON_V3" "application/vnd.gremlin-v3.0+json;types=false" or "GRAPHSON_V3_UNTYPED" "application/vnd.graphbinary-v1.0" or "GRAPHBINARY_V1"
  • profile.indexOpsboolean,允许的值:TRUEFALSE,默认值:FALSE

    如果为 true,则显示查询执行和序列化期间发生的所有索引操作的详细报告。警告:该报告可能会很长。

Neptune Gremlin profile 的示例输出

下面是一个示例 profile 查询。

curl -X POST https://your-neptune-endpoint:port/gremlin/profile \ -d '{"gremlin":"g.V().hasLabel(\"airport\") .has(\"code\", \"AUS\") .emit() .repeat(in().simplePath()) .times(2) .limit(100)", "profile.serializer":"application/vnd.gremlin-v3.0+gryo"}'

在博客文章我来为您创建该图形 - 第 1 部分 – 航线中的航线示例图形上执行此查询时,此查询会生成以下 profile 报告。

******************************************************* Neptune Gremlin Profile ******************************************************* Query String ================== g.V().hasLabel("airport").has("code", "AUS").emit().repeat(in().simplePath()).times(2).limit(100) Original Traversal ================== [GraphStep(vertex,[]), HasStep([~label.eq(airport), code.eq(AUS)]), RepeatStep(emit(true),[VertexStep(IN,vertex), PathFilterStep(simple), RepeatEndStep],until(loops(2))), RangeGlobalStep(0,100)] Optimized Traversal =================== Neptune steps: [ NeptuneGraphQueryStep(Vertex) { JoinGroupNode { PatternNode[(?1, <code>, "AUS", ?) . project ?1 .], {estimatedCardinality=1, indexTime=84, hashJoin=true, joinTime=3, actualTotalOutput=1} PatternNode[(?1, <~label>, ?2=<airport>, <~>) . project ask .], {estimatedCardinality=3374, indexTime=29, hashJoin=true, joinTime=0, actualTotalOutput=61} RepeatNode { Repeat { PatternNode[(?3, ?5, ?1, ?6) . project ?1,?3 . IsEdgeIdFilter(?6) . SimplePathFilter(?1, ?3)) .], {hashJoin=true, estimatedCardinality=50148, indexTime=0, joinTime=3} } Emit { Filter(true) } LoopsCondition { LoopsFilter([?1, ?3],eq(2)) } }, annotations={repeatMode=BFS, emitFirst=true, untilFirst=false, leftVar=?1, rightVar=?3} }, finishers=[limit(100)], annotations={path=[Vertex(?1):GraphStep, Repeat[Vertex(?3):VertexStep]], joinStats=true, optimizationTime=495, maxVarId=7, executionTime=323} }, NeptuneTraverserConverterStep ] Physical Pipeline ================= NeptuneGraphQueryStep |-- StartOp |-- JoinGroupOp |-- SpoolerOp(100) |-- DynamicJoinOp(PatternNode[(?1, <code>, "AUS", ?) . project ?1 .], {estimatedCardinality=1, indexTime=84, hashJoin=true}) |-- SpoolerOp(100) |-- DynamicJoinOp(PatternNode[(?1, <~label>, ?2=<airport>, <~>) . project ask .], {estimatedCardinality=3374, indexTime=29, hashJoin=true}) |-- RepeatOp |-- <upstream input> (Iteration 0) [visited=1, output=1 (until=0, emit=1), next=1] |-- BindingSetQueue (Iteration 1) [visited=61, output=61 (until=0, emit=61), next=61] |-- SpoolerOp(100) |-- DynamicJoinOp(PatternNode[(?3, ?5, ?1, ?6) . project ?1,?3 . IsEdgeIdFilter(?6) . SimplePathFilter(?1, ?3)) .], {hashJoin=true, estimatedCardinality=50148, indexTime=0}) |-- BindingSetQueue (Iteration 2) [visited=38, output=38 (until=38, emit=0), next=0] |-- SpoolerOp(100) |-- DynamicJoinOp(PatternNode[(?3, ?5, ?1, ?6) . project ?1,?3 . IsEdgeIdFilter(?6) . SimplePathFilter(?1, ?3)) .], {hashJoin=true, estimatedCardinality=50148, indexTime=0}) |-- LimitOp(100) Runtime (ms) ============ Query Execution: 392.686 Serialization: 2636.380 Traversal Metrics ================= Step Count Traversers Time (ms) % Dur ------------------------------------------------------------------------------------------------------------- NeptuneGraphQueryStep(Vertex) 100 100 314.162 82.78 NeptuneTraverserConverterStep 100 100 65.333 17.22 >TOTAL - - 379.495 - Repeat Metrics ============== Iteration Visited Output Until Emit Next ------------------------------------------------------ 0 1 1 0 1 1 1 61 61 0 61 61 2 38 38 38 0 0 ------------------------------------------------------ 100 100 38 62 62 Predicates ========== # of predicates: 16 WARNING: reverse traversal with no edge label(s) - .in() / .both() may impact query performance Results ======= Count: 100 Output: [v[3], v[3600], v[3614], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[47], v[49], v[136], v[13], v[15], v[16], v[17], v[18], v[389], v[20], v[21], v[22], v[23], v[24], v[25], v[26], v[27], v[28], v[416], v[29], v[30], v[430], v[31], v[9... Response serializer: GRYO_V3D0 Response size (bytes): 23566 Index Operations ================ Query execution: # of statement index ops: 3 # of unique statement index ops: 3 Duplication ratio: 1.0 # of terms materialized: 0 Serialization: # of statement index ops: 200 # of unique statement index ops: 140 Duplication ratio: 1.43 # of terms materialized: 393

除了通过调用 Neptune explain 返回的查询计划之外,profile 结果还包括有关查询执行的运行时系统统计数据。每个 Join 操作都标记了执行其联接所花费的时间以及进行该操作的解决方案的实际数量。

profile 输出包括在核心查询执行阶段以及序列化阶段(如果指定了 profile.serializer 选项)所花费的时间。

profile 输出的底部还包括在每个阶段执行的索引操作的明细。

请注意,出于缓存原因,同一查询的连续运行在运行时和索引操作方面可能会显示不同的结果。

对于使用 repeat() 步骤的查询,如果将 repeat() 步骤作为 NeptuneGraphQueryStep 的一部分下推,还将提供每次迭代边界的明细。

启用 DFE 时 profile 报告的差异

启用 Neptune DFE 替代查询引擎后,profile 输出会有所不同:

优化的遍历:本部分与 explain 输出中的一个部分类似,但包含其它信息。这包括在规划中考虑的 DFE 运算符类型,以及相关的最坏情况和最佳情况的成本估算。

物理管道:本部分捕获了用于执行查询的运算符。DFESubQuery 元素抽象了 DFE 用来执行计划中其负责的部分的物理计划。这些 DFESubQuery 元素将在下一部分中展开,其中列出了 DFE 统计数据。

DFE QueryEngine 统计信息:只有当 DFE 至少执行了部分查询时,才会显示此部分。这一部分概述了特定于 DFE 的各种运行时系统统计数据,并包含查询执行按 DFESubQuery 划分的各个部分所花费时间的详细细分。

在此部分中,不同 DFESubQuery 元素中的嵌套子查询是展平的,唯一标识符用以 subQuery= 开头的标头标记。

遍历指标:此部分显示阶梯级遍历指标,当 DFE 引擎运行查询的全部或部分内容时,显示 DFEStep 和/或 NeptuneInterleavingStep 的指标。请参阅 使用 explain 和 profile 调整 Gremlin 查询

注意

DFE 是在实验室模式下发布的一项实验特征,因此 profile 输出的确切格式仍可能发生变化。

启用 Neptune 数据流引擎 (DFE) 时的 profile 输出示例

使用 DFE 引擎运行 Gremlin 查询时,Gremlin profile API 的输出格式如下例所示。

查询:

curl https://localhost:8182/gremlin/profile \ -d "{\"gremlin\": \"g.withSideEffect('Neptune#useDFE', true).V().has('code', 'ATL').out()\"}"
******************************************************* Neptune Gremlin Profile ******************************************************* Query String ================== g.withSideEffect('Neptune#useDFE', true).V().has('code', 'ATL').out() Original Traversal ================== [GraphStep(vertex,[]), HasStep([code.eq(ATL)]), VertexStep(OUT,vertex)] Optimized Traversal =================== Neptune steps: [ DFEStep(Vertex) { DFENode { DFEJoinGroupNode[null]( children=[ DFEPatternNode((?1, vp://code[419430926], ?4, defaultGraph[526]) . project DISTINCT[?1] objectFilters=(in(ATL[452987149]) . ), {rangeCountEstimate=1}, opInfo=(type=PipelineJoin, cost=(exp=(in=1.00,out=1.00,io=0.00,comp=0.00,mem=0.00),wc=(in=1.00,out=1.00,io=0.00,comp=0.00,mem=0.00)), disc=(type=PipelineScan, cost=(exp=(in=1.00,out=1.00,io=0.00,comp=0.00,mem=34.00),wc=(in=1.00,out=1.00,io=0.00,comp=0.00,mem=34.00))))), DFEPatternNode((?1, ?5, ?6, ?7) . project ALL[?1, ?6] graphFilters=(!= defaultGraph[526] . ), {rangeCountEstimate=9223372036854775807})], opInfo=[ OperatorInfoWithAlternative[ rec=(type=PipelineJoin, cost=(exp=(in=1.00,out=27.76,io=0.00,comp=0.00,mem=0.00),wc=(in=1.00,out=27.76,io=0.00,comp=0.00,mem=0.00)), disc=(type=PipelineScan, cost=(exp=(in=1.00,out=27.76,io=Infinity,comp=0.00,mem=295147905179352830000.00),wc=(in=1.00,out=27.76,io=Infinity,comp=0.00,mem=295147905179352830000.00)))), alt=(type=PipelineScan, cost=(exp=(in=1.00,out=27.76,io=Infinity,comp=0.00,mem=295147905179352830000.00),wc=(in=1.00,out=27.76,io=Infinity,comp=0.00,mem=295147905179352830000.00)))]]) } [Vertex(?1):GraphStep, Vertex(?6):VertexStep] } , NeptuneTraverserConverterDFEStep, DFECleanupStep ] Physical Pipeline ================= DFEStep |-- DFESubQuery1 DFEQueryEngine Statistics ================= DFESubQuery1 ╔════╤════════╤════════╤═══════════════════════╤══════════════════════════════════════════════════════════════════════════════════════════════════════════════╤══════╤══════════╤═══════════╤════════╤═══════════╗ ║ ID │ Out #1 │ Out #2 │ Name │ Arguments │ Mode │ Units In │ Units Out │ Ratio │ Time (ms) ║ ╠════╪════════╪════════╪═══════════════════════╪══════════════════════════════════════════════════════════════════════════════════════════════════════════════╪══════╪══════════╪═══════════╪════════╪═══════════╣ ║ 0 │ 1 │ - │ DFESolutionInjection │ solutions=[] │ - │ 0 │ 1 │ 0.00 │ 0.01 ║ ║ │ │ │ │ outSchema=[] │ │ │ │ │ ║ ╟────┼────────┼────────┼───────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 1 │ 2 │ - │ DFEChunkLocalSubQuery │ subQuery=http://aws.amazon.com/neptune/vocab/v01/dfe/past/graph#089f43e3-4d71-4259-8d19-254ff63cee04/graph_1 │ - │ 1 │ 1 │ 1.00 │ 0.02 ║ ╟────┼────────┼────────┼───────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 2 │ 3 │ - │ DFEChunkLocalSubQuery │ subQuery=http://aws.amazon.com/neptune/vocab/v01/dfe/past/graph#089f43e3-4d71-4259-8d19-254ff63cee04/graph_2 │ - │ 1 │ 242 │ 242.00 │ 0.02 ║ ╟────┼────────┼────────┼───────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 3 │ 4 │ - │ DFEMergeChunks │ - │ - │ 242 │ 242 │ 1.00 │ 0.01 ║ ╟────┼────────┼────────┼───────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 4 │ - │ - │ DFEDrain │ - │ - │ 242 │ 0 │ 0.00 │ 0.01 ║ ╚════╧════════╧════════╧═══════════════════════╧══════════════════════════════════════════════════════════════════════════════════════════════════════════════╧══════╧══════════╧═══════════╧════════╧═══════════╝ subQuery=http://aws.amazon.com/neptune/vocab/v01/dfe/past/graph#089f43e3-4d71-4259-8d19-254ff63cee04/graph_1 ╔════╤════════╤════════╤══════════════════════╤═════════════════════════════════════════════════════════════╤══════╤══════════╤═══════════╤═══════╤═══════════╗ ║ ID │ Out #1 │ Out #2 │ Name │ Arguments │ Mode │ Units In │ Units Out │ Ratio │ Time (ms) ║ ╠════╪════════╪════════╪══════════════════════╪═════════════════════════════════════════════════════════════╪══════╪══════════╪═══════════╪═══════╪═══════════╣ ║ 0 │ 1 │ - │ DFEPipelineScan │ pattern=Node(?1) with property 'code' as ?4 and label 'ALL' │ - │ 0 │ 1 │ 0.00 │ 0.22 ║ ║ │ │ │ │ inlineFilters=[(?4 IN ["ATL"])] │ │ │ │ │ ║ ║ │ │ │ │ patternEstimate=1 │ │ │ │ │ ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────────────────────────────┼──────┼──────────┼───────────┼───────┼───────────╢ ║ 1 │ 2 │ - │ DFEMergeChunks │ - │ - │ 1 │ 1 │ 1.00 │ 0.02 ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────────────────────────────┼──────┼──────────┼───────────┼───────┼───────────╢ ║ 2 │ 4 │ - │ DFERelationalJoin │ joinVars=[] │ - │ 2 │ 1 │ 0.50 │ 0.09 ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────────────────────────────┼──────┼──────────┼───────────┼───────┼───────────╢ ║ 3 │ 2 │ - │ DFESolutionInjection │ solutions=[] │ - │ 0 │ 1 │ 0.00 │ 0.01 ║ ║ │ │ │ │ outSchema=[] │ │ │ │ │ ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────────────────────────────┼──────┼──────────┼───────────┼───────┼───────────╢ ║ 4 │ - │ - │ DFEDrain │ - │ - │ 1 │ 0 │ 0.00 │ 0.01 ║ ╚════╧════════╧════════╧══════════════════════╧═════════════════════════════════════════════════════════════╧══════╧══════════╧═══════════╧═══════╧═══════════╝ subQuery=http://aws.amazon.com/neptune/vocab/v01/dfe/past/graph#089f43e3-4d71-4259-8d19-254ff63cee04/graph_2 ╔════╤════════╤════════╤══════════════════════╤═════════════════════════════════════╤══════╤══════════╤═══════════╤════════╤═══════════╗ ║ ID │ Out #1 │ Out #2 │ Name │ Arguments │ Mode │ Units In │ Units Out │ Ratio │ Time (ms) ║ ╠════╪════════╪════════╪══════════════════════╪═════════════════════════════════════╪══════╪══════════╪═══════════╪════════╪═══════════╣ ║ 0 │ 1 │ - │ DFESolutionInjection │ solutions=[] │ - │ 0 │ 1 │ 0.00 │ 0.01 ║ ║ │ │ │ │ outSchema=[?1] │ │ │ │ │ ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 1 │ 2 │ 3 │ DFETee │ - │ - │ 1 │ 2 │ 2.00 │ 0.01 ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 2 │ 4 │ - │ DFEDistinctColumn │ column=?1 │ - │ 1 │ 1 │ 1.00 │ 0.21 ║ ║ │ │ │ │ ordered=false │ │ │ │ │ ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 3 │ 5 │ - │ DFEHashIndexBuild │ vars=[?1] │ - │ 1 │ 1 │ 1.00 │ 0.03 ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 4 │ 5 │ - │ DFEPipelineJoin │ pattern=Edge((?1)-[?7:?5]->(?6)) │ - │ 1 │ 242 │ 242.00 │ 0.51 ║ ║ │ │ │ │ constraints=[] │ │ │ │ │ ║ ║ │ │ │ │ patternEstimate=9223372036854775807 │ │ │ │ │ ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 5 │ 6 │ 7 │ DFESync │ - │ - │ 243 │ 243 │ 1.00 │ 0.02 ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 6 │ 8 │ - │ DFEForwardValue │ - │ - │ 1 │ 1 │ 1.00 │ 0.01 ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 7 │ 8 │ - │ DFEForwardValue │ - │ - │ 242 │ 242 │ 1.00 │ 0.02 ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 8 │ 9 │ - │ DFEHashIndexJoin │ - │ - │ 243 │ 242 │ 1.00 │ 0.31 ║ ╟────┼────────┼────────┼──────────────────────┼─────────────────────────────────────┼──────┼──────────┼───────────┼────────┼───────────╢ ║ 9 │ - │ - │ DFEDrain │ - │ - │ 242 │ 0 │ 0.00 │ 0.01 ║ ╚════╧════════╧════════╧══════════════════════╧═════════════════════════════════════╧══════╧══════════╧═══════════╧════════╧═══════════╝ Runtime (ms) ============ Query Execution: 11.744 Traversal Metrics ================= Step Count Traversers Time (ms) % Dur ------------------------------------------------------------------------------------------------------------- DFEStep(Vertex) 242 242 10.849 95.48 NeptuneTraverserConverterDFEStep 242 242 0.514 4.52 >TOTAL - - 11.363 - Predicates ========== # of predicates: 18 Results ======= Count: 242 Index Operations ================ Query execution: # of statement index ops: 0 # of terms materialized: 0
注意

由于 DFE 引擎是在实验室模式下发布的实验特征,因此 profile 输出的确切格式可能会发生变化。