小言_互联网的博客

记一次CPU飙升的问题排查

295人阅读  评论(0)

1.背景

   通过公司监控工具监控,发现公司某个应用cpu利用率达到120%,也就是说这个应用自己单独占用一个cpu使用,为何占用这么高?让我们一起排查一下

2.开始排查

  (1) 第一步获取cpu过高应用的进程信息 (top 命令监控)

     

  (2)通过进程获取占用cpu过高的线程(Top -H -p <pid>

    

  (3)通过jstack命令导出线程的堆栈信息


  
  1. "http-bio-7051-exec-28" #33168 daemon prio=5 os_prio=0 tid=0x00007fe343f77000 nid=0xaa1 runnable [0x00007fe329287000]
  2. java.lang.Thread.State: RUNNABLE
  3. at java.lang.StringBuilder.append(StringBuilder.java:214)
  4. at sun.util.calendar.CalendarUtils.sprintf0d(CalendarUtils.java:171)
  5. at java.util.Date.toString(Date.java:1040)
  6. at java.lang.String.valueOf(String.java:2994)
  7. at java.lang.StringBuilder.append(StringBuilder.java:131)
  8. at com.jiuyescm.oms.wm.odo.action.service.impl.CommonOmsOrderSendAction.buildAppointKey(CommonOmsOrderSendAction.java:72)
  9. at com.jiuyescm.oms.wm.odo.controller.OmsDo2BController.queryStorage(OmsDo2BController.java:1007)
  10. at sun.reflect.GeneratedMethodAccessor2011.invoke(Unknown Source)
  11. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  12. at java.lang.reflect.Method.invoke(Method.java:498)
  13. at com.bstek.dorado.data.method.MethodAutoMatchingUtils.invokeMethod(MethodAutoMatchingUtils.java:602)
  14. at com.bstek.dorado.data.method.MethodAutoMatchingUtils.invokeMethod(MethodAutoMatchingUtils.java:695)
  15. at com.bstek.dorado.data.provider.manager.DataProviderInterceptorInvoker.invokeInterceptorByParamType(DataProviderInterceptorInvoker.java:542)
  16. at com.bstek.dorado.data.provider.manager.DataProviderInterceptorInvoker.invoke(DataProviderInterceptorInvoker.java:157)
  17. at com.bstek.dorado.util.proxy.ChainedMethodInvocation.proceed(ChainedMethodInvocation.java:73)
  18. at com.bstek.dorado.data.provider.DataProviderGetResultMethodInterceptor.invokeGetResult(DataProviderGetResultMethodInterceptor.java:29)
  19. at com.bstek.dorado.data.provider.AbstractDataProviderGetResultMethodInterceptor.invoke(AbstractDataProviderGetResultMethodInterceptor.java:55)
  20. at com.bstek.dorado.util.proxy.MethodInterceptorDispatcher.invoke(MethodInterceptorDispatcher.java:241)
  21. at com.bstek.dorado.data.provider.DirectDataProvider_$$_jvst349_17.getResult(DirectDataProvider_$$_jvst349_17.java)
  22. at com.bstek.dorado.view.service.LoadDataServiceProcessor.doExecute(LoadDataServiceProcessor.java:258)
  23. at com.bstek.dorado.view.service.DataServiceProcessorSupport.execute(DataServiceProcessorSupport.java:133)
  24. at com.bstek.dorado.view.resolver.ViewServiceInvoker.invoke(ViewServiceInvoker.java:32)
  25. at com.bstek.dorado.view.resolver.ViewServiceInvoker_$$_jvst349_16._d5invoke(ViewServiceInvoker_$$_jvst349_16.java)
  26. at sun.reflect.GeneratedMethodAccessor216.invoke(Unknown Source)
  27. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  28. at java.lang.reflect.Method.invoke(Method.java:498)
  29. at com.bstek.dorado.util.proxy.MethodInterceptorDispatcher$FinalJavassistMethodInterceptor.invoke(MethodInterceptorDispatcher.java:96)
  30. at com.bstek.dorado.util.proxy.ChainedMethodInvocation.proceed(ChainedMethodInvocation.java:73)
  31. at com.bstek.dorado.util.proxy.MethodInterceptorDispatcher$FinalAopallianceMethodInterceptor.invoke(MethodInterceptorDispatcher.java:67)
  32. at com.bstek.dorado.util.proxy.ChainedMethodInvocation.proceed(ChainedMethodInvocation.java:73)
  33. at com.jiuyescm.cfm.dorado.interceptor.SessionValidationRemoteServiceMethodInterceptor.invoke(SessionValidationRemoteServiceMethodInterceptor.java:33)
  34. at com.bstek.dorado.view.service.AbstractRemoteServiceMethodInterceptor.invoke(AbstractRemoteServiceMethodInterceptor.java:30)
  35. at com.bstek.dorado.util.proxy.ChainedMethodInvocation.proceed(ChainedMethodInvocation.java:73)
  36. at com.bstek.bdf2.core.exception.interceptor.AjaxMethodInterceptor.invoke(AjaxMethodInterceptor.java:26)
  37. at com.bstek.dorado.util.proxy.MethodInterceptorDispatcher.invoke(MethodInterceptorDispatcher.java:170)
  38. at com.bstek.dorado.util.proxy.MethodInterceptorDispatcher.invoke(MethodInterceptorDispatcher.java:241)
  39. at com.bstek.dorado.view.resolver.ViewServiceInvoker_$$_jvst349_16.invoke(ViewServiceInvoker_$$_jvst349_16.java)
  40. at com.bstek.dorado.view.resolver.ViewServiceResolver.processTask(ViewServiceResolver.java:154)
  41. at com.bstek.dorado.view.resolver.ViewServiceResolver.execute(ViewServiceResolver.java:244)
  42. at com.bstek.dorado.web.resolver.AbstractTextualResolver.doHandleRequest(AbstractTextualResolver.java:128)
  43. at com.bstek.dorado.web.resolver.WebContextSupportedController.handleRequestInternal(WebContextSupportedController.java:70)
  44. at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:154)
  45. at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
  46. at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
  47. at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
  48. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
  49. at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)
  50. at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  51. at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
  52. at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  53. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  54. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  55. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  56. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  57. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  58. at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
  59. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  60. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  61. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  62. at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:108)
  63. at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
  64. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  65. at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
  66. at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
  67. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  68. at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
  69. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  70. at com.bstek.bdf2.core.security.filter.ControllerFilter.doFilter(ControllerFilter.java:64)
  71. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  72. at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
  73. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  74. at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
  75. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  76. at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
  77. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  78. at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
  79. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  80. at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
  81. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  82. at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
  83. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  84. at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
  85. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  86. at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
  87. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  88. at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:100)
  89. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  90. at com.bstek.bdf2.core.security.filter.PreAuthenticatedProcessingFilter.doFilter(PreAuthenticatedProcessingFilter.java:41)
  91. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  92. at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
  93. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  94. at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
  95. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  96. at com.bstek.bdf2.core.security.filter.ContextFilter.doFilter(ContextFilter.java:36)
  97. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  98. at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
  99. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  100. at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
  101. at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
  102. at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
  103. at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
  104. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  105. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  106. at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
  107. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
  108. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  109. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  110. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
  111. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
  112. at com.r.tomcat.session.management.RequestSessionHandlerValve.invoke(RequestSessionHandlerValve.java:30)
  113. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
  114. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  115. at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
  116. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  117. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
  118. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
  119. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
  120. at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
  121. - locked <0x0000000724439528> (a org.apache.tomcat.util.net.SocketWrapper)
  122. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  123. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  124. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  125. at java.lang.Thread.run(Thread.java:748)

 从以上日志中找出最魁祸首


  
  1. at java .lang .StringBuilder .append( StringBuilder .java :214)
  2. at sun .util .calendar .CalendarUtils .sprintf0d( CalendarUtils .java :171)
  3. at java .util .Date .toString( Date .java :1040)
  4. at java .lang .String .valueOf( String .java :2994)
  5. at java .lang .StringBuilder .append( StringBuilder .java :131)
  6. at com .jiuyescm .oms .wm .odo .action .service .impl .CommonOmsOrderSendAction .buildAppointKey( CommonOmsOrderSendAction .java :72)
  7. at com .jiuyescm .oms .wm .odo .controller .OmsDo2BController .queryStorage( OmsDo2BController .java :1007)

(4)结合代码寻找真相

  

 

   

   3.总结

      跟我们的堆栈完全可以对应的上,性能耗费在循环调用字符串拼接这里。在这里要说一下字符串使用操作符"+"拼接的问题,如果你用”+”来连接固定长度的字符串,在性能上会有问题,但是如果你是在循环中来”+”多个串的话,性能将指数倍的下降。假设有一个字符串,我们将对这个字符串做大量循环拼接操作,使用”+”的话将得到最低的性能。网上有很多对比的文章随便一找一大把,如果不信自己可以写个demo调用1000次然后看自己cpu的情况。


转载:https://blog.csdn.net/aazhzhu/article/details/115234576
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场