[Virtual machine] java jvm tuning

Transfer: https: //www.cnblogs.com/starhu/p/6400348.html utm_source = itdadao & utm_medium = referral?

  1. Heap size
    JVM maximum heap size has three limits: the operating system related data model (32-bt or 64-bit) limit; virtual memory available restriction system; physical memory available restriction system. 32-bit system, generally limited to 1.5G ~ 2G; 64 unrestricted memory for the operating system. I have Windows Server 2003 system, 3.5G physical memory, JDK5.0 under test, the maximum is set to 1478m.
    Typical settings:
    • the Java  -Xmx3550m -Xms3550m -Xmn2g  -Xss128k
      -
      Xmx3550m : Set JVM maximum memory available for the 3550M.
      -Xms3550m : Setting JVM memory to promote 3550m. This value can be set the same -Xmx, each JVM to avoid reallocate memory garbage collection completes.
      -Xmn2g : Set the size of the young generation 2G. The entire JVM memory size = size + the young generation old generation of permanent generation size + size . Permanent generation is generally a fixed size 64m, so the increase in the young generation, will reduce the size of the old generation. This value greater impact on system performance, Sun official recommended configuration for the entire heap of 3/8.
      -Xss128k : Sets the stack size for each thread. JDK5.0 after each thread stack size is 1M, before each thread stack size is 256K. Thread more application memory size of the required adjustment. At the same physical memory, reducing this value can generate more threads. However, the number of operating system threads within a process still limited, not unlimited generation, experience in 3000 and 5000.
    • -Xmx3550m -Xms3550m -Xss128k Java  -XX: NewRatio = -XX. 4: SurvivorRatio = -XX. 4: MaxPermSize the 16m -XX =: = 0 MaxTenuringThreshold
      -XX: = NewRatio. 4
      : Set the young generation (including Eden and two Survivor areas) old generation ratio (removal permanent generation). Is set to 4, the share of the young generation and old generation ratio of 1: 4, the total stack of the young generation 1/5
      -XX: SurvivorRatio = 4 : Set the size of the area ratio of Eden Survivor young generation area. Is set to 4, the ratio of the two regions with a Survivor Eden zone is 2: 4, the total area Survivor a young generation 1/6
      -XX: = MaxPermSize the 16m : setting the size of the permanent generation 16m.
      -XX: MaxTenuringThreshold = 0 : set the maximum age of garbage. If set to 0, then the younger generation of the object without Survivor areas, directly into the old generation . For more of the old generation of applications that can improve efficiency. If this value is set to a large value, then the young generation objects will be copied many times in Survivor areas, which can increase the object and then the young generation of survival time , an increase in the introduction to the young generation namely recycling.
  2. Collector selected
    JVM gave three options: serial collector, the collector parallel, concurrent collector , but the serial collector applies only to a small amount of data, so the choice here mainly for the parallel and concurrent collector collector . By default, JDK5.0 had previously been using a serial collector, if you want to use other collectors need to add the appropriate parameters at startup. After JDK5.0, JVM based on the current system configuration is determined.
    1. Priority throughput parallel collector
      as described above, mainly parallel collector to reach a certain constant target for scientific and technical background processing and the like.
      Configuration :
      • -Xmx3800m -Xms3800m -Xmn2g -Xss128k Java  -XX: + UseParallelGC -XX: ParallelGCThreads = 20 is
        -XX: + UseParallelGC
        : garbage collector to select the parallel collector. This configuration is valid only for the young generation. That the above arrangement, the young generation to use concurrent collection, while still using the old generation of the serial collector.
        -XX: ParallelGCThreads = 20 is
        : the number of threads parallel collector configuration, namely: simultaneously with many garbage collection threads. This configuration value is preferably equal to the number of processors.
      • -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX Java: + UseParallelGC -XX: ParallelGCThreads = 20 is  -XX: + UseParallelOldGC
        -XX: + UseParallelOldGC
        : Configure old generation garbage collection is collected in parallel. JDK6.0 support for the old generation of parallel collector.
      • -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX the Java: + UseParallelGC   -XX: MaxGCPauseMillis = 100
        -XX: MaxGCPauseMillis = 100
        : Set the young generation garbage collection every time the maximum time, if you can not meet this time, JVM will automatically adjust younger substituting size to meet this value.
      • -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX Java: + UseParallelGC -XX: MaxGCPauseMillis = 100  -XX: + UseAdaptiveSizePolicy
        -XX: + UseAdaptiveSizePolicy
        : this option is set, the parallel collector will automatically select the young generation area size and the corresponding Survivor proportional band, a predetermined time corresponding to the lowest target frequency system, or collection, use the recommended value when the parallel collector, has been opened.
    2. Response time priority of concurrent collector
      as described above, the concurrent collector is mainly guaranteed response time of the system, reducing the pause time garbage collection. Suitable for application servers, telecommunications and other fields.
      Configuration :
      • -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX Java: ParallelGCThreads = 20 is  -XX: + UseConcMarkSweepGC -XX: + UseParNewGC
        -XX: + UseConcMarkSweepGC : concurrent collection took old setting. After testing this configuration, -XX: NewRatio = 4 configuration fails for unknown reasons. Therefore, when the size of the young generation is preferably provided with -Xmn.
        -XX: + UseParNewGC : Set the parallel collector on behalf of the young. CMS can be collected and used simultaneously. JDK5.0 above, the JVM may set their own according to the system configuration, it is no need to set this value.
      • -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX the Java: + UseConcMarkSweepGC  -XX: CMSFullGCsBeforeCompaction = 5 -XX: + UseCMSCompactAtFullCollection
        -XX: CMSFullGCsBeforeCompaction : Since the memory space concurrent collector does not compress, organize, it will produce after running for some time. " debris ", making the operation efficiency is reduced. This value is set to run how many times GC memory space after compression, finishing.
        -XX: + UseCMSCompactAtFullCollection : Open compression of the old generation. Performance may be affected, but you can remove debris
  3. Supplementary information
    JVM provides a number of command line parameters, print information for debugging. There are some of the following:
    • -XX: + PrintGC
      output format : [GC 118250K-> 113543K (130112K ), 0.0094143 secs]

                      [Full GC 121376K->10414K(130112K), 0.0650971 secs]

    • -XX: + PrintGCDetails
      output format : [GC [DefNew: 8614K-> 781K (9088K), 0.0123035 secs] 118250K-> 113543K (130112K), 0.0124633 secs]

                      [GC [DefNew: 8614K->8614K(9088K), 0.0000665 secs][Tenured: 112761K->10414K(121024K), 0.0433488 secs] 121376K->10414K(130112K), 0.0436268 secs]

    • -XX: + PrintGCTimeStamps  -XX: + PrintGC: PrintGCTimeStamps used above with two mixing
      outputs form: 11.851: [the GC 98328K-> 93620K (130112K), 0.0082960 secs]
    • -XX: + PrintGCApplicationConcurrentTime: print before each garbage collection, the program does not interrupt the execution time. Above may be mixed using
      output form: the Application Time: 0.5291524 seconds The
    • -XX: + PrintGCApplicationStoppedTime : print garbage recycling program is suspended during the time. It can be mixed with the above
      output in the form: the Total Time for Which file application were stopped Threads: 0.0468229 seconds The
    • -XX:PrintHeapAtGC:打印GC前后的详细堆栈信息
      输出形式:
      34.702: [GC {Heap before gc invocations=7:
       def new generation   total 55296K, used 52568K [0x1ebd0000, 0x227d0000, 0x227d0000)
      eden space 49152K,  99% used [0x1ebd0000, 0x21bce430, 0x21bd0000)
      from space 6144K,  55% used [0x221d0000, 0x22527e10, 0x227d0000)
        to   space 6144K,   0% used [0x21bd0000, 0x21bd0000, 0x221d0000)
       tenured generation   total 69632K, used 2696K [0x227d0000, 0x26bd0000, 0x26bd0000)
      the space 69632K,   3% used [0x227d0000, 0x22a720f8, 0x22a72200, 0x26bd0000)
       compacting perm gen  total 8192K, used 2898K [0x26bd0000, 0x273d0000, 0x2abd0000)
         the space 8192K,  35% used [0x26bd0000, 0x26ea4ba8, 0x26ea4c00, 0x273d0000)
          ro space 8192K,  66% used [0x2abd0000, 0x2b12bcc0, 0x2b12be00, 0x2b3d0000)
          rw space 12288K,  46% used [0x2b3d0000, 0x2b972060, 0x2b972200, 0x2bfd0000)
      34.735: [DefNew: 52568K->3433K(55296K), 0.0072126 secs] 55264K->6615K(124928K)Heap after gc invocations=8:
       def new generation   total 55296K, used 3433K [0x1ebd0000, 0x227d0000, 0x227d0000)
      eden space 49152K,   0% used [0x1ebd0000, 0x1ebd0000, 0x21bd0000)
        from space 6144K,  55% used [0x21bd0000, 0x21f2a5e8, 0x221d0000)
        to   space 6144K,   0% used [0x221d0000, 0x221d0000, 0x227d0000)
       tenured generation   total 69632K, used 3182K [0x227d0000, 0x26bd0000, 0x26bd0000)
      the space 69632K,   4% used [0x227d0000, 0x22aeb958, 0x22aeba00, 0x26bd0000)
       compacting perm gen  total 8192K, used 2898K [0x26bd0000, 0x273d0000, 0x2abd0000)
         the space 8192K,  35% used [0x26bd0000, 0x26ea4ba8, 0x26ea4c00, 0x273d0000)
          ro space 8192K,  66% used [0x2abd0000, 0x2b12bcc0, 0x2b12be00, 0x2b3d0000)
          rw space 12288K,  46% used [0x2b3d0000, 0x2b972060, 0x2b972200, 0x2bfd0000)
      }
      , 0.0757599 secs]
    • -Xloggc: filename : Several used in conjunction with the above, the record log information to a file for analysis.
  4. Common Configuration Summary
    1. Heap settings
      • -Xms : Initial heap size
      • The -Xmx : maximum heap size
      • -XX: the NewSize = n- : Set the young generation size
      • -XX: NewRatio = n: setting the young generation and old generation ratio. Such as: 3, showing the young generation to the old generation ratio of 1: 3, the total the young generation and the young generation older generations 1/4
      • -XX: SurvivorRatio = n- : Eden ratio in the young generation area and two Survivor region. Note that there are two Survivor areas. Such as: 3, expressed Eden: Survivor = 3: 2, the total area Survivor a young generation 1/5
      • -XX: MaxPermSize = n- : setting the size of the permanent generation
    2. Collector settings
      • -XX: + UseSerialGC : serial collector provided
      • -XX: + UseParallelGC : disposed parallel collector
      • -XX: + UseParalledlOldGC : old generation collector disposed parallel
      • -XX: + UseConcMarkSweepGC : concurrent collector provided
    3. Garbage collection statistics
      • -XX:+PrintGC
      • -XX:+PrintGCDetails
      • -XX:+PrintGCTimeStamps
      • -Xloggc:filename
    4. Disposed parallel collector
      • -XX: ParallelGCThreads = n- : Set the number of CPU used to collect the parallel collector. Parallel to collect the number of threads.
      • -XX: MaxGCPauseMillis = n- : collecting the maximum pause time is provided in parallel
      • -XX: GCTimeRatio = n- : Garbage Collection percentage of time the program running time. Formula 1 / (1 + n)
    5. Concurrent collector settings
      • -XX: + CMSIncrementalMode : mode setting increments. For single CPU case.
      • -XX: ParallelGCThreads = n- : concurrent collector is provided to collect the young generation mode when the number of parallel CPU collected, used. Parallel to collect the number of threads.


