你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

配置缓存

重要

此功能目前以预览版提供。 Microsoft Azure 预览版的补充使用条款包含适用于 beta 版、预览版或其他尚未正式发布的 Azure 功能的更多法律条款。 有关此特定预览版的信息,请参阅 Azure HDInsight on AKS 预览版信息。 如有疑问或功能建议,请在 AskHDInsight 上提交请求并附上详细信息,并关注我们以获取 Azure HDInsight Community 的更多更新。

使用 Hive 连接器查询对象存储是 Trino 的一种常见用例。 此过程通常涉及到发送大量数据。 对象由多个工作器从 HDFS 或其他受支持的对象存储中检索,并由这些工作器进行处理。 包含不同参数的重复查询,甚至来自不同用户的不同查询,常常会访问和传输相同的对象。

HDInsight on AKS 为 Trino 添加了最终结果缓存功能,该功能具有以下优势:

  • 减少对象存储上的负载。
  • 提高查询性能。
  • 降低查询成本。

缓存选项

不同的缓存选项:

  • 最终结果缓存:启用后(在协调器组件配置部分),对任何目录运行的任何查询的结果将缓存在协调器 VM 上。
  • Hive/Iceberg/Delta Lake 目录缓存:启用后(针对相应类型的特定目录),每个查询的拆分数据将缓存在工作器 VM 上的群集中。

最终结果缓存

可以通过两种方式配置最终结果缓存:

可用的配置参数为:

properties 默认 说明
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 指标,可以使用托管 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 门户搜索栏中,键入“HDInsight on AKS 群集”,然后从下拉列表中选择“Azure HDInsight on AKS 群集”。

    屏幕截图显示了用于开始使用 HDInsight on AKS 群集的搜索选项。

  3. 从列表页面中选择你的群集名称。

    屏幕截图显示了如何从列表中选择所需的 HDInsight on AKS 群集。

  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 模板