配置缓存
重要
AKS 上的 Azure HDInsight 已于 2025 年 1 月 31 日停用。 了解更多信息,请查看此公告 。
需要将工作负荷迁移到 Microsoft Fabric 或等效的 Azure 产品,以避免工作负荷突然终止。
重要
此功能目前以预览版提供。 Microsoft Azure 预览版的补充使用条款 包括适用于 beta 版、预览版或尚未正式发布的 Azure 功能的更多法律条款。 关于这一特定预览的信息,请参阅 AKS 上的 Azure HDInsight 预览信息。 有关问题或功能建议,请在 AskHDInsight 上提交请求,并提供详细信息。关注我们以获取有关 Azure HDInsight Community 的更多更新。
使用 Hive 连接器查询对象存储是 Trino 的常见用例。 此过程通常涉及发送大量数据。 对象由多个辅助角色从 HDFS 或其他受支持的对象存储中检索,并由这些辅助角色处理。 具有不同参数的重复查询,甚至来自不同用户的查询,通常访问和传输相同的对象。
AKS 上的 HDInsight 为 Trino 添加了 最终结果缓存 功能,这具有以下优势:
- 减少对象存储上的负载。
- 提高查询性能。
- 降低查询成本。
缓存选项
缓存的不同选项:
- 最终结果缓存:当在协调器组件配置部分中启用时,任何目录的查询结果都会缓存到协调器 VM 上。
- Hive/Iceberg/Delta Lake 目录缓存:启用后(针对相应类型的特定目录),每个查询的拆分数据会在工作节点 VM 上的群集内进行缓存。
最终结果缓存
最终结果缓存可以通过两种方式进行配置:
- 使用 Azure 门户
- 使用 ARM 模板
可用的配置参数包括:
财产 | 违约 | 描述 |
---|---|---|
query.cache.enabled |
假 | 启用最终结果缓存(如果为 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 |
假 | 如果设置为 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 门户
在 Azure 门户搜索栏中,键入“AKS 群集上的 HDInsight”,然后从下拉列表中选择“AKS 群集上的 Azure HDInsight”。
从列表页中选择群集名称。
导航到 配置管理 面板。
显示 Azure 门户配置管理的
转到 config.properties -> 自定义配置,然后单击 添加。
显示自定义配置的
设置所需的属性,然后单击“确定”。
显示配置属性的
保存配置。
使用 ARM 模板
先决条件
- 在 AKS 上运行的具备 HDInsight 的 Trino 集群。
- 为群集创建 ARM 模板。
- 查看完整的 群集 ARM 模板示例。
- 熟悉 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 # Hive缓存磁盘使用百分比设置为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 模板。