Avoid OutOfMemoryError errors in Aiven for Apache Kafka®
When a node in an Aiven for Apache Kafka® or Aiven for Apache Kafka® Connect cluster runs low on memory, the Java virtual machine (JVM) running the service may not be able to allocate the memory, and will raise a java.lang.OutOfMemoryError exception.
As a result, Apache Kafka may stop processing messages in topics, and Apache Kafka Connect
may be unable to manage connectors.
For example, you can have a
Kafka Connect S3 sink connector with a TimeBasedPartitioner that is configured to generate
data directories with a path.format=YYYY/MM format.
This means that each output S3 object contains the data for a full month
of the year. Internally, the connector uses a buffer in memory for each
S3 object before it is flushed to AWS. If the total amount of data for
any single month exceeds the amount of available RAM at the time of data
ingestion, the JVM executing the Kafka Connect worker, throws a
java.lang.OutOfMemoryError exception and cannot manage the workload.
How to avoid OutOfMemoryError issues
There are three options for handling heavy workloads and potentially
avoiding java.lang.OutOfMemoryError exceptions:
- Decrease the maximum amount of data simultaneously kept in memory
- Increase the available memory for Kafka services or Kafka Connect workers
- Create a dedicated Kafka Connect cluster
The strategy to apply depends on a number of factors, and may combine more than one option.