排查线上高CPU占用


现象

Error occurred when intercept sql:update `campaign_user_log` set `status`='SENT', `fail_reason`=, `update_timestamp`= 1644562526235 where id in( 2869972 )Error creating bean with name 'sentryTransactionAdvisor' defined in class path resource [io/sentry/spring/tracing/SentryAdviceConfiguration.class]: Unsatisfied dependency expressed through method 'sentryTransactionAdvisor' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sentryTransactionAdvice' defined in class path resource [io/sentry/spring/tracing/SentryAdviceConfiguration.class]: Unsatisfied dependency expressed through method 'sentryTransactionAdvice' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sentryHub' defined in class path resource [io/sentry/spring/boot/SentryAutoConfiguration$HubConfiguration.class]: Unsatisfied dependency expressed through method 'sentryHub' parameter 1; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'sentry-io.sentry.spring.boot.SentryProperties': Could not bind properties to 'SentryProperties' : prefix=sentry, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4604b900 has been closed already

系统频繁异常预警,从日志看服务被重启了。表面上是由健康检测机制导致的,即多次访问健康检查页失败,自动重启应用。

健康检测失败排查

  • JVM正常
  • CPU高占用

CPU高占用排查

top

命令查看系统资源占用情况,不出意外Java进程占用CPU持续90%以上

ps -mp [pid] -o THREAD,tid,time

通过ps命令查看Java进程的线程信息,tid代码线程ID,time代表这个线程的已运行时间

执行结果,直接刷屏,线程信息过多,执行:ps -mp [pid] -o THREAD,tid,time | wc -l,统计线程数量:1万+,创建线程过多

解决问题

OkHttpClient client = new OkHttpClient().newBuilder().build(),调度任务中循环创建了大量的httpClient,线程不能及时回收。改为公共变量,每个调度任务生成一个解决问题。