c1z3vq
Last Updated: February 25, 2016
·
630
· amirkarimi

JVM's insufficient memory error and the swap

As I develop on Scala/Play/Mongo I'm comfortable with maintaining my own server. About a month ago I've got a small VPS (2GB of RAM) from DigitalOcean and prepared it as my host environment by installing the following packages as usual:

  • Git
  • Nginx (as front-end server)
  • Virtualmin
    • DNS
    • Email Server
    • Apache
    • MySQL
    • RoundCube (as webmail)
  • MongoDB
  • OpenJDK 7

As you may guess they would need a reasonable amount of RAM.

I also have a publish script on my local machine which compiles the source (using stage), pushes it to the special repository on deployment server (using git) and restarts the embedded server of the Play application (using ssh).

I've deployed several applications the same way successfully but this time I had a problem. There were three running Play applications on this server. The problem was that applications stop running once in a while with an hs_err_pid*.log file which indicates that the memory is insufficient! Worse than that, Play web server wasn't getting started after publish.

Today, I accidentally found out that the server swap is zero. This was the main reason of insufficient memory error. After adding the swap file the server and web apps are working like a charm.

I don't need all of running processes to be lightning fast. Plus, the more the process is used the more priority it receives.

Conclusion

Always check the server swap before any other action on your VPS.

4 Responses
Add your response

22160

Thanks for sharing your experience.

over 1 year ago ·
22161

Thanks for sharing; but as I know It will work good until that the OS does not swap your JVM app (of course, there isn't any guarantee). In that case every time that the JVM's GC will garbage memory, the application/system performance will be terrible. I suggest you to increase memory or optimize your application/services...
Don't Relay on SWAP :)

Please forgive me If I have mistake in English :-)))

over 1 year ago ·
22162

@reza-samee Thanks for your comment.

As I mentioned there are plenty of other processes which are resident in the RAM while their priority is very low. Like MySQL, Apache for Roundcube and other Virtualmin services.

Swap guarantees that those less important processes will be moved to disk when there are more important processes (Play apps) to live in the RAM; that is exactly what I'm looking for. They are just custom-made CMS websites and I have to keep the server costs at minimum ;) They don't mind if I work with PHP and deploy on very cheap servers or develop on Scala with full asynchronous architecture and build and maintain the server by my self :D

Finally, the performance is great! I don't have any problem since then.

over 1 year ago ·
22170

Good post Amir, continue sharing knowledge.

over 1 year ago ·