问题查询-tomcat内存泄露

1.报警信息

内容: 微信服务器向公众号推送消息或事件后,开发者5秒内没有返回 次数: 5分钟 239次 错误样例: [OpenID=o][Stamp=1562718361][3rdUrl=url][IP=ip][Event=Click Menu Url]

处理:

从阿里云监控查看主机均正常运行中;查看各台服务器日志情况,其中一台服务器不打印日志,但进程还在。重启了该条服务器后,告警停止。

2.nginx报错日志   16:29:09开始报错

2019/07/09 16:29:09 [error] 23960#0: *274190994 upstream timed out (110: Connection timed out) while reading response header from upstream, client: ip, server: server, request: "GET /wxqhb/pagemenu.html?pagemenuType=1 HTTP/1.1", upstream: "http://ip:8080/wxqhb/pagemenu.html?pagemenuType=1", host: "tpwxcloud.life.cntaiping.com"

nginx从upstream读取响应时超时,nginx默认的读超时为20s,读超时不是整体读的时间超时,而是指两次读操作之间的超时,整体读耗时有可能超过20s

2019/07/09 16:30:31 [error] 23963#0: *274221748 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.158.231.28, server: tpwxcloud.life.cntaiping.com, request: "GET /wxqhb/pagemenu.html?pagemenuType=1 HTTP/1.1", upstream: "http://ip:8080/wxqhb/pagemenu.html?pagemenuType=1", host: "tpwxcloud.life.cntaiping.com"

nginx从upstream读取响应时连接被对方reset

nginx连接服务器异常了,查看服务器的连接数情况

tomcat设置的连接数 <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="300" minSpareThreads="100"/>

3.分析生成的heapdump.hprof(16:33)

 tomcat 启动参数里设置了内存泄漏存入dump文件: /usr/java/apache-tomcat-7.0.62/bin/catalina.sh

tomcat配置的jvm是2G,内存快照显示2Gjvm已用完。占内存较大的是数据库返回的结果集。

4.查看慢SQL分析

有一条查询语句返回行数达到了近18万行。

5.该条慢SQL产生的原因

客户从官微进入95589的保单信息页面,先调腾讯接口获取客户的union_id,通过union_id在绑定表里查绑定的信息,该表union_id值为'null'的数据有179764条。

a.对于未关注的用户请求腾讯接口返回的union_id为空。

未关注: 获取腾讯unionId接口出参:{subscribe=0.0, openid=oFMgYv-D2tHaxUbspZWTt8PCT8z0, tagid_list=[]}

已关注: 获取腾讯unionId接口出参:{subscribe=1.0, openid=oFMgYv9XJPZ5iO8cf-cmdsZA2igY, nickname=睡着的水~, sex=1.0, language=zh_CN, city=浦东新区, province=上海, country=中国, headimgurl=http://thirdwx.qlogo.cn/mmopen/ajNVdqHZLLCwR59KibfCj8fEvIJ57JvBH30TB2icdFQaLgfq1jnkyPqu6W1aEwfpuKfhv4ibAiay8jn8KNiaJkAtYRQ/132, subscribe_time=1.553682236E9, unionid=oPWq_wnqNuogedygwjtona_inqig, remark=, groupid=0.0, tagid_list=[], subscribe_scene=ADD_SCENE_PROFILE_CARD, qr_scene=0.0, qr_scene_str=}

b.程序里的处理: 

String UnionId = String.valueOf(resultMapId.get("unionid"));
session.setAttribute("weixin_check_unionid", UnionId);

String unionid = (String)session.getAttribute("weixin_check_unionid");
if(''==unionid  || null==unionid ){ return ;}
UserBindingRs ubr = userBindingRsService.getCheckCustomerByunionId(unionid);//返回近18万行
select * from wcap_user_binding_rs where unioncode = ? and ubr_status = 1

TOMCAT与内存泄露

https://www.cnblogs.com/yangxia-test/p/3611385.html

原文地址:https://www.cnblogs.com/hongyedeboke/p/11301445.html