跳至主要内容
跳至主要内容

配额

ClickHouse Cloud 中的配额

ClickHouse Cloud 支持配额,但必须使用 DDL 语法 创建。 以下文档中记录的 XML 配置方法不受支持

配额允许您限制一段时间内的资源使用情况,或跟踪资源的消耗。 配额是在用户配置中设置的,通常是 'users.xml'。

系统还具有限制单个查询复杂度的功能。 请参阅 查询复杂度限制 部分。

与查询复杂度限制不同,配额

  • 对可以在一段时间内运行的一组查询施加限制,而不是限制单个查询。
  • 考虑分布式查询处理中所有远程服务器上消耗的资源。

让我们看一下定义配额的 'users.xml' 文件部分。

<!-- Quotas -->
<quotas>
    <!-- Quota name. -->
    <default>
        <!-- Restrictions for a time period. You can set many intervals with different restrictions. -->
        <interval>
            <!-- Length of the interval. -->
            <duration>3600</duration>

            <!-- Unlimited. Just collect data for the specified time interval. -->
            <queries>0</queries>
            <query_selects>0</query_selects>
            <query_inserts>0</query_inserts>
            <errors>0</errors>
            <result_rows>0</result_rows>
            <read_rows>0</read_rows>
            <execution_time>0</execution_time>
        </interval>
    </default>

默认情况下,配额跟踪每个小时的资源消耗,而不限制使用量。 为每个间隔计算的资源消耗会在每次请求后输出到服务器日志。

<statbox>
    <!-- Restrictions for a time period. You can set many intervals with different restrictions. -->
    <interval>
        <!-- Length of the interval. -->
        <duration>3600</duration>

        <queries>1000</queries>
        <query_selects>100</query_selects>
        <query_inserts>100</query_inserts>
        <written_bytes>5000000</written_bytes>
        <errors>100</errors>
        <result_rows>1000000000</result_rows>
        <read_rows>100000000000</read_rows>
        <execution_time>900</execution_time>
        <failed_sequential_authentications>5</failed_sequential_authentications>
    </interval>

    <interval>
        <duration>86400</duration>

        <queries>10000</queries>
        <query_selects>10000</query_selects>
        <query_inserts>10000</query_inserts>
        <errors>1000</errors>
        <result_rows>5000000000</result_rows>
        <result_bytes>160000000000</result_bytes>
        <read_rows>500000000000</read_rows>
        <result_bytes>16000000000000</result_bytes>
        <execution_time>7200</execution_time>
    </interval>
</statbox>

对于 'statbox' 配额,每小时和每天(86,400 秒)设置限制。 时间间隔是从实现定义的固定时刻开始计算的。 换句话说,24 小时的时间间隔不一定从午夜开始。

当间隔结束时,所有收集的值都会被清除。 对于下一个小时,配额计算会重新开始。

以下是可以限制的量

queries – 请求的总数。

query_selects – select 请求的总数。

query_inserts – insert 请求的总数。

errors – 抛出异常的查询数量。

result_rows – 作为结果返回的总行数。

result_bytes - 作为结果返回的行的总大小。

read_rows – 在所有远程服务器上运行查询时从表中读取的总源行数。

read_bytes - 在所有远程服务器上运行查询时从表中读取的总大小。

written_bytes - 写入操作的总大小。

execution_time – 查询总执行时间,以秒为单位(实际时间)。

failed_sequential_authentications - 连续身份验证错误的次数。

如果至少在一个时间间隔内超过了限制,则会抛出一个异常,其中包含关于哪个限制被超过、针对哪个间隔以及新间隔何时开始(可以再次发送查询)的文本。

配额可以使用“配额键”功能来独立地报告多个键的资源。 这里有一个例子

<!-- For the global reports designer. -->
<web_global>
    <!-- keyed – The quota_key "key" is passed in the query parameter,
            and the quota is tracked separately for each key value.
        For example, you can pass a username as the key,
            so the quota will be counted separately for each username.
        Using keys makes sense only if quota_key is transmitted by the program, not by a user.

        You can also write <keyed_by_ip />, so the IP address is used as the quota key.
        (But keep in mind that users can change the IPv6 address fairly easily.)
    -->
    <keyed />

配额分配给配置的 'users' 部分中的用户。 请参阅“访问权限”部分。

对于分布式查询处理,累积的量存储在请求服务器上。 因此,如果用户切换到另一个服务器,那里的配额将“重新开始”。

服务器重启时,配额会被重置。

    © . This site is unofficial and not affiliated with ClickHouse, Inc.