跳到主要内容
跳到主要内容

配额

配额允许您限制一段时间内的资源使用量或跟踪资源的使用情况。配额在用户配置中设置,通常是 ‘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>
<errors>100</errors>
<result_rows>1000000000</result_rows>
<read_rows>100000000000</read_rows>
<execution_time>900</execution_time>
</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>
<read_rows>500000000000</read_rows>
<execution_time>7200</execution_time>
</interval>
</statbox>

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

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

以下是可以限制的量

queries – 请求总数。

query_selects – select 请求总数。

query_inserts – insert 请求总数。

errors – 抛出异常的查询数。

result_rows – 作为结果给出的总行数。

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

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

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

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

<!-- 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’ 部分中分配给用户。请参阅 “访问权限” 部分。

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

当服务器重新启动时,配额将被重置。