RDS for MySQL 连接相关指标说明

数据库关系型数据库技术服务知识库
前言

在当前 RDS MySQL 控制台上,选择监控告警,引擎监控,连接,我们可以看如下指标: 图片 目前关于连接相关的指标有三个,分别为:

  1. 当前打开的连接数
  2. 已创建的线程数
  3. 运行的线程数

下面会介绍下这几个指标在RDS 中是如何取值的。

当前打开的连接数

当前打开的连接数取自Threads_connected,意为已连接的 thread,官方文档描述如下:The number of currently open connections[1]。

mysql> show global status like 'Threads_connected%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 10    |
+-------------------+-------+
1 row in set (0.00 sec)

控制台显示如下: 图片

已创建的线程数

已创建的线程数指标取自Threads_created,意为建立的 thread 数量,官方文档描述如下:The number of threads created to handle connections[2]。

mysql> show global status like 'Threads_created%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Threads_created | 14    |
+-----------------+-------+
1 row in set (0.00 sec)

控制台显示如下: 图片

运行的线程数

运行的线程数取自Threads_running,意为running状态的 thread 数量,官方文档有如下描述:The number of threads that are not sleeping[3].

mysql> show global status like 'Threads_running%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Threads_running | 2     |
+-----------------+-------+
1 row in set (0.00 sec)
总结

通常来说,关于这参数指标有如下计算公式

  • Threads_created = Threads_cached + Threads_connected
  • Threads_running <= Threads_connected

Threads_cached 用来缓存的 thread,新连接建立时会优先使用cache中的thread。 同时需要注意的是,MySQL 建立新连接非常消耗资源,频繁使用短连接,又没有其他组件实现连接池时,可以适当提高 thread_cache_size,降低新建连接的开销。

参考文档:

[1] https://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html#statvar_Threads_connected [2] https://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html#statvar_Threads_created [3] https://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html#statvar_Threads_running 如果您有其他问题,欢迎您联系火山引擎技术支持服务

31
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论