пятница, 17 августа 2018 г.

Cannot allocate memory on EC2 instance. Out of memory error.

Ok folks. Yo have EC2 instance. When you are doing a build, you can see the following error:
17:29:39.149 [INFO] [org.gradle.api.Project] OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000007ac000000, 234881024, 0) failed; error='Cannot allocate memory' (errno=12)
17:29:39.150 [INFO] [org.gradle.api.Project] # There is insufficient memory for the Java Runtime Environment to continue.
17:29:39.150 [INFO] [org.gradle.api.Project] # Native memory allocation (malloc) failed to allocate 234881024 bytes for committing reserved memory.
I've sold the same problem. (I have ec2, t2.micro, Ubuntu 14, Jenkins, Tomcat, Maven). By default you don't have swap space. To confirm this:
free -m
Just add some. Try with 1 GB for begin.
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Check again:
free -m
For more details look here