问题及其罪魁祸首
WEB服务器: apache-tomcat-8.0.33
JDK: jdk1.8.0_66
操作系统: Linux SHB-L0064049 2.6.32-642.6.2.el6.x86_6

运维反馈CPU抖动异常,如下。
CPU状态

CPU时不时的会从0%抖动到50%,定位到时tomcat的热部署导致的问题。最终通过显式的加上reloadable=“false” 的配置解决了该问题。

注: 这里有一个坑,tomcat 的热部署默认是关闭的,具体请看[(文档)[http://tomcat.apache.org/tomcat-8.0-doc/config/context.html]] 中的reloadable说明, 然而我的服务器并没有显示配置reloadable 为true,tomcat却还是执行了对应的热部署相关的行为!

下面说说定位流程。

问题定位
查看服务进程的ID
ps aux | grep webAppName
定位占用CPU高的线程
top -H -p pid
查看线程堆栈
[root@SZC-L0095267 serviceop]# /wls/apache/tomcat/jdk1.8.0_66/bin/jstack -F 52754 |grep 53069 -A 20
Thread 53069: (state = IN_JAVA)
java.util.jar.JarFile.getJarEntry(java.lang.String) @bci=2, line=223 (Compiled frame; information may be imprecise)
org.apache.catalina.webresources.JarResourceSet.getArchiveEntry(java.lang.String) @bci=9, line=120 (Compiled frame)
org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(java.lang.String) @bci=279, line=270 (Compiled frame)
org.apache.catalina.webresources.StandardRoot.getResourceInternal(java.lang.String, boolean) @bci=103, line=281 (Compiled frame)
org.apache.catalina.webresources.Cache.getResource(java.lang.String, boolean) @bci=14, line=63 (Compiled frame)
org.apache.catalina.webresources.StandardRoot.getResource(java.lang.String, boolean, boolean) @bci=23, line=216 (Compiled frame)
org.apache.catalina.webresources.StandardRoot.getClassLoaderResource(java.lang.String) @bci=22, line=225 (Compiled frame)
org.apache.catalina.loader.WebappClassLoaderBase.modified() @bci=81, line=706 (Compiled frame)
org.apache.catalina.loader.WebappLoader.modified() @bci=11, line=342 (Compiled frame)
org.apache.catalina.loader.WebappLoader.backgroundProcess() @bci=8, line=286 (Compiled frame)
org.apache.catalina.core.StandardContext.backgroundProcess() @bci=21, line=5608 (Compiled frame)
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(org.apache.catalina.Container) @bci=55, line=1377 (Compiled frame)
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(org.apache.catalina.Container) @bci=94, line=1381 (Compiled frame)
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(org.apache.catalina.Container) @bci=94, line=1381 (Compiled frame)
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run() @bci=68, line=1349 (Interpreted frame)
java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)
查看源码
调用流程: WebappLoader.backgroundProcess() -> WebappLoader.modified()
从线程堆栈可以看出是tomcat相关的线程导致的CPU异常,我们从源码入手看是什么问题。以下是
WebappLoader.java 的相关关键代码,从代码和打印的线程堆栈中可以看出,线上的生产服务器其实是走到了
reloadable为true的流程中去了的,说明tomcat开启了热部署。
/**

  • The reloadable flag for this Loader.
    */
    private boolean reloadable = false;
    /**

    • Execute a periodic task, such as reloading, etc. This method will be
    • invoked inside the classloading context of this container. Unexpected
    • throwables will be caught and logged.br/>*/
      @Override
      public void backgroundProcess() {
      if (reloadable && modified()) {
      try {
      Thread.currentThread().setContextClassLoader
      (WebappLoader.class.getClassLoader());
      if (context != null) {
      context.reload();
      }
      } finally {
      if (context != null && context.getLoader() != null) {
      Thread.currentThread().setContextClassLoader
      (context.getLoader().getClassLoader());
      }
      }
      }
      }
      /**
  • Has the internal repository associated with this Loader been modified,
  • such that the loaded classes should be reloaded?br/>*/
    @Override
    public boolean modified() {
    return classLoader != null ? classLoader.modified() : false ;
    }
    查看tomcat的server.xml配置,确认是否有开启reloadable
    <!-- 省略部分 -->
    <Host name="localhost" appBase="app base dir" unpackWARs="true" autoDeploy="false">
    <Context path="/f5monweb" docBase="/wls/apache/monitor_tm/f5monweb.war" unpackWAR="false"/>
    <Context path="/perfmon" docBase="/wls/apache/monitor_tm/perfmon.war" unpackWAR="false"/>
    <!-- 省略部分 -->
    可以看出,我们的应用并没有显式的配置reloadable="true",即没有开启热部署, tomcat中关于reloadable的说明如下:

reloadable
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and
automatically reload the web application if a change is detected. This feature is very useful during application
development, but it requires significant runtime overhead and is not recommended for use on deployed production
applications. That’s why the default setting for this attribute is false. You can use the Manager web application,
however, to trigger reloads of deployed applications on demand.

这真是tomcat的一个大坑,线程定位就是走了热部署相关的流程无误了。

解决问题
最终通过显式的添加reloadable="false"解决问题,调整后server.xml配置如下:
<!-- 省略部分 -->
<Host name="localhost" appBase="app base dir" unpackWARs="true" autoDeploy="false">
<Context path="/myWebappName" docBase="myWebappName.war" reloadable="false"/>
<Context path="/f5monweb" docBase="/wls/apache/monitor_tm/f5monweb.war" unpackWAR="false"/>
<Context path="/perfmon" docBase="/wls/apache/monitor_tm/perfmon.war" unpackWAR="false"/>
<!-- 省略部分 -->

转自 http://blog.vioao.me/%E5%AE%9A%E4%BD%8DCPU%E5%BC%82%E5%B8%B8%E6%8A%96%E5%8A%A8-tomcat%E7%83%AD%E9%83%A8%E7%BD%B2%E7%9A%84%E5%9D%91/

我们线上一个系统日访问量大概1000W,3台机器,tomcat容器运行十几天后CPU占用就会比较高

通过top -hp 和jstack查到是一个跟热部署的线程占用CPU比较高 大概10~20%
关闭热部署后目前未重现原现象

转载于:https://blog.51cto.com/flybluesky/2377318

定位CPU异常抖动---tomcat热部署的坑[转载]相关推荐

  1. Tomcat热部署方法(3种)

    Tomcat热部署方法(3种) 2012-02-06 11:32:56|  分类: tomcat |  标签:tomcat  热部署  热启动  context  server   |字号 订阅 热部 ...

  2. IDEA第二章----配置git、tomcat(热部署)、database,让你的项目跑起来

    第一节:下载git客户端,整合idea 由于博主公司用的git版本管理,所以本系列都是基于git版本工具的,当然SVN与git配置类似.git同样支持安装版和解压版,支持各种操作系统,我这里下载的是W ...

  3. IDEA9+Tomcat热部署配置二法

    IDEA9+Tomcat热部署配置 idea9的web开发配置方式与之前的版本发生了大的变化,idea其实也可以像MyEclipse一样自动热部署,不过配置稍微麻烦了一些. 环境: Idea9.03 ...

  4. tomcat热部署 更改类文件不需要重起

    tomcat热部署 更改类文件不需要重起 (2011-04-18 11:53:29) 转载▼ 标签: it 分类: server tomcat上的部署问题,有时候也是个麻烦的问题,要是不采用热部署,我 ...

  5. Jrebel实现tomcat热部署,遇到的问题以及解决办法,详解

    Jrebel实现tomcat热部署,遇到的问题以及解决办法,详解 参考文章: (1)Jrebel实现tomcat热部署,遇到的问题以及解决办法,详解 (2)https://www.cnblogs.co ...

  6. tomcat 热部署

    场景介绍: 频繁更新项目代码但不能重启服务的时候,就可以使用到 tomcat热部署. 步骤: 1.配置好JDK和tomcat的环境变量 2.将 war 包解压后的项目文件放在某个位置,比如:D\pro ...

  7. tomcat java 热部署,tomcat热部署

    Tomcat 热部署:webapps下的项目正在运行,直接把开发的新版本发布到正在运行的Tomcat下(不能关闭Tomcat再发布新版本)​ 开发者本地将代码通过Git push到服务器端,服务器自动 ...

  8. idea tomcat热部署_IDEA设置热部署

    之前用Eclipse的时候,可以下载插件jrebel进行热部署,但是换成idea后,怎么部署都不行,只能用idea自带的热部署了. idea自带的热部署,只能对方法内进行的更改进行重新加载,如果是新增 ...

  9. tomcat 热部署、热加载 精析

    1.前言 找了很多篇文章,没有一篇文章讲的清晰.明了,很多人只是会用,但不是能真正说明白,这年头找个懂理论的,真难! 2.热部署 原定义:tomcat处于运行状态时,能够监测webapps下的文件,如 ...

  10. IDEA tomcat热部署

    文章目录 一.通过IDEA配置热部署 二.在pom.xml添加相应依赖 一.通过IDEA配置热部署 ①找到在idea tomcat 中server的配置里的on frame deactivation ...

最新文章

  1. 【Network Security!】IP地址详解(看不懂你来打我)
  2. bzoj2427: [HAOI2010]软件安装
  3. php--点赞功能的实现
  4. 《嵌入式Linux软硬件开发详解——基于S5PV210处理器》——2.2 DDR2 SDRAM芯片
  5. tomcat提高图片服务器性能,Tomcat性能调优(windows)
  6. Bootstrap组件_导航
  7. double 格式化
  8. html超过高度的没显示,CSS 设置的高度超出屏幕高度为什么没出现滚动条?
  9. 《Java基础学习笔记》JAVA面向对象之封装
  10. 卧槽!二维码要被扫完了吗?疫情期间竟用掉了1400亿个!
  11. cesium加载shp格式数据
  12. 安卓音效AudioEffect源码剖析2——音效库接口
  13. js页面跳转并传递参数
  14. 数字音频水印技术的matlab代码,数字水印技术dct算法matlab源代码
  15. 时间管理表 - 《周计划表》
  16. 电视收视率评估工具推荐
  17. 数组数据通过sql语句转为数据库表衔接到from或join后进行直接或关联查询
  18. 2.5.3 文法二义性的消除
  19. 老旧的API,你应该如何处理?
  20. 中科大王彬计算机学院,中国科学院国家纳米科学中心 贺涛 男 博导

热门文章

  1. TensorFlow学习笔记——图像数据处理
  2. 机器学习入门——图解集成学习(附代码)
  3. 集合阿里云、达摩院、平头哥相关技术的HaaS,官宣出书啦
  4. 系统架构与软件架构是一层含义吗
  5. C语言基础:用快速排序实现输出最大数
  6. pytorch序列化容器
  7. it技术交流平台_IT协会向你招手了,不了解了解?
  8. Ros简单程序编写及使用类Hello World
  9. php nsdata,转换NSArray- JSON- NSData- PHP服务器- JSON表示
  10. java枚举比较_java枚举enum equal与==