cloudfoundry / java-buildpack-memory-calculator

Cloud Foundry JVM Memory Calculator
Apache License 2.0
642 stars 70 forks source link

Getting java.lang.OutOfMemoryError: Java heap space when using Spring kafka to produce a message #27

Closed rajeshhereforyou closed 5 years ago

rajeshhereforyou commented 5 years ago

I'm trying to deploy a spring boot app on Pivotal Cloud Foundry to use spring kafka to send a message to kafka and getting below error with 1GB memory in manifest.yml. My sprint boot app has just one Rest Controller with only one endpoint to send a message. The app is starting without any issue if I change the memory to 2GB in my manifest.yml and it's taking almost 1.3 GB - 1.8 GB to run the app. I'm wondering why this simple app is taking so much more. Is it because of Kafka ? In our app, we are using org.apache.kafka.clients.admin.KafkaAdminClient

We are using Spring 2.x, java 8 and buildpack 3.9 with this app.

[APP/PROC/WEB/0] OUT # java.lang.OutOfMemoryError: Java heap space
 {APP/PROC/WEB/0] OUT # -XX:OnOutOfMemoryError="/home/vcap/app/.java-buildpack/open_jdk_jre/bin/killjava.sh"

Any help to understand this issue would be greatly appreciated.

nebhale commented 5 years ago

Each application has its own memory profile. It appears that given a 1GB container (which likely results in ~400M of heap after all of the memory regions are allocated), your application requires more heap than is available. I'd hook a profiler like YourKit or JProfiler to the application to determine where your memory usage is occurring.