spring boot项目,jvm基础配置

服务器启动文件startup.sh

`#!/bin/sh

check JAVA_HOME & java

noJavaHome=false
echo $noJavaHome
if [ -z "$JAVA_HOME" ] ; then
noJavaHome=true
fi
if [ ! -e "$JAVA_HOME/bin/java" ] ; then
noJavaHome=true
fi

CURR_DIR=pwd
cd dirname "$0"/..
COMM_HOME=pwd
cd $CURR_DIR
if [ -z "$COMM_HOME" ] ; then
echo
echo "Error: COMM_HOME environment variable is not defined correctly."
echo
exit 1
fi

startup Server

RUN_CMD="nohup java -Xms4g -Xmx4g -Xss512k -XX:+AlwaysPreTouch -Xss512K -XX:+UseG1GC -XX:MaxDirectMemorySize=256m -XX:MaxMetaspaceSize=256m -XX:ReservedCodeCacheSize=256M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/readsense/heapdump.hprof"
RUN_CMD="$RUN_CMD -jar readsense-face.jar > catalina.out "
RUN_CMD="$RUN_CMD 2>&1 &"
echo $RUN_CMD
eval $RUN_CMD`

在k8s中的配置方式

FROM docker-repository.xxxx.com/xxx/jdk:11.0.7 ADD app-xxxx.jar app.jar ENTRYPOINT ["java","-Xbootclasspath/a:./","-jar","-Xms2G","-Xmx2G","-XX:+AlwaysPreTouch","-Xss512K","-XX:+UseG1GC","-XX:MaxDirectMemorySize=256m","-XX:MaxMetaspaceSize=256m","-XX:ReservedCodeCacheSize=256M","-Dspring.profiles.active=common","app.jar"]
-XX:+AlwaysPreTouch 开启后,配置的xms内存会分配物理内存,减少物理内存波动
-Xss 每个线程的栈大小 默认1m,设置512可以新建更多的线程
-XX:+UseG1GC 使用 G1 垃圾收集器

控制堆外内存

-XX:MaxDirectMemorySize Direct buffer 大小(堆外内存)
-XX:MaxMetaspaceSize 源空间大小(堆外内存)
-XX:ReservedCodeCacheSize Code Cache(代码缓存)的预留大小(堆外内存)

posted @ 2024-11-27 10:06  hyiam  阅读(5)  评论(0编辑  收藏  举报