JVM内存和性能

来源:互联网 发布:java http json 编辑:程序博客网 时间:2024/05/17 23:01

As you know 32-bit machines are limited to a 4GB process space. Of that 4GB, the OS takes a chunk and the JVM takes the chunk that you allocated using -Xmx(Heap Allocation) and -XX:MaxPermSize(Perm Size). In what is left, the JVM threads are allocated. Woops, so the more RAM you need, the fewer threads you can create. Here is what that looks like (more or less):

C-Heap capacity = 2GB – Java Heap size (-Xms, -Xmx) – PermGen size (-XX:MaxPermSize)
Number of threads = (MaxProcessMemory - JVMMemory - ReservedOsMemory) / (ThreadStackSize)

JVM and OS use a more likely 150MB of Memory and the memory allocation of the Jvm is the sum of the Heap Allocation and of the Perm Size. The first can be fixed using the -Xms and -Xmx options, the second with the -XX:PermSize and -XX:MaxPermSize (default from 32MB to 64MB depending on JVM version).

A 64-bit JVM process is in theory allowed to use most of the OS virtual memory available or up to 16 EB (16 million TB)

Java HotSpot VM Options
Top 10 Causes of Java EE Enterprise Performance Problems
Thread Dump
verbosegc output tutorial - Java 7
10 Garbage Collection Interview Questions and Answers
How Garbage Collection works in Java
10 points about Java Heap Space or Java Heap Memory

"java.lang.OutOfMemoryError: unable to create new native thread"
OutOfMemory errors can be caused by several things:
Overcache, not well tuned JVM startup options, permgen out of memories, HttpSessions not purging or low frequency purge, or buggy code.

Recommendations:

  • First, quickly rule out any obvious OS memory (physical & virtual memory) & process capacity (e.g. ulimit) problem.
  • Perform a JVM Thread Dump analysis and determine the source of all the active threads vs. an established baseline. Determine what is causing your Java application or Java EE container to create so many threads at the time of the failure
  • Please ensure that your monitoring tools closely monitor both your Java VM processes size & OS virtual memory. This crucial data will be required in order to perform a full root cause analysis. Please remember that a 32-bit Java process size is limited between 2 GB - 4 GB depending of your OS
  • Look at all running processes and determine if your JVM processes are actually the source of the problem or victim of other processes consuming all the virtual memory
  • Revisit your Java EE container thread configuration & JVM thread stack size. Determine if the Java EE container is allowed to create more threads than your JVM process and / or OS can handle
  • Determine if the Java Heap size of your 32-bit JVM is too large, preventing the JVM to create enough threads to fulfill your client requests. In this scenario, you will have to consider reducing your Java Heap size (if possible), vertical scaling or upgrade to a 64-bit JVM

参考资料:

  • OutOfMemoryError: unable to create new native thread – Problem Demystified
  • How to fix "java.lang.OutOfMemoryError: unable to create new native thread"
  • fix for java.lang.OutOfMemoryError: unable to create new native thread
  • Resolving OutOfMemoryError: unable to create new native thread by changing max user processes - use "ulimit -u" (or "limit maxproc" in tcsh) to change max user processes
  • 2 solution of java.lang.OutOfMemoryError in Java

Java Performance tools:

  • Java VisualVM
    JConsole, jstat, jinfo, jstack, and jmap are part of Java VisualVM
  • visualgc
  • jhat (heap analyzer tool)
  • Eclipse memory analyzer (MAT)

jstatd
jstatd error : Could not create remote object : access denied
Using VisualVM to monitor a remote JBoss instance

0 0