MySQL thread_stack连接线程的优化

2023-04-24  本文已影响0人  古飞_数据
mysql> show variables like 'thread%';
+-------------------+---------------------------+
| Variable_name     | Value                     |
+-------------------+---------------------------+
| thread_cache_size | 9                         |
| thread_handling   | one-thread-per-connection |
| thread_stack      | 1048576                   |
+-------------------+---------------------------+
3 rows in set (0.01 sec)

Thread_cache_size:Thread Cache池中应该存放的连接线程数。
Thread_stack:每个连接线程被创建时,MySQL给它分配的内存大小。当MySQL创建一个新的连接线程时,需要给它分配一定大小的内存堆栈空间,以便存放客户端的请求的Query及自身的各种状态和处理信息。

查看系统被连接的次数及当前系统中连接线程的状态值

mysql> show status like 'connections';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Connections   | 12    |
+---------------+-------+
1 row in set (0.00 sec)


mysql> show status like '%thread%';
+------------------------------------------+-------+
| Variable_name                            | Value |
+------------------------------------------+-------+
| Delayed_insert_threads                   | 0     |
| Mysqlx_worker_threads                    | 2     |
| Mysqlx_worker_threads_active             | 0     |
| Performance_schema_thread_classes_lost   | 0     |
| Performance_schema_thread_instances_lost | 0     |
| Slow_launch_threads                      | 0     |
| Threads_cached                           | 0     |
| Threads_connected                        | 1     |
| Threads_created                          | 1     |
| Threads_running                          | 2     |
+------------------------------------------+-------+
10 rows in set (0.00 sec)

系统启动到现在共接受到客户端的连接12次,共创建了1个连接线程,当前有2个连接线程处于和客户端连接的状态,只有2个处于 active 状态,即只有2个正在处理客户端提交的请求,。而在Thread Cache池中共缓存了0个连接线程

Thread Cache 命中率:
Thread_Cache_Hit = (Connections - Threads_created) / Connections * 100%;
一般在系统稳定运行一段时间后,Thread Cache命中率应该保持在90%左右才算正常。

实际应用:

针对16G/32G的机器,一般设置 512K

上一篇 下一篇

猜你喜欢

热点阅读