linux java tuning

Insert picture description here

Tomcat encountered Caused by: java.lang.OutOfMemoryError: PermGen space or java.lang.OutOfMemoryError: Java heap space error.

  1. Abnormal cause
    The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of ​​memory. This memory is mainly used by the JVM to store Class and Meta information. Class is placed in PermGen space when it is loaded by Loader, which is different from the Heap area where class instances are stored. GC (Garbage Collection) will not clean up the PermGen space during the main program runtime, so if your application has a lot of CLASS, it is likely that a PermGen space error occurs. This kind of error is common in web server precompile JSP time. If you use a lot of third-party jars under your WEB APP, the size of which exceeds the jvm default size (4M) then this error message will be generated.

Java heap space: The setting of the JVM heap refers to the setting of the memory space that can be used by the JVM during the running of the Java program. The JVM will automatically set the Heap size value at startup, and its initial space (ie -Xms) is physical memory 1/64, the maximum space (-Xmx) is 1/4 of physical memory. It can be set by using options such as -Xmn -Xms -Xmx provided by JVM. Heap size is the sum of Young Generation and Tenured Generaion. In the JVM, if 98% of the time is used for GC and the available Heap size is less than 2%, this exception message will be thrown. The maximum Heap Size should not exceed 80% of the available physical memory. Generally, the -Xms and -Xmx options should be set to the same, and -Xmn is the 1/4 -Xmx value.

  1. Solution

Modify the TOMCAT_HOME / bin / catalina.sh file:

OS specific support. $var must be set to either true or false.

JAVA_OPTS="-server -Xms2048m -Xmx2048m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=512m -Djava.awt.headless=true"

cygwin=false

darwin=false

After adding the above red JAVA_OPTS line record, restart the tomcat service. The specific value of each parameter of JAVA_OPTS must be allocated according to the actual server physical memory size.

  1. Monitor JVM

4.1 View jdk installation path
Optional commands:

(1) # echo $JAVA_HOME

(2) # whereis java

(3) # which java (java execution path)

(4) # echo $PATH

This example:

4.2 View java process

Use the jps (JavaVirtual Machine Process Status Tool) gadget provided by jdk to view the current Java process.

This example: After entering the /usr/java/jdk1.7.0_79 directory, execute bin / jps -v:

You can see that the number 10142 in front of Bootstrap is the Java process ID, and you can see that the JAVA_OPTS parameter takes effect.

4.3 View the GC of the JVM

Use the jstat tool to view, the syntax is:

jstat [generalOption | outputOptions vmid [interval [s | ms] [count]]] Parameter explanation:

* Options-options, we generally use -gcutil to check the GC situation

vmid -VM process number, that is, the currently running java process number

interval-interval time in seconds or milliseconds

In this example: also check the java process number 10142 in the /usr/java/jdk1.7.0_79 directory and output it every 3 seconds, execute # bin / jstat -gcutil 10142 3000:

The parameter description is as follows:

S0-The percentage of used space in the Survivor space 0 area on Heap

S1-The percentage of used space in the Survivor space 1 area on Heap

Percentage of used space in the Eden space area on E-Heap

The percentage of used space in the Old space area on O-Heap, reaching 100%, is a memory overflow

The percentage of used space in the P-Perm space area, reaching 100%, is a memory overflow

YGC-The number of times Yang GC occurred from application start to sampling

YGCT-the time it takes for the Yang GC from application startup to sampling [in seconds]

FGC-the number of full GCs from application launch to sampling

FGCT-the time it takes for the Full GC from application launch to sampling

GCT-the total time for garbage collection from application launch to sampling [in seconds]

By monitoring the value of O and P, the size of JAVA_OPTS related parameters is adjusted again to achieve the purpose of optimization.

