Phenomenon of the problem
[root@2wkvx /]# jstat -gc 1 2000 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796531.9 109388.0 104798.1 12364.0 11638.8 181 4.508 4129 914.951 919.459 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796536.4 109388.0 104798.1 12364.0 11638.8 181 4.508 4139 916.811 921.318 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796542.0 109388.0 104798.1 12364.0 11638.8 181 4.508 4150 918.822 923.330 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796541.4 109388.0 104798.1 12364.0 11638.8 181 4.508 4160 920.780 925.287 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796543.5 109388.0 104798.1 12364.0 11638.8 181 4.508 4171 922.759 927.267 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796544.0 109388.0 104798.1 12364.0 11638.8 181 4.508 4182 924.802 929.310 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796544.0 109388.0 104798.1 12364.0 11638.8 181 4.508 4193 926.755 931.263 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796544.0 109388.0 104798.1 12364.0 11638.8 181 4.508 4204 928.730 933.238 465408.0 465920.0 0.0 0.0 446464.0 446455.5 2796544.0 2796542.0 109388.0 104798.1 12364.0 11638.8 181 4.508 4215 930.797 935.304 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796544.0 109388.0 104798.1 12364.0 11638.8 181 4.508 4222 932.032 936.540 465408.0 465920.0 0.0 0.0 446464.0 446464.0 2796544.0 2796521.6 109388.0 104798.5 12364.0 11638.8 181 4.508 4230 934.761 939.269 Size of the second survival area * S0U: size of the first survival area * S1U: size of the second survival area * EC: size of Eden Park * EU: size of Eden Park * OC: Old age size * OU: Old age size * MC: Method area size * MU: Method area size * CCSC: size of compressed class space * CCSU: size of compressed class space * YGC: Number of young generation garbage collection * YGCT: Number of young generation garbage collection time * FGC: number of old generation garbage collection time * FGCT: Number of old generation garbage collection time * GCT: Number of old generation garbage collection time * GCT: Number of old generation garbage collection time * GCT: Number of old generation garbage collection time * GCT: Number of old generation garbage collection time * GCT: Number of old generation garbage collection time [root@kuai-websocket-77b9dc5dbf-8z5mp /]# jinfo 1 VM Flags: non-default VM Flags: -XX:CICompilerCount=15 -XX:InitialHeapSize=1073741824 -XX:MaxHeapSize=4294967296 -XX:MaxNewSize=1431306240 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=357564416 -XX:OldSize=716177408 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC Command line: -Xms1024m -Xmx4096m [root@kuai-server-757799875b-2wkvx /]# jmap -heap 1 Attaching to process ID 1, please wait... Server Compiler detected. JVM version is 25.181-B13 using thread-local object allocation. Parallel GC with 33 thread(s) Heap Configuration: MinHeapFreeRatio = 0 MaxHeapFreeRatio = 100 MaxHeapSize = 4294967296 (4096.0MB) NewSize = 357564416 (341.0MB) MaxNewSize = 1431306240 (1365.0MB) OldSize = 716177408 (683.0MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 (0.0MB) Heap Usage: PS Young Generation Eden Space: Capacity = 457179136 (436.0MB) Used = 457179136 (436.0MB) Free = 0 (0.0MB) Capacity = 476577792 (454.5MB) Used = 0 (0.0MB) Free = 476577792 (454.5MB) 0.0% used To Space: Capacity = 477102080 (455.0MB) Used = 0 (0.0MB) Free = 477102080 (455.0MB) 0.0% Used PS Old Generation capacity = 2863661056 (2731.0MB) Used = 2861965360 (2729.382858276367MB) Free = 1695696 (1.6171417236328125MB) 99.94078572963629% used [root@kuai-server-757799875b-slmzd /]# jmap -histo:live 1|grep WsFrameServer 175: 202 22624 org.apache.tomcat.websocket.server.WsFrameServer [root@kuai-server-757799875b-slmzd /]# jmap -dump:live,format=b,file=dump.hprof 1Copy the code
Analyze dump files:
-
The reference objects for WsFrameServer as seen in the Histogram are 3.1g in total
Shallow Heap represents the size of memory occupied by the object itself, excluding references to other objects, which is the sum of the object header plus its member variables (not their values).
Retained Heap is the Retained Heap of the object plus all Retained Heap that can be accessed directly or indirectly from the object. In other words, the Retained Heap is the sum of memory that can be recovered from the object after GC.
-
Look for external references not released by the GCRoot of WsFrameServer
Paths to GC Roots -> exclude all phantom/weak/soft etc. Reference Find the code logical segment with the highest memory footprint that has not been freed (most likely generating out of memory code)
-
Filter to see the size of InstanceMonitorHandler
-
Look at the memory usage of WsFrameServer. There will be two objects, a messageBufferText and a messageBufferBinary, one 10M and one 5M
-
Code diagnosis:
A. Spring-websocket. XML configuration bufferSize:
<bean class="org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean">
<property name="maxTextMessageBufferSize" value="5242800"/>
<property name="maxBinaryMessageBufferSize" value="5242800"/>
</bean>
Copy the code
B. The WebSocket connection is not closed when the page is closed. As a result, the number of connections increases