GBase 8a空闲超时sleep优化配置方法

本文涉及的产品
RDS AI 助手,专业版
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
简介: GBase 8a空闲超时sleep优化配置方法

GBase 8a数据库集群,当外部连接长时间处于空闲状态(Sleep), 为了减少资源浪费,提供了Wait_timeout参数,Sleep超过该参数的连接会被自动kill掉。

控制参数
Wait_timeout,interactive_timeout

参数默认值
1000000秒。

gbase> show variables like 'wait_timeout';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| wait_timeout | 1000000 |
+---------------+---------+
1 row in set (Elapsed: 00:00:00.00)

gbase> show variables like 'interactive_timeout';
+---------------------+---------+
| Variable_name | Value |
+---------------------+---------+
| interactive_timeout | 1000000 |
+---------------------+---------+
1 row in set (Elapsed: 00:00:00.00)
参数使用样例
除了修改配置文件,重启集群外,还可以用过set方式进行动态设置。

Session级别
建议用wait_timeout即可

如下修改参数为2秒,稍等再执行SQL,可以发现其ID已经变化,从226变成了230,期间有重新连接的信息。

gbase> show processlist;
+-----+-----------------+---------------------+-------+---------+--------+---------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+-----------------+---------------------+-------+---------+--------+---------------------------+------------------+
| 1 | event_scheduler | localhost | NULL | Daemon | 972348 | Waiting for cluster mutex | NULL |
| 3 | gbase | 192.168.6.138:45070 | gbase | Sleep | 226 | | NULL |
| 52 | gbase | 192.168.6.138:45072 | gbase | Sleep | 1101 | | NULL |
| 115 | root | localhost | NULL | Sleep | 369086 | | NULL |
| 116 | root | localhost | test | Sleep | 369005 | | NULL |
| 223 | gbase | 192.168.6.139:37612 | gbase | Sleep | 226 | | NULL |
| 226 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+-----+-----------------+---------------------+-------+---------+--------+---------------------------+------------------+
7 rows in set (Elapsed: 00:00:00.00)

gbase> show variables like 'wait_timeout';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| wait_timeout | 1000000 |
+---------------+---------+
1 row in set (Elapsed: 00:00:00.00)

gbase> set wait_timeout=2;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)

gbase> show variables like 'wait_timeout';
ERROR 2006 (HY000): GBase server has gone away
No connection. Trying to reconnect...
Connection id: 230
Current database: NONE

+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| wait_timeout | 1000000 |
+---------------+---------+
1 row in set (Elapsed: 00:00:00.00)

gbase> show processlist;
+-----+-----------------+---------------------+-------+---------+--------+---------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+-----------------+---------------------+-------+---------+--------+---------------------------+------------------+
| 1 | event_scheduler | localhost | NULL | Daemon | 972447 | Waiting for cluster mutex | NULL |
| 3 | gbase | 192.168.6.138:45070 | gbase | Sleep | 325 | | NULL |
| 52 | gbase | 192.168.6.138:45072 | gbase | Sleep | 1200 | | NULL |
| 115 | root | localhost | NULL | Sleep | 369185 | | NULL |
| 116 | root | localhost | test | Sleep | 369104 | | NULL |
| 223 | gbase | 192.168.6.139:37612 | gbase | Sleep | 325 | | NULL |
| 230 | root | localhost | NULL | Query | 0 | NULL | show processlist |
+-----+-----------------+---------------------+-------+---------+--------+---------------------------+------------------+
全局参数global
需要设置另一个interactive_timeout,否则下次登录时,参数不生效。

gbase> set global wait_timeout=30;
Query OK, 0 rows affected (Elapsed: 00:00:00.25)

gbase> show variables like '%timeout%';
+------------------------------------+---------+
| Variable_name | Value |
+------------------------------------+---------+
| _gbase_crash_dump_timeout | 60 |
| _gbase_net_alive_timeout | 92 |
| connect_timeout | 1000000 |
| delayed_insert_timeout | 300 |
| gbase_export_write_timeout | 300 |
| gbase_hdfs_client_timeout | 600 |
| gbase_loader_read_timeout | 300 |
| gcluster_async_connect_timeout | 120 |
| gcluster_connect_net_read_timeout | 1000000 |
| gcluster_connect_net_write_timeout | 1000000 |
| gcluster_lock_timeout | 0 |
| gcluster_send_client_data_timeout | 30 |
| gcluster_task_status_poll_timeout | 6000 |
| gcluster_wait_query_cancel_timeout | 200 |
| interactive_timeout | 1000000 |
| net_read_timeout | 1000000 |
| net_write_timeout | 1000000 |
| node_peer_connect_timeout | 5 |
| node_peer_read_timeout | 0 |
| node_peer_write_timeout | 0 |
| slave_net_timeout | 3600 |
| table_lock_wait_timeout | 50 |
| wait_timeout | 1000000 |
+------------------------------------+---------+
23 rows in set (Elapsed: 00:00:00.00)

gbase>
gbase> ^CAborted
[gbase@gbase ~]$ gccli -uroot

GBase client 8.6.2.43-R33.129391.133425. Copyright (c) 2004-2024, GBase. All Rights Reserved.