U2FsdGVkX18g0ZLF3Ibx8leQC3HH5p2Nvz6cJ934srMP/+1lWLrb+ZSIMH7coWPh
25D1UpL6Fadad9OO9e6sq3ST9KWGwrqr12KLXgi2CHfjWyHjPa49Ajz62QquzmaC8J2ZcXvw6rIPFBnAdKAMAwHJEQLomLlDR7oVz7Ir6aCWYAnXes4vNJMVBgKLd2pGKYTXXkb6IXTF2V36QpX9vjqClcNvj2DWf07CrQiegwrJIjjGxTxJJAbPtTkqpjF0PY60NRVRwzqknitBjQKjJcuu+7QjlCfh+sdsYMZl8rerw7D4iLHXD16zGsUrkpPxdXfioC8EGNl/Q0/iXAuLD2QmzS1K+R59SVKiK2r0y6PGIywRv8PJ5e8VifMv9ckdtpuy2NXEqNi9VBh87lK7s6W8zUcrDptq942Rvo1qejXgTegDvzSCpY7z1ZgFMfSMZePmSCQyQCpCYpGV7o53Xf24ClfUh3WjU6lQycX/vmG2QdQGtOFtb4mb6f6n1Bpx478MOkPV4twhYyeWac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qrxaUUhQ2u3WTdadVulb3bWVpj4XhdKIBK7cmTg + bDscItbnah9SznXrSAyrCHU2 / 9SLxaObANXHu + / m03EhfE + QK7J4mm3caFnRThc7xYkVKKRiHeA58zjfxOxfUrNLwjoYTrFjK + wY9hCWL4VUJWZFX4VUJNSFX4VUJNSFX4VUJWZFX4VUJNSFTqSyxtuFRPd004AVD066yK94WUpTj9NwpSu9HcNTShVAT7F1KJefpbZTiTGhqEi0jgYVIYR80PMyMXcuTR64259pmhKUFsy93kMnj1xTHrXR91RMBbfqvGKnIaC6OmtIBs5KKGQztwCUozg + XkzvHofiAQixKKoclsDERanRFdUvaXQ1BLPDK71zPU3xHpY8tnPfEgaIXuDsIFBF / 6ULbD4MDz8ddGEtGX8WgaaUjH1i3OrME5WYXXiGF / 7nC + mhM + AfGASCk8cqNCjUGFdZY3ZeH4 + Dcef1ZWjgE5d9JICgNkf0pJMqJYDUCJPLY1SntEhwv + G + 3i2qDzgqD8lnhLPPy80kGNNBhk3WzjYekbPNxlrZOgaFsiKlu / N9cE9fSHtd7snPHkeQ6IRPKPPirURNJQ7uS2D5pdtCppdqXDeDKp3hGaDkdNJjmKOJIo8Ivhy377RWnAo4fiHgcJJvdIRxYEe2oEGCW2GHosp5Gj2Cav / OrAQhKPONERH70zQBNN3ufJmFGLN8d60vCEFPXlJsdpcFLwInqvtg0KZYyrRzY7dok3Oi8eZjWPcB9Q5XvhgZ41YEYi / l9u + e5ZSQxPprvlnTwFR8cdxDcDn4u5J8LD3Jl + NmKGXv1vEcunbQmCKb0UOniik00D6X179XZIWN + eKjxfab + to6AtskiSPHiGTkcG2tsuO775UwrmpuCEMSr / 1hL0SiJTFhWoo3e4nrnRTqI / gtV9jjd5wlgyuhOg1 + O9AAMugm / vUUev36wNsjUtny78Ir04OeF6SMbP0zK0VRlAMeHWlDeSlRUdHjF80wq5V7eSoyqWxXX / JHlrZOEHBno / SmvblEO48HwdyCyzUkVkNN 9pbxP5d20WBgUsBkXGAyp7K7IoYpsCFjbKMQKMRVqvyhFhPBC8lkdrKpvst2j1LcrBFmSKfODwJP7PvLnKwjAGVgxyx + + + + O zctl2KdGHcbiujXJYxEwRyhgw Jeb28tPQhGFE3mOJ9 qxeXkQiL5b5XDNUUVs5ihx74qn + ++ + PNklJJZshiDiDvpk8ctTBhsk9AV05EqbepmEWWa3qKigvJ0QDSOmevQsHjAcgsH4hMN9hx8 pbswqr1yexyvLFMikMRcC2XQ8ISJuu / eUuAUL5KEJfgLfbqboDWzDTVLtT9If4a4YZVlbvxmsb5eELaoyiNHI99UCR8NCR4rW / cBkDCO891uSy + + vfvW8jVUmhrcgLLCNXwdjLt0x85BJBRl7Zwi 3BKpJho / I8D07jYbjG / y5ZdenzULr5PD8bjK5isIYcH7tTzb28kp5K4ZdgVDLakmtkz7nLmtJhb3i2xyFD72ZsiyIpHLAxNVqxOaTjO2ttevKNeKfiZtVDaXi8HSWh6zwvPndb5d1wbAOvkvd8KgdXDTOpiKSAq0k9Npd // zdKeHPQkjwNwXQu48j95smrEDgi336ktkOivOhsqWJ4 1VRkmMJx559FqJvYwIgzVd6jv958I5wXiKlbAi + / TVYvu8IyhxrA74P80f7WLi9BGoyT3rCciejclvZFX4j6L / Ftssb24rlQtATHxgQwNYslkLEwkvBRk9Fsg0A3A / O6erPGpm3buN066jM61ME / vKt / vrkzcr / RkEYW7N 1EWhlQ28vPpTW3MDjiY40 + + + OybVShWLd3hc0dFZ0JOpTXxMNzitlUrEQG34DBCOCqGPWUhE5WL02JJrvCKSAr 5UEKjOe9Y/3OLgWTxmK2Cl+Xm0lwBfQZ+ZvH73BePTl30mv6RyDMcyqTqo/DGJnOTxmWLST/M7GY48GsKp3nuqk7qGqPphsw2Ykf2/K6jm3QJ3HhWsXhsRPHUAHpw9DYQA+kxZ/1TuVfJuWvLYAyF6I

Published 219 original articles · Like3 · Visit 70,000+

Guess you like

Origin blog.csdn.net/xmh_sxh_1314/article/details/105497721