你的mac跑java应用是否较慢?
一、缘起
最近做Springboot启动优化,通过Jprofiler 性能分析监控,发现在我mac上应用启动进行了三次jdk的dns查询,且耗时严重。
如果觉得一次应用启动20秒左右挺快,出门右转、不送。
本文针对mac 加 java用户,欢迎对比自己mac情况,大概率存在同样问题,若有疑问欢迎反馈。
二、追踪
1.Jprofiler 监控
通过调用链发现Inet6AddressImpl.lookupAllHostAddr()被调用3次,且每次耗时5s左右。
2.调试 & google大法
目前已确认Mac运行Java 1.8.0_92 – 1.80_221 执行InetAddress.getLocalhost() 均存在同样问题,执行非常慢。
三、解决
解决方案:
1、退回到 java 1.8.0_051以前。(你不选,不能怂!)
2、修改 /etc/hosts 配置。
修改hosts文件命令:
duanbin@duanbindeMacBook-Pro ~ % sudo vim /etc/hosts
修改如下:
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost duanbindeMacBook-Pro.local
::1 localhost duanbindeMacBook-Pro.local
保存后再次运行Springboot应用,启动时间由20秒 降至 3秒 !!
这才是Mbp该有的性能!