diff --git a/configure-memory-usage.md b/configure-memory-usage.md index 00710333bee5f..589b8f6fa18e2 100644 --- a/configure-memory-usage.md +++ b/configure-memory-usage.md @@ -62,7 +62,7 @@ set @@tidb_mem_quota_query = 8 << 10; ## Configure the memory usage threshold of a tidb-server instance -In the TiDB configuration file, you can set the memory usage threshold of a tidb-server instance by configuring [`server-memory-quota`](/tidb-configuration-file.md#server-memory-quota). +In the TiDB configuration file, you can set the memory usage threshold of a tidb-server instance by configuring [`server-memory-quota`](/tidb-configuration-file.md#server-memory-quota-new-in-v409). The following example sets the total memory usage of a tidb-server instance to 32 GB: @@ -82,7 +82,7 @@ In this configuration, when the memory usage of a tidb-server instance reaches 3 ## Trigger the alarm of excessive memory usage -In the default configuration, a tidb-server instance prints an alarm log and records associated status files when the machine memory usage reaches 80% of its total memory. You can set the memory usage ratio threshold by configuring `memory-usage-alarm-ratio`. For detailed alarm rules, refer to the description of [`memory-usage-alarm-ratio`](/tidb-configuration-file.md#memory-usage-alarm-ratio). +In the default configuration, a tidb-server instance prints an alarm log and records associated status files when the machine memory usage reaches 80% of its total memory. You can set the memory usage ratio threshold by configuring `memory-usage-alarm-ratio`. For detailed alarm rules, refer to the description of [`memory-usage-alarm-ratio`](/tidb-configuration-file.md#memory-usage-alarm-ratio-new-in-v409). Note that after the alarm is triggered once, it will be triggered again only if the memory usage rate has been below the threshold for more than ten seconds and reaches the threshold again. In addition, to avoid storing excessive status files generated by alarms, currently, TiDB only retains the status files generated during the recent five alarms. @@ -110,11 +110,11 @@ The following example constructs a memory-intensive SQL statement that triggers The fields of the example log file above are described as follows: - * `is server-memory-quota set` indicates whether [`server-memory-quota`](/tidb-configuration-file.md#server-memory-quota) is set. + * `is server-memory-quota set` indicates whether [`server-memory-quota`](/tidb-configuration-file.md#server-memory-quota-new-in-v409) is set. * `system memory total` indicates the total memory of the current system. * `system memory usage` indicates the current system memory usage. * `tidb-server memory usage` indicates the memory usage of the tidb-server instance. - * `memory-usage-alarm-ratio` indicates the value of [`memory-usage-alarm-ratio`](/tidb-configuration-file.md#memory-usage-alarm-ratio). + * `memory-usage-alarm-ratio` indicates the value of [`memory-usage-alarm-ratio`](/tidb-configuration-file.md#memory-usage-alarm-ratio-new-in-v409). * `record path` indicates the directory of status files. 5. You can see a set of files in the directory of status files (In the above example, the directory is `/tmp/1000_tidb/MC4wLjAuMDo0MDAwLzAuMC4wLjA6MTAwODA=/tmp-storage/record`), including `goroutinue`, `heap`, and `running_sql`. These three files are suffixed with the time when status files are logged. They respectively record goroutine stack information, the usage status of heap memory, and the running SQL information when the alarm is triggered. For the format of log content in `running_sql`, refer to [`expensive-queries`](/identify-expensive-queries.md). diff --git a/system-variables.md b/system-variables.md index 8a4dbda6beb4a..2439b23073829 100644 --- a/system-variables.md +++ b/system-variables.md @@ -916,5 +916,5 @@ explain select * from t where age=5; - Scope: SESSION - Default value: 0.8 -- TiDB triggers an alarm when the percentage of the memory it takes exceeds a certain threshold. For the detailed usage description of this feature, see [`memory-usage-alarm-ratio`](/tidb-configuration-file.md#memory-usage-alarm-ratio). -- You can set the initial value of this variable by configuring [`memory-usage-alarm-ratio`](/tidb-configuration-file.md#memory-usage-alarm-ratio). +- TiDB triggers an alarm when the percentage of the memory it takes exceeds a certain threshold. For the detailed usage description of this feature, see [`memory-usage-alarm-ratio`](/tidb-configuration-file.md#memory-usage-alarm-ratio-new-in-v409). +- You can set the initial value of this variable by configuring [`memory-usage-alarm-ratio`](/tidb-configuration-file.md#memory-usage-alarm-ratio-new-in-v409). diff --git a/tidb-configuration-file.md b/tidb-configuration-file.md index 291f3a6812c9a..8ce730152e315 100644 --- a/tidb-configuration-file.md +++ b/tidb-configuration-file.md @@ -287,7 +287,7 @@ Configuration items related to performance. - Default value: `0` - The default `0` indicates using all the CPUs on the machine. You can also set it to n, and then TiDB uses n CPUs. -### `server-memory-quota` +### `server-memory-quota` New in v4.0.9 > **Warning:** > @@ -296,11 +296,11 @@ Configuration items related to performance. + The memory usage limit of tidb-server instances. This configuration item completely supersedes the previous [`max-memory`](https://docs.pingcap.com/tidb/stable/tidb-configuration-file#max-memory). + Default value: `0` (in bytes), which means no memory limit. -### `memory-usage-alarm-ratio` +### `memory-usage-alarm-ratio` New in v4.0.9 + TiDB triggers an alarm when the memory usage of tidb-server instance exceeds a certain threshold. The valid value for this configuration item ranges from `0` to `1`. If it is configured as `0` or `1`, this alarm feature is disabled. + Default value: `0.8` -+ When the memory usage alarm is enabled, if [`server-memory-quota`](/tidb-configuration-file.md#server-memory-quota) is not set, then the threshold of memory usage is ```the `memory-usage-alarm-ratio` value * the system memory size```; if [`server-memory-quota`](/tidb-configuration-file.md#server-memory-quota) is set to a value greater than 0, then the threshold of memory usage is ```the `memory-usage-alarm-ratio` value * the `server-memory-quota` value```. ++ When the memory usage alarm is enabled, if [`server-memory-quota`](/tidb-configuration-file.md#server-memory-quota-new-in-v409) is not set, then the threshold of memory usage is ```the `memory-usage-alarm-ratio` value * the system memory size```; if `server-memory-quota` is set to a value greater than 0, then the threshold of memory usage is ```the `memory-usage-alarm-ratio` value * the `server-memory-quota` value```. + When TiDB detects that the memory usage of the tidb-server instance exceeds the threshold, it considers that there might be a risk of OOM. Therefore, it records ten SQL statements with the highest memory usage, ten SQL statements with the longest running time, and the heap profile among all SQL statements currently being executed to the directory [`tmp-storage-path/record`](/tidb-configuration-file.md#tmp-storage-path) and outputs a log containing the keyword `tidb-server has the risk of OOM`. + The value of this configuration item is the initial value of the system variable [`tidb_memory_usage_alarm_ratio`](/system-variables.md#tidb_memory_usage_alarm_ratio).