后端项目模块越来越多,构建部署速度越来越慢,想办法进行构建部署速度上的优化。
1、使用Maven的并发构建功能来加快构建速度。
在执行mvn clean install命令时,可以使用-T参数指定并发线程数。
mvn clean install -T 10 -Dmaven.test.skip=true
lscpu查看linux服务器cpu核数。
修改后项目构建时可能会报错too many open files(打开的文件过多)。
原因就是进程在某个时刻打开了超过系统限制的文件数量以及通讯链接数,通过命令ulimit -a可以查看当前系统设置的最大句柄数:
增大允许打开的文件数——修改系统配置文件
vim /etc/security/limits.conf
在文件结尾初增加配置:
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
2、优化启动脚本
并发启动微服务模块
原脚本(片段):
## 启动MY_GATEWAY
echo "****开始启动MY网关****"
nohup java -jar -Dloader.path=$2/libs/MY-gateway $JAVA_OPTS $MY_GATEWAY > $MY_GATEWAY_LOG 2>&1 &
MY_GATEWAY_PID=`lsof -i:$MY_GATEWAY_PORT|grep "LISTEN"|awk '{print $2}'`
until [ -n "$MY_GATEWAY_PID" ]
do
MY_GATEWAY_PID=`lsof -i:$MY_GATEWAY_PORT|grep "LISTEN"|awk '{print $2}'`
done
echo "MY_GATEWAY PID is $MY_GATEWAY_PID"
## sleep 1
echo "****MY网关服务启动成功!****"
echo " * "
## 启动MY_SYSTEM
echo "****开始启动MY系统管理****"
nohup java -jar -Dloader.path=$2/libs/MY-modules-system $JAVA_OPTS $MY_SYSTEM > $MY_SYSTEM_LOG 2>&1 &
MY_SYSTEM_PID=`lsof -i:$MY_SYSTEM_PORT|grep "LISTEN"|awk '{print $2}'`
until [ -n "$MY_SYSTEM_PID" ]
do
MY_SYSTEM_PID=`lsof -i:$MY_SYSTEM_PORT|grep "LISTEN"|awk '{print $2}'`
done
echo "MY_SYSTEM PID is $MY_SYSTEM_PID"
##sleep 1
echo "****MY系统管理服务启动成功!****"
echo " * "
## 启动MY_BASE
echo "****开始启动MY基础数据****"
nohup java -jar -Dloader.path=$2/libs/MY-modules-base $JAVA_OPTS $MY_BASE > $MY_BASE_LOG 2>&1 &
MY_BASE_PID=`lsof -i:$MY_BASE_PORT|grep "LISTEN"|awk '{print $2}'`
until [ -n "$MY_BASE_PID" ]
do
MY_BASE_PID=`lsof -i:$MY_BASE_PORT|grep "LISTEN"|awk '{print $2}'`
done
echo "MY_BASE PID is $MY_BASE_PID"
##sleep 1
echo "****MY基础数据服务启动成功!****"
echo " * "
新脚本(片段):
## 启动MY_GATEWAY
echo "****开始启动MY网关****"
nohup java -jar -Dloader.path=$2/libs/MY-gateway $JAVA_OPTS $MY_GATEWAY > $MY_GATEWAY_LOG 2>&1 &
MY_GATEWAY_PID=`lsof -i:$MY_GATEWAY_PORT|grep "LISTEN"|awk '{print $2}'`
nohup java -jar -Dloader.path=$2/libs/MY-modules-system $JAVA_OPTS $MY_SYSTEM > $MY_SYSTEM_LOG 2>&1 &
MY_SYSTEM_PID=`lsof -i:$MY_SYSTEM_PORT|grep "LISTEN"|awk '{print $2}'`
nohup java -jar -Dloader.path=$2/libs/MY-modules-base $JAVA_OPTS $MY_BASE > $MY_BASE_LOG 2>&1 &
MY_BASE_PID=`lsof -i:$MY_BASE_PORT|grep "LISTEN"|awk '{print $2}'`
until [ -n "$MY_GATEWAY_PID" ]
do
MY_GATEWAY_PID=`lsof -i:$MY_GATEWAY_PORT|grep "LISTEN"|awk '{print $2}'`
done
echo "MY_GATEWAY PID is $MY_GATEWAY_PID"
## sleep 1
echo "****MY网关服务启动成功!****"
echo " * "
## 启动MY_SYSTEM
echo "****开始启动MY系统管理****"
until [ -n "$MY_SYSTEM_PID" ]
do
MY_SYSTEM_PID=`lsof -i:$MY_SYSTEM_PORT|grep "LISTEN"|awk '{print $2}'`
done
echo "MY_SYSTEM PID is $MY_SYSTEM_PID"
##sleep 1
echo "****MY系统管理服务启动成功!****"
echo " * "
## 启动MY_BASE
echo "****开始启动MY基础数据****"
until [ -n "$MY_BASE_PID" ]
do
MY_BASE_PID=`lsof -i:$MY_BASE_PORT|grep "LISTEN"|awk '{print $2}'`
done
echo "MY_BASE PID is $MY_BASE_PID"
##sleep 1
echo "****MY基础数据服务启动成功!****"
echo " * "