Fourth, the tuning summary

      1. Select the size of the young generation
        • Priority response time of applications : as a large set until near the minimum system response time limit (based on the actual situation). In this case, the young generation collection frequency of occurrence is minimal. At the same time, reducing the reach of the old generation object.
        • Throughput priority applications : as much as possible to set a large, may reach the level of Gbit. Because the response time is not required, garbage collection may be performed in parallel, for more general applications 8CPU.
      2. Old generation size selection
        • Priority response time of the application : using concurrent old generation of collectors, so its size need to be careful to set, usually to consider concurrent sessions rate and duration of the session some of the parameters. If the heap is set small, it can cause memory fragmentation, high frequency and recovery application to suspend the use of the traditional way of marking clear; if a big heap, will require a longer collection time. The most optimal solution, usually need to refer to the following data obtained:
          • Concurrent garbage collection information
          • The number of concurrent permanent generation collection
          • Traditional GC information
          • The proportion of time spent on the young generation and the old generation recycling
          The young generation and the old generation to reduce the time it takes, generally raise the efficiency of the application
        • Throughput priority applications : general throughput priority applications have a lot of the young generation and a smaller old generation. The reason is, so you can recover as much as possible out most short-term target to reduce medium-term target, while the old generation to make long-term storage of live objects.
      3. Small pile of debris caused
        because the old generation concurrent collector using the mark, sweep algorithm, so it will not compress the heap. When the collector recovered, he would merge the adjacent space, which can be assigned to larger object. However, when the heap space is small, after running for some time, there will be "debris" if concurrent collector can not find enough space, then the concurrent collector will stop, and then use the traditional markers, clearing the way for recovery. If the "debris" appears, you may need as follows:
        • -XX: + UseCMSCompactAtFullCollection : When using concurrent collector, turn on compression for older generations.
        • -XX: CMSFullGCsBeforeCompaction = 0 : the case of the above configuration on, how many times Full GC provided herein, compression of the old generation

Guess you like

Origin www.cnblogs.com/wjqhuaxia/p/11920545.html