[英]Understanding fold() and its impact on gremlin query cost in Azure Cosmos DB
我正在嘗試了解Azure Cosmos DB中的查詢成本
我無法弄清楚以下示例的區別以及為什么使用fold()會降低成本:
g.V().hasLabel('item').project('itemId', 'id').by('itemId').by('id')
產生以下輸出:
[
{
"itemId": 14,
"id": "186de1fb-eaaf-4cc2-b32b-de8d7be289bb"
},
{
"itemId": 5,
"id": "361753f5-7d18-4a43-bb1d-cea21c489f2e"
},
{
"itemId": 6,
"id": "1c0840ee-07eb-4a1e-86f3-abba28998cd1"
},
....
{
"itemId": 5088,
"id": "2ed1871d-c0e1-4b38-b5e0-78087a5a75fc"
}
]
成本為15642 RUs x 0.00008 $ / RU = 1.25 $
g.V().hasLabel('item').project('itemId', 'id').by('itemId').by('id').fold()
產生以下輸出:
[
[
{
"itemId": 14,
"id": "186de1fb-eaaf-4cc2-b32b-de8d7be289bb"
},
{
"itemId": 5,
"id": "361753f5-7d18-4a43-bb1d-cea21c489f2e"
},
{
"itemId": 6,
"id": "1c0840ee-07eb-4a1e-86f3-abba28998cd1"
},
...
{
"itemId": 5088,
"id": "2ed1871d-c0e1-4b38-b5e0-78087a5a75fc"
}
]
]
成本為787 RUs x 0.00008 $ / RU = 0.06 $
g.V().hasLabel('item').values('id', 'itemId')
具有以下輸出:
[
"186de1fb-eaaf-4cc2-b32b-de8d7be289bb",
14,
"361753f5-7d18-4a43-bb1d-cea21c489f2e",
5,
"1c0840ee-07eb-4a1e-86f3-abba28998cd1",
6,
...
"2ed1871d-c0e1-4b38-b5e0-78087a5a75fc",
5088
]
費用:10639 RUs x 0.00008 $ / RU = 0.85 $
g.V().hasLabel('item').values('id', 'itemId').fold()
具有以下輸出:
[
[
"186de1fb-eaaf-4cc2-b32b-de8d7be289bb",
14,
"361753f5-7d18-4a43-bb1d-cea21c489f2e",
5,
"1c0840ee-07eb-4a1e-86f3-abba28998cd1",
6,
...
"2ed1871d-c0e1-4b38-b5e0-78087a5a75fc",
5088
]
]
成本為724.27 RUs x 0.00008 $ / RU = 0.057 $
如您所見,對成本的影響是巨大的。 這只是大約。 3200個節點,幾乎沒有屬性。
我想了解為什么要增加倍數變化。
我試圖重現您的示例,但不幸的是結果相反(Cosmos中有500個頂點):
g.V().hasLabel('test').values('id')
要么
g.V().hasLabel('test').project('id').by('id')
分別給出86.08和91.44 RU,而相同的查詢后跟fold()步驟則得出585.06和590.43 RU。
根據TinkerPop 文檔 ,我得到的結果似乎還不錯:
在某些情況下,遍歷流需要“屏障”來聚合所有對象並發出作為聚合函數的計算。 fold()-step(映射)是其中的一個特定實例。
知道宇宙的RU電荷兩個數訪問的對象和計算的被上獲得的那些對象進行(在該特定情況下倍 ),對倍更高的成本被預期。
您可以嘗試運行遍歷的executionProfile()步驟,這可以幫助您調查案例。 當我嘗試:
g.V().hasLabel('test').values('id').executionProfile()
我為fold()增加了2個步驟(為簡潔起見,省略了輸出的相同部分),而此ProjectAggregation是將結果集從500映射到1的地方:
...
{
"name": "ProjectAggregation",
"time": 165,
"annotations": {
"percentTime": 8.2
},
"counts": {
"resultCount": 1
}
},
{
"name": "QueryDerivedTableOperator",
"time": 1,
"annotations": {
"percentTime": 0.05
},
"counts": {
"resultCount": 1
}
}
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.