I have a Vert.x web server which provides Websocket service. Vert.x server sends some data to client when client registers on server then the client sends a ACK back to server to make sure those data has already been delivered reliably.
I found the Vert.x server consumes a lot of memory after it has finished all the work.
Below are steps to reproduce the issue:
VertXSocketClient
vertx run testserver.java
The memory usage of Vert.x server will be printed out in your console with format:
total memory - free memory = used memory(MB)
System.gc()
Runtime runtime = Runtime.getRuntime();
int mb = 1024 * 1024;
totalMemory = runtime.totalMemory() / mb;
freeMemory = runtime.freeMemory() / mb;
I call System.gc()
every 5 secs to make sure to free memory. Yes, I know. System.gc()
shouldn't be called frequently. It has negative impact to system performance. The used memory does not decrease without such an instruction.
You can download the code here: https://www.dropbox.com/sh/6oxtfhgwffed72c/AAAX-BvYdGaTBgnRagxD9Bf-a/TestServer.java
vertx run VertXSocketClient.java
The client will register to websocket channel server automatically and the server instance will send data to client after registration has finished.
Here down the sample code to send data to client:
byte[] serverResponseData = serverResponse.getBytes();
Buffer buffer= new Buffer(serverResponseData);
ws.write(buffer);
With above code, used memory would be up to 62MB after all work is done, wherease it is only up to 15MB if I comment out ws.write(buffer)
.
My assumption is that Vert.x server always sets aside 62MB of memory for its lifetime.Isn't it supposed to release memory after the work is done?
You should definitely check Hazelcast map
configuration if you are using Vert.x. Maybe it's not related to your problem and your Vert.x usage, but I had similar problems with memory usage and found that my configuration (in cluster.xml
) was not appropriate regarding my use cases.
Some points you should check in Hazelcast config:
backup-count
- By default, Hazelcast has one sync backup copy time-to-live-seconds
- Maximum time in seconds for each map entry to stay in the map is 0 ( infinite
) by default max-idle-seconds
- Maximum time in seconds for each entry to stay idle in the map is 0 ( infinite
) by default eviction-policy
- NONE
eviction policy for Maps is used by default See Hazelcast Map documentation for more details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.