MySQL/连接池
来自康健生活
< MySQL
连接池
遇到一个问题,使用 think.js 做后端,mysql 做数据库,加载页面的时候,偶尔会发生请求等待的情况,eq。
查看文档,think.js 默认设置连接池数量[1]为 1。重新配置连接池数量为 20。后续跟进看情况是否有改善。
连接池数量
查看最大连接数量。
[jian@kang /home/kangkk]$
show variables like '%max_connection%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 2000 |
+-----------------+-------+
1 row in set (0.01 sec)
查看当前实际连接数量。
[jian@kang /home/kangkk]$
show global status like '%max_used_connections%';
+---------------------------+---------------------+
| Variable_name | Value |
+---------------------------+---------------------+
| Max_used_connections | 89 |
| Max_used_connections_time | 2022-07-22 11:57:30 |
+---------------------------+---------------------+
2 rows in set (0.01 sec)
一般设定实际连接数量为最大连接数量的 85% 为合理值(Max_used_connections / max_connections * 100% ≈ 85%)。
查看当前分配的线程数量。
[jian@kang /home/kangkk]$
show status like '%thread%';
+------------------------------------------+-------+
| Variable_name | Value |
+------------------------------------------+-------+
| Delayed_insert_threads | 0 |
| Performance_schema_thread_classes_lost | 0 |
| Performance_schema_thread_instances_lost | 0 |
| Slow_launch_threads | 0 |
| Threads_cached | 40 |
| Threads_connected | 49 |
| Threads_created | 89 |
| Threads_running | 4 |
+------------------------------------------+-------+
8 rows in set (0.00 sec)
连接数计算
连接数 = ((核心数 * 2) + 有效磁盘数)
- ↑ qitutuan. think.js[OL]. https://thinkjs.org/zh-cn/doc/3.0/relation_model.html#mysql.
No categories