-
Notifications
You must be signed in to change notification settings - Fork 686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: add slow-query doc #587
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,12 @@ Configuration about log. | |
- Default: false | ||
- If you set the value to true, the log does not output timestamp | ||
|
||
### `slow-query-file` | ||
|
||
- The file name of the slow query log | ||
- Default: "" | ||
- After you set it, the slow query log outputs to this file separately | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. outputs -> is output |
||
|
||
### `slow-threshold` | ||
|
||
- To output the threshold value of consumed time in the slow log | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: Slow Query Log | ||
summary: Use the slow query log to locate inappropriate SQL statements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a period at the end of the sentence. |
||
category: user guide | ||
--- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The metadata cannot display correctly. You can click |
||
|
||
# Slow Query Log | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls also delete the extra space at the beginning of the line. Other similar issues in this doc:
|
||
|
||
An inappropriate SQL statement can increase the pressure on the entire cluster, resulting in a longer response time. To solve this problem, you can use the slow query log to locate the questionable statements and thus improve the performance. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
### Obtain the log | ||
|
||
By grepping the keyword `SLOW_QUERY` in the log file of TiDB, you can obtain the logs of statements whose execution time exceeds [slow-threshold](../op-guide/tidb-config-file.md#slow-threshold). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grepping -> |
||
|
||
`slow-threshold` can be edited in the configuration file and its default value is 300ms. If you configure the [slow-query-file](../op-guide/tidb-config-file.md#slow-query-file), all of the slow query log will be written in this file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
### Usage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Usage/Example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OR you can use Usage Example |
||
|
||
``` | ||
2018/08/20 19:52:08.632 adapter.go:363: [warning] [SLOW_QUERY] cost_time:18.647928814s | ||
process_time:1m6.768s wait_time:12m11.212s backoff_time:600ms request_count:2058 | ||
total_keys:1869712 processed_keys:1869710 succ:true con:3 user:[email protected] | ||
txn_start_ts:402329674704224261 database:test table_ids:[31],index_ids:[1], | ||
sql:select count(c) from sbtest1 use index (k_1) | ||
``` | ||
|
||
### Fields Explanation | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this sentence here: "This section explains fields in the slow query log based on the usage example above." |
||
#### `cost_time` | ||
|
||
The execution time of this statement. Only the statements whose execution time exceeds [slow-threshold](../op-guide/tidb-config-file.md#slow-threshold) output the slow query log. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. output the slow query log -> output this log |
||
|
||
#### `process_time` | ||
|
||
The total processing time that TiKV spends on this statement. Since data is sent to TiKV concurrently for execution, this value may exceed `cost_time`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#### `wait_time` | ||
|
||
The total waiting time that TiKV spends on this statement. Since the `coprocessor` of TiKV runs a limited number of threads, requests may queue up when all threads of `coprocessor` are working. When some request in the queue takes a long time to process, the waiting time of the following requests will increase. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#### `backoff_time` | ||
|
||
The waiting time that TiKV spends before retrying when the mistakes in need of retrying occur. The common mistakes which requires retrying include: lock, Region split, TiKV server is busy, etc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> The waiting time before retry when this statement encounters errors that require a retry. The common such errors include: lock occurs, Region split, the TiKV server is busy. |
||
|
||
#### `request_count` | ||
|
||
The number of `coprocessor` requests that this statement sends. | ||
|
||
#### `total_keys` | ||
|
||
The number of keys that `coprocessor` has scanned. | ||
|
||
#### `processed_keys` | ||
|
||
The number of keys that `coprocessor` has processed. Compared with `total_keys`, `processed_keys` | ||
does not include the old versions of MVCC or the MVCC delete flags. A great difference between `processed_keys` and `total_keys` indicates that the number of old versions are relatively large. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#### `succ` | ||
|
||
Whether the execution of the request succeeds or not. | ||
|
||
#### `con` | ||
|
||
Connection ID or session ID. For example, you can use the keyword `con:3` to grep the log whose session ID is 3. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Connection ID or session ID. -> Connection ID (session ID). Note: To avoid the user think they are two different IDs. |
||
|
||
#### `user` | ||
|
||
The username of the executed statement. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> The username of the user who executes this statement. |
||
|
||
#### `txn_start_ts` | ||
|
||
The start timestamp of the transaction, that is, the ID of the transaction. You can use this value to grep the transaction-related logs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grep -> |
||
|
||
#### `database` | ||
|
||
The current database. | ||
|
||
#### `table_ids` | ||
|
||
The IDs of the tables involved in the statement. | ||
|
||
#### `index_ids` | ||
|
||
The IDs of the indexes involved in the statement. | ||
|
||
#### `sql` | ||
|
||
The SQL statements. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. statements -> statement |
||
|
||
### Ways of locating questionable statements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> Identify problematic SQL statements |
||
|
||
Not all of the `SLOW_QUERY` statements are questionable. Only those whose `process_time` is very large will increase the pressure on the entire cluster. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. questionable -> problematic |
||
|
||
The statements whose `wait_time` is very large and `process_time` is very small are usually not questionable. They are blocked by the real questionable statements so that they have to wait in the execution queue and thus have a much longer response time. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,8 @@ Before starting the process, make sure the result of `ulimit -n` is large enough | |
|
||
## Database access times out and the system load is too high | ||
|
||
Provide the following information: | ||
First, check the [SLOW-QUERY](./sql/slow-query.md) log and see if it's because of some inappropriate SQL statement. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's -> it is |
||
If you failed to solve the problem, provide the following information: | ||
|
||
+ The deployment topology | ||
- How many `tidb-server`/`pd-server`/`tikv-server` instances are deployed? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> Slow Query Log