共用方式為


設定快取

重要

此功能目前為預覽功能。 適用於 Microsoft Azure 預覽版的補充使用規定包含適用於 Beta 版、預覽版或尚未發行至正式運作之 Azure 功能的更合法條款。 如需此特定預覽的相關信息,請參閱 AKS 預覽資訊的 Azure HDInsight。 如需問題或功能建議,請在 AskHDInsight提交要求,並提供詳細數據,並遵循我們在 Azure HDInsight 社群取得更多更新。

使用Hive連接器查詢物件記憶體是 Trino 的常見使用案例。 此程式通常牽涉到傳送大量數據。 物件是由多個背景工作角色從 HDFS 或其他支援的物件存放區擷取,並由這些背景工作角色處理。 具有不同參數的重複查詢,或甚至來自不同使用者的不同查詢,通常會存取和傳輸相同的物件。

AKS 上的 HDInsight 新增 了 Trino 的最終結果快 取功能,可提供下列優點:

  • 減少物件記憶體上的負載。
  • 改善查詢效能。
  • 降低查詢成本。

快取選項

快取的不同選項:

  • 最終結果快取:啟用時(在協調器元件組態區段中),協調器 VM 上任何目錄快取的任何查詢結果。
  • Hive/Iceberg/Delta Lake 目錄快取:啟用時(針對對應類型的特定目錄),背景工作 VM 上叢集內每個查詢快取的分割數據。

最終結果快取

最終結果快取可以透過兩種方式進行設定:

可用的組態參數如下:

屬性 預設 描述
query.cache.enabled false 如果為 true,則啟用最終結果快取。
query.cache.ttl - 定義快取數據在收回之前保留的時間。 例如:“10m”,“1h”
query.cache.disk-usage-percentage 80 用於快取數據的磁碟空間百分比。
query.cache.max-result-data-size 0 結果的數據大小上限。 如果超過此值,則結果不會快取。

注意

最終結果快取會使用查詢計劃和ttl作為快取索引鍵。

最終結果快取也可以透過下列會話參數來控制:

會話參數 預設 描述
query_cache_enabled 原始組態值 啟用/停用查詢/工作階段的最終結果快取。
query_cache_ttl 原始組態值 定義快取數據在收回之前保留的時間。
query_cache_max_result_data_size 原始組態值 結果的數據大小上限。 如果超過此值,則結果不會快取。
query_cache_forced_refresh false 當設定為 true 時,強制快取查詢執行的結果,也就是說,如果結果存在,就會取代現有的快取數據。

注意

會話參數可以設定會話(例如,如果使用 Trino CLI),也可以在查詢文字之前於多語句中設定。 例如,

set session query_cache_enabled=true;
select cust.name, *
from tpch.tiny.orders 
join tpch.tiny.customer as cust on cust.custkey = orders.custkey
order by cust.name
limit 10;

最終結果快取會產生 JMX 計量,可使用 Managed Prometheus 和 Grafana 來檢視。 可用以下計量如下:

計量 描述
trino_cache_cachestats_requestcount 經過快取層的查詢總數。 此數位不包含使用快取關閉執行的查詢。
trino_cache_cachestats_hitcount 快取叫用次數,亦即當數據可供使用並從快取傳回時,查詢數目。
trino_cache_cachestats_misscount 快取遺漏次數,也就是數據無法使用且必須快取的查詢數目。
trino_cache_cachestats_hitrate 針對查詢總數的快取叫用百分比表示。
trino_cache_cachestats_totalevictedcount 從快取收回的快取查詢數目。
trino_cache_cachestats_totalbytesfromsource 從來源讀取的位元組數目。
trino_cache_cachestats_totalbytesfromcache 從快取讀取的位元組數目。
trino_cache_cachestats_totalcachedbytes 快取的位元組總數。
trino_cache_cachestats_totalevictedbytes 收回的位元組總數。
trino_cache_cachestats_spaceused 快取的目前大小。
trino_cache_cachestats_cachereadfailures 因為發生任何錯誤而無法從快取讀取數據的次數。
trino_cache_cachestats_cachewritefailures 因為發生任何錯誤而無法將數據寫入快取的次數。

使用 Azure 入口網站

  1. 登入 Azure 入口網站

  2. 在 Azure 入口網站搜尋列中,輸入「AKS 叢集上的 HDInsight」,然後從下拉式清單中選取 [AKS 叢集上的 Azure HDInsight]。

    顯示開始使用 AKS 叢集上 HDInsight 之搜尋選項的螢幕快照。

  3. 從清單頁面選取叢集名稱。

    顯示從清單中選取 AKS 叢集上 HDInsight 的螢幕快照。

  4. 流覽至 [ 組態管理] 刀鋒視窗。

    顯示 Azure 入口網站 組態管理的螢幕快照。

  5. 移至 config.properties -> 自定義組態,然後按兩下 [ 新增]。

    顯示自訂設定的螢幕快照。

  6. 設定必要的屬性,然後按兩下 [ 確定]。

    顯示組態屬性的螢幕快照。

  7. 儲存設定。

    顯示如何儲存設定的螢幕快照。

使用ARM範本

必要條件

您必須在 ARM 範本的 properties.clusterProfile.serviceConfigsProfiles 區段中定義協調器元件中的屬性。 下列範例示範新增屬性的位置。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "resources": [
        {
            "type": "microsoft.hdinsight/clusterpools/clusters",
            "apiVersion": "<api-version>",
            "name": "<cluster-pool-name>/<cluster-name>",
            "location": "<region, e.g. westeurope>",
            "tags": {},
            "properties": {
                "clusterType": "Trino",

                "clusterProfile": {

                    "serviceConfigsProfiles": [
                        {
                            "serviceName": "trino",
                            "configs": [
                                {
                                    "component": "coordinator",
                                    "files": [
                                        {
                                            "fileName": "config.properties",
                                            "values": {
                                                "query.cache.enabled": "true",
                                                "query.cache.ttl": "10m"
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }

            }
        }
    ]
}

Hive/Iceberg/Delta Lake 快取

這三個連接器都會共用一組相同的參數,如Hive快取中所述

注意

某些參數無法設定,且一律設定為預設值:
hive.cache.data-transfer-port=8898,
hive.cache.bookkeeper-port=8899,
hive.cache.location=/etc/trino/cache,
hive.cache.disk-usage-percentage=80

下列範例示範使用ARM樣本新增屬性以啟用Hive快取的位置。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "resources": [
        {
            "type": "microsoft.hdinsight/clusterpools/clusters",
            "apiVersion": "<api-version>",
            "name": "<cluster-pool-name>/<cluster-name>",
            "location": "<region, e.g. westeurope>",
            "tags": {},
            "properties": {
                "clusterType": "Trino",

                "clusterProfile": {

                    "serviceConfigsProfiles": [
                        {
                            "serviceName": "trino",
                            "configs": [
                                {
                                    "component": "catalogs",
                                    "files": [
                                        {
                                            "fileName": "hive1.properties",
                                            "values": {
                                                "connector.name": "hive"
                                                "hive.cache.enabled": "true",
                                                "hive.cache.ttl": "5d"
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }

            }
        }
    ]
}

部署更新的 ARM 範本,以反映叢集中的變更。 瞭解如何 部署ARM範本