SuperAPI AI 工具集

starrocks-resource-management

数据与分析

查看项目

更新于 10-16 06:57

技能介绍

用途

StarRocks Resource Management 用于控制 StarRocks 如何消耗计算与存储资源,覆盖会话级限制、资源组和存储卷三个方面。典型使用场景包括:隔离不同工作负载(如 ETL 与交互式看板)、限制单查询的内存、CPU 或并发、控制查询并行度或启用磁盘溢写、以及通过存储卷配置远程/分层存储。

相关技能:starrocks-cluster-setup 用于底层节点拓扑;starrocks-query-optimization 用于针对具体查询调优并行度;starrocks-monitoring 用于观察资源使用情况。

会话级资源控制

可通过 SET 语句在会话级别调整资源参数:

-- Set query timeout
SET query_timeout = 300;

-- Set memory limit per query
SET query_mem_limit = 8589934592;  -- 8GB in bytes

-- Enable spilling to disk for large operations
SET enable_spill = true;
SET spill_mem_limit_threshold = 0.8;

-- Control parallelism
SET pipeline_dop = 16;  -- Degree of parallelism
SET parallel_fragment_exec_instance_num = 8;

资源组(全局)

用户/角色通过 TO (...) 子句中的分类器(classifiers)映射到资源组,不存在 SET PROPERTY ... 'resource_group' 这种写法。CPU 份额通过 cpu_weight(相对权重)或 exclusive_cpu_cores(独占核心)设置;旧的 cpu_core_limit/"type" 属性自 v3.3.5 起已废弃。

-- Create resource group for ETL jobs, mapped to a user via a classifier
CREATE RESOURCE GROUP etl_group
TO (user = 'etl_user')
WITH (
    "cpu_weight" = "10",
    "mem_limit" = "50%",
    "concurrency_limit" = "10"
);

-- Create high-priority group for dashboards with dedicated CPU cores
CREATE RESOURCE GROUP dashboard_group
TO (user = 'dashboard_user', query_type in ('select'))
WITH (
    "exclusive_cpu_cores" = "20",
    "mem_limit" = "30%",
    "concurrency_limit" = "20"
);

-- View resource groups
SHOW RESOURCE GROUPS ALL;

存储卷管理

可创建存储卷用于远程存储,并将表指向该存储卷:

-- Create storage volume (for remote storage)
CREATE STORAGE VOLUME my_s3_volume
TYPE = S3
LOCATIONS = ("s3://my-bucket/starrocks/")   -- bucket/path only (use s3:// here, unlike backup repos which use s3a://)
PROPERTIES (
    "enabled" = "true",                       -- required to activate the volume
    "aws.s3.region" = "us-east-1",
    "aws.s3.access_key" = "your_key",
    "aws.s3.secret_key" = "your_secret"
);

-- Set table to use remote storage
ALTER TABLE large_table
SET ("storage_volume" = "my_s3_volume");

适用场景

  • 将 ETL 批处理与交互式看板查询隔离到不同资源组,避免相互抢占资源。
  • 为单条查询设置内存上限、超时时间或并发上限,防止个别查询拖垮集群。
  • 调整查询并行度,或对大操作启用磁盘溢写以降低内存压力。
  • 使用存储卷将大表数据放到 S3 等远程/分层存储上。

限制

资料未提供关于版本兼容范围、权限要求、参数取值范围、性能影响或配额上限的更多说明,这些内容暂未提供。