gbase> show variables like '%timeout%';
+------------------------------------+---------+
| Variable_name | Value |
+------------------------------------+---------+
| _gbase_crash_dump_timeout | 60 |
| _gbase_net_alive_timeout | 92 |
| connect_timeout | 1000000 |
| delayed_insert_timeout | 300 |
| gbase_export_write_timeout | 300 |
| gbase_hdfs_client_timeout | 600 |
| gbase_loader_read_timeout | 300 |
| gcluster_async_connect_timeout | 120 |
| gcluster_connect_net_read_timeout | 1000000 |
| gcluster_connect_net_write_timeout | 1000000 |
| gcluster_lock_timeout | 0 |
| gcluster_send_client_data_timeout | 30 |
| gcluster_task_status_poll_timeout | 6000 |
| gcluster_wait_query_cancel_timeout | 200 |
| interactive_timeout | 1000000 |
| net_read_timeout | 1000000 |
| net_write_timeout | 1000000 |
| node_peer_connect_timeout | 5 |
| node_peer_read_timeout | 0 |
| node_peer_write_timeout | 0 |
| slave_net_timeout | 3600 |
| table_lock_wait_timeout | 50 |
| wait_timeout | 1000000 |
+------------------------------------+---------+
23 rows in set (Elapsed: 00:00:00.00)

gbase> set global interactive_timeout=60;
Query OK, 0 rows affected (Elapsed: 00:00:00.10)

gbase> ^CAborted
[gbase@gbase ~]$ gccli -uroot

GBase client 8.6.2.43-R33.129391.133425. Copyright (c) 2004-2024, GBase. All Rights Reserved.

gbase> show variables like '%timeout%';
+------------------------------------+---------+
| Variable_name | Value |
+------------------------------------+---------+
| _gbase_crash_dump_timeout | 60 |
| _gbase_net_alive_timeout | 92 |
| connect_timeout | 1000000 |
| delayed_insert_timeout | 300 |
| gbase_export_write_timeout | 300 |
| gbase_hdfs_client_timeout | 600 |
| gbase_loader_read_timeout | 300 |
| gcluster_async_connect_timeout | 120 |
| gcluster_connect_net_read_timeout | 1000000 |
| gcluster_connect_net_write_timeout | 1000000 |
| gcluster_lock_timeout | 0 |
| gcluster_send_client_data_timeout | 30 |
| gcluster_task_status_poll_timeout | 6000 |
| gcluster_wait_query_cancel_timeout | 200 |
| interactive_timeout | 30 |
| net_read_timeout | 1000000 |
| net_write_timeout | 1000000 |
| node_peer_connect_timeout | 5 |
| node_peer_read_timeout | 0 |
| node_peer_write_timeout | 0 |
| slave_net_timeout | 3600 |
| table_lock_wait_timeout | 50 |
| wait_timeout | 30 |
+------------------------------------+---------+
23 rows in set (Elapsed: 00:00:00.00)
解决方案
1、调高参数
默认值已经是100万秒,不建议一个空闲连接10多天无任何任务,建议根据实际的业务场景进行调整。

2、连接检测
一般是连接池的功能,在调用方获取连接时,先检测连接是否可用,常见是发送一个select 1到数据库,如果正常返回则表示连接当前可用,返回调用方;如果报错,则连接不可用,则寻找下一个可用连接或新建一个连接,再次检测成功后返回。

相关文章
|
Linux Docker Python
Alpine Linux详解
Alpine以其小巧、简单在docker容器中得到了广泛的应用。但是Alpine Linux使用了musl,可能和其他Linux发行版使用的glibc实现会有些不同。这里主要介绍了它的基础用法,但是足以满足日常运维需要。
16152 1
|
数据采集 SQL Oracle
从ORACLE源进行批量数据迁移到GBase8a参考示例
从ORACLE源进行批量数据迁移到GBase8a参考示例
从ORACLE源进行批量数据迁移到GBase8a参考示例
|
9月前
|
SQL JSON Java
告别拼接噩梦:Java文本块让多行字符串更优雅
告别拼接噩梦:Java文本块让多行字符串更优雅
760 82
|
存储 SQL 安全
GBase 8a 忘记密码怎么办
GBase 8a 忘记密码怎么办
|
Ubuntu Linux Apache
在Linux中,如何使用logrotate命令管理日志文件?
在Linux中,如何使用logrotate命令管理日志文件?
|
IDE PHP 开发工具
【PHP开发专栏】Xdebug在PHP调试中的应用
Xdebug 是一个功能强大的 PHP 扩展,提供调试、代码分析和性能分析等功能。本文介绍了 Xdebug 的基本概念、安装配置方法及在 PHP 调试中的应用技巧,包括断点调试、堆栈跟踪、远程调试和性能分析等。通过合理使用 Xdebug,可以显著提高调试效率和代码质量。
347 3
|
数据挖掘 BI 定位技术
南大通用GBase 8s 高级分组查询 —— GROUP BY ROLLUP介绍
本文详细介绍了GBase 8s数据库中GROUP BY ROLLUP的高级分组查询功能,涵盖基本概念、语法结构、应用示例及使用场景。ROLLUP支持多维度数据汇总,适用于销售分析、财务报表和用户统计等领域,提升数据汇总的灵活性与便捷性。
|
人工智能 数据挖掘 决策智能
跟着我的步骤,轻松打造出 AI 智能体
跟着我的步骤,轻松打造出 AI 智能体
741 3
跟着我的步骤,轻松打造出 AI 智能体
|
关系型数据库 MySQL 大数据
教你使用Python玩转MySQL数据库,大数据导入不再是难题!
教你使用Python玩转MySQL数据库,大数据导入不再是难题!
405 1
|
NoSQL 算法 Java
使用 Spring Boot 实现限流功能:从理论到实践
【6月更文挑战第18天】在微服务和高并发系统中,限流(Rate Limiting)是一种非常重要的技术手段,用于保护系统免受过载,确保服务的稳定性。限流可以控制请求的速率,防止单个客户端或恶意用户消耗过多的资源,从而影响其他用户。
1907 5