服务器开发优化

① tomcat优化(1GB内存的机子)
https://www.cnblogs.com/centos2017/p/9956432.html
https://cloud.tencent.com/developer/article/1463754
在catalina.sh文件中,找到cygwin=false,在这一行的前面加入具体如下并保存退出:

JAVA_OPTS="-server -Xms256m -Xmx768m -Xss1024K -XX:PermSize=128m -XX:MaxPermSize=256m"

② 图片等资源文件不要放在tomcat的webapps目录下,放在专门存放资源文件的云存储,然后只要记录路径于数据库即可,或者放在webapps目录之外。
https://ask.csdn.net/questions/507863

③ 发现堆内存走势如上图,正常情况下堆内存走势应该是折线,而该图表示,直到堆内存满了之后,系统执行了full gc 堆内存使用率才下降,即发生了内存泄漏,这个问题令我百思不得其解,然后我利用mat排查原因,发现是框架问题,猜测spring在默认配置下,不会释放对象,但确确实实影响了我并发速度,查阅资料发现在主监听器千增加

IntrospectorCleanupListener

监听器可解决该问题 于是在web.xml中添加:
【亲测仅增加IntrospectorCleanupListener可以正常访问】

<!-- 防止内存泄露 -->
<listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>

再增加下面的就不行了,所以注释掉

<!--<listener>
    <description>Spring 核心监听器</description>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>-->

https://blog.csdn.net/qq_20948277/article/details/79158602

④ tomcat开机自启动:【亲测有效】
https://blog.csdn.net/hwijew/article/details/83586921
这个脚本是使用者自定的开机启动程序,可以在里面添加想在系统启动之后执行的脚本或者脚本执行命令
修改脚本文件rc.local:vim /etc/rc.d/rc.local
在最后一行增加(换成你实际tomcat的路径):
/home/tomcat包名/bin/startup.sh start
esc 退出编辑,:wq 保存修改

⑤ tomcat在生产环境多次热部署APP导致内存不断被消耗最终溢出的问题:
方案1:一个项目使用一个tomcat,部署后重启该tomcat,不会对其他项目产生影响
方案2:使用tomcat-docker
https://stackoverflow.com/questions/42265522/memory-leak-issue-in-deploying-multiple-tomcat-application-in-cpanel-server

Are you in production environment?
Exception appear exactly at deployment stage or at the first usage of your app?
Your apps are ligth (microservices) or are monolithics apps ? Xms and -Xmx arguments depend of that.
When you deploy a war file in tomcat, some section of tomcat java memory are used and is not well-managed by tomcat. A proof of that is if you deploy several times the same app without restart, an outofmemory appear in tomcat log.

If you are in production environment:

Use one tomcat by app. So you can deploy, stop, start, restart, etc this app without risk of impact other apps. If you restart tomcat after one deploy, memory errors at deployment stage go away.

Use tomcat-docker. With docker your could kill the entire tomcat ad start a new instance in each deploy. So your tomcat would be clean.

https://www.cnblogs.com/areyouready/p/8949991.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ithouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值