ClickHouse/docs/en/operations/quotas.md

121 lines
4.7 KiB
Markdown
Raw Normal View History

2020-04-03 13:23:32 +00:00
---
2022-03-30 02:38:50 +00:00
sidebar_position: 51
sidebar_label: Quotas
2020-04-03 13:23:32 +00:00
---
2020-03-18 18:43:51 +00:00
# Quotas {#quotas}
2020-04-04 06:35:35 +00:00
Quotas allow you to limit resource usage over a period of time or track the use of resources.
Quotas are set up in the user config, which is usually users.xml.
The system also has a feature for limiting the complexity of a single query. See the section [Restrictions on query complexity](../operations/settings/query-complexity.md).
In contrast to query complexity restrictions, quotas:
- Place restrictions on a set of queries that can be run over a period of time, instead of limiting a single query.
- Account for resources spent on all remote servers for distributed query processing.
2020-03-20 10:10:48 +00:00
Lets look at the section of the users.xml file that defines quotas.
2020-03-20 10:10:48 +00:00
``` xml
<!-- Quotas -->
<quotas>
2018-04-23 06:20:21 +00:00
<!-- Quota name. -->
<default>
2018-04-23 06:20:21 +00:00
<!-- Restrictions for a time period. You can set many intervals with different restrictions. -->
<interval>
<!-- Length of the interval. -->
2018-03-25 02:04:22 +00:00
<duration>3600</duration>
2018-04-23 06:20:21 +00:00
<!-- Unlimited. Just collect data for the specified time interval. -->
<queries>0</queries>
<query_selects>0</query_selects>
<query_inserts>0</query_inserts>
2018-04-23 06:20:21 +00:00
<errors>0</errors>
<result_rows>0</result_rows>
<read_rows>0</read_rows>
<execution_time>0</execution_time>
</interval>
</default>
```
2020-04-04 06:35:35 +00:00
By default, the quota tracks resource consumption for each hour, without limiting usage.
The resource consumption calculated for each interval is output to the server log after each request.
2020-03-20 10:10:48 +00:00
``` xml
<statbox>
2018-04-23 06:20:21 +00:00
<!-- 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>
2018-04-23 06:20:21 +00:00
<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>
2018-04-23 06:20:21 +00:00
<errors>1000</errors>
<result_rows>5000000000</result_rows>
<read_rows>500000000000</read_rows>
<execution_time>7200</execution_time>
</interval>
</statbox>
```
2021-05-27 19:44:11 +00:00
For the statbox quota, restrictions are set for every hour and for every 24 hours (86,400 seconds). The time interval is counted, starting from an implementation-defined fixed moment in time. In other words, the 24-hour interval does not necessarily begin at midnight.
When the interval ends, all collected values are cleared. For the next hour, the quota calculation starts over.
Here are the amounts that can be restricted:
`queries` The total number of requests.
`query_selects` The total number of select requests.
`query_inserts` The total number of insert requests.
`errors` The number of queries that threw an exception.
2020-04-04 06:35:35 +00:00
`result_rows` The total number of rows given as a result.
2020-04-04 06:35:35 +00:00
`read_rows` The total number of source rows read from tables for running the query on all remote servers.
`execution_time` The total query execution time, in seconds (wall time).
If the limit is exceeded for at least one time interval, an exception is thrown with a text about which restriction was exceeded, for which interval, and when the new interval begins (when queries can be sent again).
2020-04-04 06:35:35 +00:00
Quotas can use the “quota key” feature to report on resources for multiple keys independently. Here is an example of this:
2020-03-20 10:10:48 +00:00
``` xml
<!-- For the global reports designer. -->
<web_global>
2020-03-20 10:10:48 +00:00
<!-- keyed The quota_key "key" is passed in the query parameter,
2018-04-23 06:20:21 +00:00
and the quota is tracked separately for each key value.
2022-03-29 14:26:35 +00:00
For example, you can pass a username as the key,
2018-04-23 06:20:21 +00:00
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.
2020-04-04 06:35:35 +00:00
You can also write <keyed_by_ip />, so the IP address is used as the quota key.
2018-04-23 06:20:21 +00:00
(But keep in mind that users can change the IPv6 address fairly easily.)
2018-03-25 02:04:22 +00:00
-->
<keyed />
```
2020-03-20 10:10:48 +00:00
The quota is assigned to users in the users section of the config. See the section “Access rights”.
2020-03-20 10:10:48 +00:00
For distributed query processing, the accumulated amounts are stored on the requestor server. So if the user goes to another server, the quota there will “start over”.
When the server is restarted, quotas are reset.
2018-04-23 06:20:21 +00:00
[Original article](https://clickhouse.com/docs/en/operations/quotas/) <!--hide-->