In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
When tomcat is used in daily operation and maintenance work, it is necessary to optimize the jvm virtual machine in tomcat. Only when we know the specific use of the parameters that need to be optimized, can we deeply understand the significance of optimizing jvm.
In the usual work, we talk about the optimization of jvm, mainly for the optimization of heap memory and garbage collection mechanism of java.
Schematic diagram of JVM heap memory:
The composition of JVM's heap memory:
Young generation: the new generation
Eden: Eden Park
Surived: survival area
Among them, there are two survival areas, the first is S0 and the second is S1
Old generation: the old age
Permanent generation: persistent generation
Detailed description of heap memory related parameters:
-Xms: initializes the heap memory size, excluding persistent memory. It defaults to 1x64 of physical memory and does not exceed 1G.
-Xmx: maximum heap memory size, excluding persistent memory. Default is 1x4 of physical memory.
-Xmn: the memory size of the new generation. The default value is 3x8 of Xmx, while the memory of the old age is 5can8.
-XX:NewRatio: specifies the ratio of memory between the new generation and the old generation. The default value is 2.
The ratio of-XX:SurvivorRatio:eden to the memory of 2 living areas. The default value is 8.
-XX:PermSize: the size of persistent memory during initialization
-XX:MaxPermSize: the size of the maximum persistent memory
Recommendations:
1. It is generally recommended that Xms be equal to Xmx. The advantage is to avoid adjusting the heap size after each gc and reducing the memory allocation overhead of the system.
two。 It is recommended that the values of-XX:PermSize and-XX:MaxPermSize are the same, because permanent generation resizing also causes heap memory needs to trigger FGC; is generally set to 128m is sufficient
Detailed description of parameters related to stack memory:
-Xss: specifies the maximum stack space of the thread. The default is 1m.
Jvm garbage collection algorithm:
1. Citation counting algorithm
Each object has a reference count property, which adds a reference count plus 1, minus 1 when the reference is released, and can be recycled if the count is 0.
This method is simple and can not solve the problem of circular reference between objects. Another problem is how to solve the problem of accurate counting.
two。 Root search algorithm (GC Roots)
Starting with GC Roots, the search takes a path called a reference chain, and when an object does not have any reference chain to the GC Roots, it proves that the object is unavailable.
Jvm garbage collection algorithm:
1. Replication algorithm (Copying)
two。 Tag removal algorithm (Mark-Sweep)
3. Tag finishing compression algorithm (Mark-Compac)
Replication algorithm:
By scanning from the root collection and copying the surviving objects to a new unused space, the cost is that a piece of memory swap space is required.
This algorithm is used for the new generation of memory recovery, copying from area E to S0 or S1.
Tag removal algorithm:
Scan from the root set, mark the surviving objects, and then scan the untagged objects in the whole space for recycling.
Advantages: extremely efficient in the case of more surviving objects
Disadvantages: tag removal algorithm directly recycles objects that are not alive, which will cause memory fragmentation
Tag finishing compression algorithm:
Objects are marked in the same way as tag cleanup, but unlike during cleanup, all objects that do not survive will be reclaimed.
The object moves to the left free space and updates the corresponding pointer. This algorithm not only clears the mark, but also moves the object.
Advantages: can solve the problem of memory fragmentation
Disadvantages: the cost is higher than the tag removal algorithm.
Garbage collection terms explain:
1. Serial Reclamation (Serial)-> gc single-threaded memory Recycling, suspending all user threads, exclusive reclamation
two。 Parallel Reclamation (Parallel)-> multiple gc threads working in parallel, suspending all user threads, exclusive recycling
3. Concurrent Reclamation (CMS)-- > gc thread and user thread execute at the same time, there is no need to pause the user thread (the user thread still needs to pause, just very short)
GC serial recycler (Serial recycler):
1. Is a single-threaded collector that can only use one CPU or one thread to complete garbage collection; when performing garbage collection, you must
Pause all other worker threads. Until the collection is complete.
two。 Cons: Stop-the-World
3. Advantages: simple, in the case of a single CPU, because there is no multi-threaded interaction overhead, but more efficient.
Opening method:
-XX:+UseSerialGC to open it.
After using this parameter: both the new generation and the old age use Serial collectors for garbage collection.
The new generation uses replication algorithm
The use of tag compression algorithm in the old days
GC parallel collector (ParNew collector):
1. Parallel collection is also an exclusive collector, and the application is completely paused during the collection process. But because the parallel collector uses multithreading
Garbage collection, so on the CPU with strong concurrency, it produces a shorter pause time than the serial collector. And in the single
On CPU or in systems with weak concurrency, the recovery effect will not be better than that of serial collectors.
Opening method:
-XX:UserParNewGC
After using this parameter: the new generation uses the parallel recovery collector, and the old generation uses the serial collector.
-XX:ParallelGCThreads can specify the number of threads, preferably equal to the number of CPU
The new generation uses replication algorithm
A new generation of throughput priority recyclers (Parallel Scavenge recyclers):
1. Throughput first Collector: focus on CPU throughput, that is, the time / total time it takes to run user code, which makes the most efficient use of CPU.
Opening method:
-XX:UseParallelGC enabled
After using this parameter: garbage collection will be collected using the Parallel Scavenge+Serial Old collector combination, which is also the default value in Server mode.
-XX:GCTimeRation can set the ratio of user execution time to total time. The default is 99, that is, 1% of the time for garbage collection.
The new generation uses replication algorithm
New Generation Throughput priority Collector (Parallel Scavenge Collector): Laosheng substitute Parallel Old algorithm
Opening method:
-XX:UseParallelOldGC enabled
Use Parallel Scavenge and Parallel Old combined collectors for collection
Using the tag collation algorithm in the old days
Concurrent tag cleanup recycler (CMS recycler):
The operation process is divided into four stages: initial marking, concurrent tagging, re-tagging, and concurrent clearing.
The two phases of marking and relabeling still require Stop-The-World, and the collector and user thread work together in other processes
Startup method:
-XX:ParallelCMSMarkSweepGC
After using this parameter: use the combination of ParNew + CMS + Serial Old for memory collection. Serial Old appears as CMS
Used by the backup collector after the "Concurrent Mode Failure" failure.
Other parameters:
-XX:ParallelCMSThreads manually sets the number of threads for CMS
-XX:CMSInitiatingOccupancyFraction: sets the amount of space used by the CMS collector to issue garbage collection. The default is 68%, which is valid only when the CMS collector is used.
-XX:CMSFullGCBeforeCompaction: sets the CMS collector to perform a memory defragmentation process after several garbage collections, usually used with-XX:CMSInitiatingOccupancyFraction
GC performance monitoring metrics:
Throughput-> percentage of time that applications spend on non-GC
CG load-- > contrary to throughput, refers to the percentage of time the application spends on GC
Pause time-> time spent on GC stop-the-world by App
GC frequency-- >
An interactive application requires less pause time, while for non-interactive applications, the lower the GC load, the better.
The lower the pause time and GC load, the better for a real-time system.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Support for remote connection protocols such as RDP, VNC, XDMCP, SSH, etc.
© 2024 shulou.com SLNews company. All rights reserved.