当前位置:网站首页>[development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39

[development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39

2022-07-05 01:01:00 Random stone light

One : Performance monitoring jvm Memory model

 Insert picture description here

1. Program counter Program Counter Register

  • It records the address of the virtual machine bytecode instruction being executed ,
  • This memory area is the only one in JAVA Nothing is specified in the virtual machine specification OutOfMemoryError Region

2. virtual machine VM Stack

  • Describe the JAVA Memory model for method execution , Each method creates a stack frame when it executes , Used to store local variables , The stack of operands , Dynamic links , Method interface, etc
  • The local variable table stores various basic data types known at compile time 、 Object reference
  • If the stack depth requested by thread is not enough, it will report StackOverflowError abnormal
  • If the dynamic expansion capacity of the stack is not enough, it will be reported that OutOfMemoryError abnormal
  • The virtual machine stack is thread isolated , That is, each thread has its own independent virtual machine stack

3. Local method Native Stack

  • The local method stack is similar to the virtual machine stack , It's just that the local method stack uses local methods

4. Pile up Heap

  • Almost all object instances allocate memory on the heap
     Insert picture description here

Two : Pile up

All object instances and arrays are allocated on the heap . The heap is the main area managed by the garbage collector , Also known as “GC Pile up ”; It's also the place that we consider most about optimization . Heaps can be subdivided into :

1. The new generation :Eden Space 、From Survivor Space 、To Survivor Space

2. Old age

3. Forever / Meta space :Java8 The old generation , suffer jvm management ,java8 After the meta space , Use physical memory directly . therefore , By default , The size of the meta space is limited only by local memory .

 Insert picture description here
from Java8 Start ,HotSpot It has been completely replaced forever (Permanent Generation) remove , Instead, a A new area — Meta space (MetaSpace)
 Insert picture description here
 Insert picture description here

  • After object creation , Go to the Cenozoic area first , If you can't put it down , Then take GC Garbage collection . Then go to the Cenozoic area , If you still can't put it down , Just go to the elderly area
  • The elderly area is a situation that cannot be handled by the Cenozoic area , Will go in . If the elderly area can be put down , Then allocate memory . If you still can't put it down , Then carry out comprehensive GC
  • If you still can't put it down , Memory overflow exception will be reported
  • Elderly areas generally store objects with long-lasting vitality and large objects
  • Eden The park can be put into the survivor area , If you can't put it in, put it in the elderly area

3、 ... and :jconsole And jvisualvm( Monitor local and remote applications )

Jdk Two of my little tools jconsole、jvisualvm( Upgraded version jconsole); Start... From the command line , Can monitor local and local Remote applications . Remote applications need to be configured

1.jconsole

1) Get into jconsole
win+r Get into cmd, Input jconsole
 Insert picture description here
Double click the service you want to connect
2) View monitoring information
 Insert picture description here

2.jvisualvm( Recommended )

1) start-up
win+r Get into cmd, Input jvisualvm
 Insert picture description here
2)jvisualvm Can do
Monitor memory leaks , Tracking garbage collection , Memory at execution time 、cpu analysis , Thread analysis …
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-SfBQfgzm-1656760038856)(https://img-blog.cdnimg.cn/e4897ddc7b9a4c00895c6720de838f8e.png)]
function : Running
Sleep :sleep
wait for :wait
Resident : Idle threads in the thread pool
monitor : Blocked threads , Waiting for lock
3) Install plug-ins for easy viewing of garbage collection (gc)

  • Tools -> plug-in unit
     Insert picture description here
  • Available plug-ins -> Check for version updates
     Insert picture description here
  • If 503 Error resolution :
    Open the url https://visualvm.github.io/pluginscenters.html
    cmd Check out your jdk edition , Find the corresponding
     Insert picture description here
  • Copy the links found below . And reset it
     Insert picture description here
  • download gc plug-in unit
     Insert picture description here
  • see gc
     Insert picture description here
原网站

版权声明
本文为[Random stone light]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050059094068.html