HikariPool-1 - Interrupted during connection acquisition

news/2024/11/4 21:12:33

HikariPool-1 - Interrupted during connection acquisition

  • 问题描述
  • 临时解决办法
  • 根本原因

最近在压测springboot服务的是时候,遇到 HikariPool-1 - Interrupted during connection acquisition,先记录一下临时解决办法,后面有时间在review这个问题。

问题描述

问题日志:

Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: HikariPool-1 - Interrupted during connection acquisition
### The error may exist in URL [jar:file:/data/app.jar!/BOOT-INF/classes!/mapping/SessionDataMapper.xml]
### The error may involve com.geniuworks.bot.mapper.SessionDataMapper.selectById
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: HikariPool-1 - Interrupted during connection acquisition
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)
	at jdk.internal.reflect.GeneratedMethodAccessor121.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
	... 125 more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: HikariPool-1 - Interrupted during connection acquisition
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
	at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80)
	at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
	at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
	at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.prepareStatement(MybatisSimpleExecutor.java:93)
	at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:66)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:143)
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
	at jdk.proxy3/jdk.proxy3.$Proxy354.query(Unknown Source)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
	... 131 more
Caused by: java.sql.SQLException: HikariPool-1 - Interrupted during connection acquisition
	at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:201)
	at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:162)
	at com.zaxxer.hikari.HikariDataSource.getConnection$original$ll24d7XA(HikariDataSource.java:128)
	at com.zaxxer.hikari.HikariDataSource.getConnection$original$ll24d7XA$accessor$Ht7KSzci(HikariDataSource.java)
	at com.zaxxer.hikari.HikariDataSource$auxiliary$lqHwejmZ.call(Unknown Source)
	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:86)
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java)
	at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
	... 143 more
Caused by: java.lang.InterruptedException
	at java.base/java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:940)
	at com.zaxxer.hikari.util.ConcurrentBag.borrow(ConcurrentBag.java:151)
	at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:180)
	... 152 more

问题日志截图:

在这里插入图片描述

日志给出的原因:
HikariPool-1 - Interrupted during connection acquisition

jdbc的一个中间组件链接的时候被强制中断了。

导致压测百分之99.9的请求都失败了。

在这里插入图片描述

临时解决办法

去掉了下面的线程池配置,配置如下:


/**
 * @Author dingws
 * @PackageName geniubot_developer_service
 * @Package com.geniuworks.bot.config
 * @Date 2022/3/16 4:35 下午
 * @Version 1.0
 */
@Configuration
@Slf4j
public class ThreadPoolConfig implements AsyncConfigurer {

    private static final int cpuNum = Runtime.getRuntime().availableProcessors();

    @Override
    @Bean(name = "threadPoolTaskExecutor")
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        // 最小线程数(核心线程数)
        taskExecutor.setCorePoolSize(cpuNum + 1);
        // 最大线程数
        taskExecutor.setMaxPoolSize(cpuNum * 2);
        // 等待队列(队列最大长度)
        taskExecutor.setQueueCapacity(1000);
        // 等待时间
        taskExecutor.setAwaitTerminationSeconds(300);
        // 线程池维护线程所允许的空闲时间 ,单位s
        taskExecutor.setKeepAliveSeconds(300);
        // 线程池名称前缀
        taskExecutor.setThreadNamePrefix("thread-pool-");
        // 线程池对拒绝任务(无线程可用)的处理策略
        taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());

        taskExecutor.initialize();
        log.info("线程池初始化完成...");
        return taskExecutor;
    }


    /**
     * 异步异常处理
     *
     * @return
     */
    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return new SpringAsyncExceptionHandler();
    }

    class SpringAsyncExceptionHandler implements AsyncUncaughtExceptionHandler {
        @Override
        public void handleUncaughtException(Throwable throwable, Method method, Object... obj) {
            log.error("Exception occurs in async method", throwable.getMessage());
        }
    }
}

通过这个方法,可以使压测正常进行,且能预期的1000QPS。

在这里插入图片描述

根本原因

目前只能大概推测,大量并发请求过来后,导致线程并发数量增加,但是因为cpu是一定的,会存在少数线程得不到响应。在超过一定时长后,被HikariPool组件认为是僵死线程,强制清理退出导致请求失败。

但具体为什么会产生这种原因,个人还是有点困惑,还需要进一步研究,最近手头工作比较忙,先记录一下,等闲的时候再review这个问题。


http://www.niftyadmin.cn/n/3656067.html

相关文章

GIS自主创新十年路(三): 超图成立

GIS自主创新十年路(三) 超图成立转载自:http://songguanfu.blog.ccidnet.com/blog-htm-do-showone-uid-33694-type-blog-itemid-187064.html作者:宋关福原文发表时间:2007年9月18日完成香港综合地理信息系统后不久,科学院为推动地…

postman黑屏问题 mac电脑

文章目录方法一、设置全局变量方法二、卸载重装,清除用户数据最近运气确实不咋地,水逆的不行,postman用的好好的,然后突然打不开了,打开加载一会就是黑屏,然后也关不了,只能通过任务管理器kill掉…

kafka大量堆积故障复盘(生产环境)

kafka大量消息堆积故障复盘一、前言二、过程复盘三、总结1、产生原因2、解决方案2.1、优先处理堆积数据,恢复生产环境2.2、处理堆积数据一、前言 这个事是上个老东家遇到的,我是一个旁观者的角度目睹整个故障的产生和修复,过后也未进行总结复…

GIS自主创新十年路(一):缘起ActiveMap

GIS自主创新十年路(一) :缘起ActiveMap转载自:http://songguanfu.blog.ccidnet.com/blog.php?doshowone&itemid187062&typblog作者:宋关福原文发表时间:2007年9月18日从 最初默默无闻的课题组,到今天在GIS自主…

kafka重复消费(总结)

kafka重复消费(总结)根本原因解决方法关键参数配置根本原因 已经消费的数据,但是offset没有成功提交 具体情况: 消费者宕机、重启,导致消息已经消费但是未提交offset。消费者处理比较耗时,一次poll的数据…

GIS自主创新十年路(二) :牛刀小试

GIS自主创新十年路(二) 牛刀小试转载自:http://songguanfu.blog.ccidnet.com/blog-htm-do-showone-uid-33694-type-blog-itemid-187063.html作者:宋关福原文发表时间:2007年9月18日推荐ActiveMap并没有被立即派上用场。当时我们正在给解放军驻…

qtextcodec file not find 问题解决

项目文件.pro中添加 QT core5compat头文件中添加 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)#include <QtCore/QTextCodec> #else#include <QtCore5Compat/QTextCodec> #endif