There is insufficient memory for the Java Runtime Environment to continue

I have a small memory footprint to work with 1g. It’s running 5.2.7+62 lucee build. Runs for about 3 weeks with a continuous workload then dies due to out of memory. It’s just running a loop polling sensors.

I know I can do a reboot on a cron to refresh it. Wondering if anyone has any better ideas on what to do here?

Thanks for the help in advance.

There is insufficient memory for the Java Runtime Environment to continue.
[ERROR] runwar.context: # Native memory allocation (mmap) failed to map 179044352 bytes for committing reserved memory.
[ERROR] runwar.context: # An error report file with more information is saved as:
[ERROR] runwar.context: # /root/pollmodbus/hs_err_pid28804.log
[INFO ] runwar.server: Starting RunWAR 3.8.1-SNAPSHOT
[INFO ] runwar.server: Starting background pollmodbus [lucee 5.2.7+62] from: /root/.CommandBox/lib/runwar-3.8.1-SNAPSHOT.jar
[INFO ] runwar.context: Starting in background -
[ERROR] runwar.context: Java HotSpot™ Client VM warning: INFO: os::commit_memory(0x54000000, 179044352, 0) failed; error=‘Cannot allocate memory’ (errno=12)

Caused by: java.lang.OutOfMemoryError: Java heap space

There is insufficient memory for the Java Runtime Environment to continue.

Native memory allocation (mmap) failed to map 55717888 bytes for committing reserved memory.

Possible reasons:

The system is out of physical RAM or swap space

In 32 bit mode, the process size limit was hit

Possible solutions:

Reduce memory load on the system

Increase physical memory or swap space

Check if swap backing store is full

Use 64 bit Java on a 64 bit OS

Decrease Java heap size (-Xmx/-Xms)

Decrease number of Java threads

Decrease Java thread stack sizes (-Xss)

Set larger code cache with -XX:ReservedCodeCacheSize=

This output file may be truncated or incomplete.

You mentioned 1Gig. Is that the amount of heap assigned or the amount of Ram on the server? Also, are you setting your min and max heap sizes? I would recommend that. Based on the error, it sounds like Java is trying to grow the heap size and the OS doesn’t have more RAM for it to use.

https://commandbox.ortusbooks.com/embedded-server/configuring-your-server/jvm-args#heapsize

https://commandbox.ortusbooks.com/embedded-server/configuring-your-server/jvm-args#minheapsize

Brad, had some time to revisit this today. Looking at this server this is the server.json file for it. I had set the heap size for it. Yet it blew up trying to grow it.

This is the memory allocation freshly rebooted. Wondering what I am missing , in that the max heap is growing beyond bounds? Any recommendations?

total used free shared buff/cache available

Mem: 1000208 505220 32808 374860 462180 63956

Swap: 0 0 0

{
“name”:“myapp”,
“web”:{
“host”:“0.0.0.0”,
“http”:{
“port”:“80”
}
},
“jvm”:{
“heapSize”:768,
“minHeapSize”:256
}
}

This really isn’t a CommandBox or even a Java issue, it’s an OS issue. Basically, the fix is that you need to set the min and max heap sizes to the same so the OS assigns the full amount of RAM right off the bat to Java and java doesn’t need to grow. However, keep in mind that Java uses other RAM for non-heap memory so factor that into what you leave for the operating system.

What is happening is your JVM is starting up with 256 Megs and over the course of time, the available RAM on the server is getting used from other processes-- who knows what. And later on, when Java asks for more, the OS says, “Sorry bud, I’m all out.”.

Now, keep in mind you most likely have your RAM over-allocated. Changing your JVM min heap size will most likely prevent Java from erroring, but might just make some other process down the road error. I would run your app for a while and profile what processes on the server are consuming RAM and how much.

Thanks for that explanation. It is very much appreciated here.