Application out of memory
This topic describes how to resolve out-of-memory errors in applications that use Message Queue.
Symptoms
The memory on the machine where the application is deployed is exhausted.
The
OutOfMemorykeyword is found in the/{user.home}/logs/sofamq.logfile.In the Message Queue console, the consumer status for the target Group ID shows a high number of accumulated messages in the Message Accumulation column. The Connection Information column displays the message accumulation for each connected client. A Jstack check shows that the
ConsumeMessageThread_thread is not stuck.
Possible causes
By default, the maximum memory that a client can consume is 512 MB. This value represents the total cache size for all topics to which the Group ID subscribes. The client caches up to 1,000 messages for each queue of each topic. For example, a topic may have 16 queues in a cluster with two primary nodes and two secondary nodes, with eight queues on each broker. If the average size of a message in this topic is 64 KB, the total size of messages cached on the client for this topic is 1 GB (16 × 1,000 × 64 KB). If you subscribe to eight similar topics at the same time, the total memory usage will exceed your JVM configuration. This causes an out-of-memory (OOM) error.
Solutions
Confirm the version of the ons-client dependency for the application.
Set the
com.alipay.sofa.sofamq.client.PropertyKeyConst#MAX_CACHED_MESSAGE_SIZE_IN_MI_Bparameter for theConsumerBeanto specify the maximum memory consumption. Set the value based on the memory usage of the application machine. The valid range is 16 MB to 2048 MB.Restart the application.
Verify the results
The
OutOfMemorykeyword no longer appears in the/{user.home}/logs/sofamq.logfile.Log on to the Message Queue console and view the consumer status. The real-time consumption speed increases and message accumulation decreases.