Skip to content
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 descriptions of new panels and update the plan cache doc #11799

Merged
merged 7 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions grafana-tidb-dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ aliases: ['/docs-cn/dev/grafana-tidb-dashboard/','/docs-cn/dev/reference/key-mon
- Expensive Executor OPS:每秒消耗系统资源比较多的算子。包括 Merge Join、Hash Join、Index Look Up Join、Hash Agg、Stream Agg、Sort、TopN 等。
- Queries Using Plan Cache OPS:每秒使用 Plan Cache 的查询数量。
- Plan Cache Miss OPS:每秒出现 Plan Cache Miss 的数量。
- Plan Cache Memory Usage:每个 TiDB 实例上所有 Plan Cache 缓存的执行计划占用的总内存。
- Plan Cache Plan Num:每个 TiDB 实例上所有 Plan Cache 缓存的执行计划总数。

- Distsql
- Distsql Duration:Distsql 处理的时长
Expand Down
Binary file added media/planCache-memoryUsage-planNum-panels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions sql-prepared-plan-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,19 @@ MySQL [test]> select @@last_plan_from_cache;

## Prepared Plan Cache 的内存管理

使用 Prepared Plan Cache 会有一定的内存开销,在内部测试中,平均每个缓存计划会消耗 100 KiB 内存,且目前 Plan Cache 是 `SESSION` 级别的,因此总内存消耗大致为 `SESSION 个数 * SESSION 平均缓存计划个数 * 100KiB`
使用 Prepared Plan Cache 会有一定的内存开销,可以通过 Grafana 中的 [`Plan Cache Memory Usage`](/grafana-tidb-dashboard.md)查看每台 TiDB 实例上所有 `SESSION` 所缓存的计划占用的总内存
fzzf678 marked this conversation as resolved.
Show resolved Hide resolved

比如目前 TiDB 实例的 `SESSION` 并发数是 50,平均每个 `SESSION` 大致缓存 100 个计划,则总内存开销为 `50 * 100 * 100KiB` 约等于 `512MB`。
> **注意:**
>
> 考虑到 Golang 的内存回收机制以及部分未统计的内存结构,Grafana 中的展示的内存与实际的堆内存使用量并不相等。经过实验验证约存在 X0% 的误差。
fzzf678 marked this conversation as resolved.
Show resolved Hide resolved

对于每台 TiDB 实例上所缓存的执行计划总数量,可以通过 Grafana 中的 [`Plan Cache Plan Num`](/grafana-tidb-dashboard.md)查看。
fzzf678 marked this conversation as resolved.
Show resolved Hide resolved

### 图例
fzzf678 marked this conversation as resolved.
Show resolved Hide resolved

![grafana_panels](/media/planCache-memoryUsage-planNum-panels.png)

目前可以通过变量 `tidb_prepared_plan_cache_size` 来设置每个 `SESSION` 最多缓存的计划数量,针对不同的环境,推荐的设置如下:
目前可以通过变量 `tidb_prepared_plan_cache_size` 来设置每个 `SESSION` 最多缓存的计划数量,针对不同的环境,推荐的设置如下,用户可结合监控调整
Oreoxmt marked this conversation as resolved.
Show resolved Hide resolved

- TiDB Server 实例内存阈值 <= 64 GiB 时,`tidb_prepared_plan_cache_size = 50`
- TiDB Server 实例内存阈值 > 64 GiB 时,`tidb_prepared_plan_cache_size = 100`
Expand Down