tomcat服务器cpu占用率居高不下的原因分析及解决

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/abcxbcba/article/details/87193150

偶遇服务器cpu飙升,过段时间后正常,反反复复

尝试通过百度,谷歌等搜索,获取可行的解决方案无果,偶然的机会得知 fastthread 可视化分析工具,问题才能顺利解决。

获取cpu占用高的java进程运行中的堆栈信息

通过top命令查看cpu占用率高的进程,并记录pid;
在这里插入图片描述
分析得到进程9934时不时的就cpu使用了居高不下,最高达到200%,下定决心解决掉;
在高cpu的占用情况下,下载该进程的运行中堆栈信息:jstack -l 9934 >> 9934.txt
压缩日志文件 zip 9934.zip 9934.txt
下载本地分析,通过https://fastthread.io分析日志数据
在这里插入图片描述
重点关注 cpu threads 的日志情况:
在这里插入图片描述
发现该CaoCaoNotifyApiHandler类在150行存在异常情况
打开源码 发现
在这里插入图片描述
罪恶的源头出现了,修改循环休息1秒,而非原有的无限循环,问题解决。

总结:
运行中的定位比较复杂,有时候看着日志也是一头雾水,之前一段时间也是自己看指日志文本不断的分析也没有定位到正真的问题,今天偶然的机会知道了 fastthread 网站,可视化的日志分析工具,使得问题被迅速定位解决 。

展开阅读全文

udP socket CPU居高不下

01-19

[code=c]bool prepareUDP()rnrnint buffsize = 1024*1024;rn unsigned long nFlag = 1;rnrn m_sokVideoSocket = socket(AF_INET, SOCK_DGRAM, 0);rn BOOL fReuse = true;rn if (SOCKET_ERROR == setsockopt(m_sokVideoSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&fReuse, sizeof(BOOL)))rn rn closesocket(m_sokVideoSocket);rn m_sokVideoSocket = INVALID_SOCKET;rn rnrn if (SOCKET_ERROR == setsockopt(m_sokVideoSocket, SOL_SOCKET, SO_RCVBUF, (char*)&buffsize, sizeof(int)))rn rn closesocket(m_sokVideoSocket);rn m_sokVideoSocket = INVALID_SOCKET;rn rn if (SOCKET_ERROR == ioctlsocket(m_sokVideoSocket, FIONBIO, &nFlag))rn rn closesocket(m_sokVideoSocket);rn m_sokVideoSocket = INVALID_SOCKET;rn rnrn sockaddr_in stSokAddr = 0 ;rn int nSokStLen = sizeof(sockaddr);rn //stSokAddr.sin_addr.S_un.S_addr = inet_addr(localIP);rn stSokAddr.sin_addr.S_un.S_addr = INADDR_ANY;rn stSokAddr.sin_port = htons(port);rn stSokAddr.sin_family = AF_INET;rnrn if (SOCKET_ERROR == bind(m_sokVideoSocket, (sockaddr *)&stSokAddr, nSokStLen))rn rn //TRACE("m_sokVideoData bind port %d \n ", port);rn closesocket(m_sokVideoSocket);rn m_sokVideoSocket = INVALID_SOCKET;rn return false;rn rnrn return true;rnrnrnrnstatic int recvData(void* ptr)rnrn rn int nDataLen = 0;rn char* szDataBuf = new char[65536];rn memset(szDataBuf, 0, 65536);rnrn int nSokStLen = sizeof(sockaddr);rnrn fd_set stSocketSet;rn timeval stTimeOut;rn stTimeOut.tv_sec = 3;rn stTimeOut.tv_usec = 0;rn while (player->m_continuRcv)rn rn FD_ZERO(&stSocketSet);rnrn if (m_sokVideoSocket != INVALID_SOCKET)rn rn FD_SET(m_sokVideoSocket, &stSocketSet);rn rn rn //if (select(0, &stSocketSet, NULL, NULL, &stTimeOut) > 0)rn rn // if (FD_ISSET(m_sokVideoSocket, &stSocketSet))rn rn //SOCKADDR_IN remoteAddr;rn // int nAddrLen = sizeof(remoteAddr);rn //nDataLen = recvfrom(m_sokVideoSocket, (char*)szDataBuf, 65536, 0, (SOCKADDR*)&remoteAddr, &nAddrLen); //BUF_SIZE rn nDataLen = recv(m_sokVideoSocket, (char*)szDataBuf, 65536, 0);rn if (nDataLen > 12)rn rn //processUDPDate(szDataBuf, nDataLen);rn rn printf("%d\n",nDataLen);rn rn rn //elsern rn std::this_thread::sleep_for(std::chrono::milliseconds(1));//milliseconds nanosecondsrn rnrn rnreturn 0;rnrnrnint main()rnrn if(prepareUDP)rn rn std::thread t(recvData,nullptr);rn t.detach();rn rnrn[/code]rn尝试了各种,阻塞非阻塞,各种超时尝试,select,recv,sleep,cpu依然居高不下,求哪位大神帮看下 论坛

xfire导致CPU居高不下

07-20

webservcie项目用xifre,不定期出现CPU100%的情况,经过分析是xfire引起的rn[code=java]rn"http-bio-80-exec-8" daemon prio=10 tid=0x00007f84dc001800 nid=0x166d runnable [0x00007f853526f000]rn java.lang.Thread.State: RUNNABLErn at com.sun.xml.stream.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:876)rn at com.sun.xml.stream.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:353)rn at com.sun.xml.stream.XMLReaderImpl.next(XMLReaderImpl.java:557)rn at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:44)rn at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)rn at org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64)rn at org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)rn at org.codehaus.xfire.transport.http.XFireServletController.invoke(XFireServletController.java:304)rn at org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:129)rn at org.codehaus.xfire.transport.http.XFireServlet.doPost(XFireServlet.java:116)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)rn at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)rn at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)rn - locked <0x00000000c6459540> (a org.apache.tomcat.util.net.SocketWrapper)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)rn at java.lang.Thread.run(Thread.java:745)rn[/code]rnrn现在想在还用xfire的情况下解决该问题,不考虑:定期重启tomcat、改成cxf。rn 论坛

没有更多推荐了,返回首页