[Reposted] How to solve the problem of high boot memory usage in springboot project

How to solve the problem of too high memory usage in the springboot project

problem:

A very serious resource problem in the development of springboot is that the memory usage is too high, and in fact, the local development test does not have a large amount of requests, so this is a serious waste of computer resources and even causes the IDE to freeze ,collapse.

Sometimes a very simple project can easily occupy 1g of memory as soon as it is started. Today's optimization has successfully reduced the memory to about 200m. In fact, the main default configuration is a bit large, so that the optimization can run smoothly no matter whether it is local or server.

Dry goods:

Start command example, it is almost enough to start about 150m:

nohup java -jar -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=56m -Xms128m -Xmx128m -Xmn32m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC short-url.jar --spring.profiles.active=prod >/dev/null 2>&1&

Parameter meaning:

-XX: MetaspaceSize = 128m: default size of metaspace

-XX: MaxMetaspaceSize = 128m: the maximum size of the meta space

-Xms1024m: the maximum size of the heap

-Xmx1024m: default heap size

-Xmn256m: new generation size

-Xss256k: the maximum depth of the stack

-XX: SurvivorRatio = 8: Cenozoic partition ratio 8: 2

-XX: + UseConcMarkSweepGC: specify the garbage collector to use, here use the CMS collector

-XX: + PrintGCDetails: print detailed GC logs

If the set memory size is too small, you can change the configuration according to the actual situation.

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12602791.html