0

I have a Servlet application running on Tomcat 7. I set the following in setenv.sh

CATALINA_OPTS="
-server 
-Xms1G 
-Xmx5G
-XX:MaxPermSize=512m
-Dfile.encoding=UTF-8";

The server runs on Ubuntu 12.04LTS, has 6 Cores and 8GB of RAM. My application is a Grails/Spring/Java app where users can upload images. Sometime it occurs that 3-5 users start uploading images at the same time. In these situations my Tomcat crashes because of the following error:

java.lang.OutOfMemoryError: Java heap space

I know that I have to increase the Xmx parameter of my Tomcat to prevent this problem. But seriously what is wrong in my case?

  1. Is there a best practice to handle file uploads like in my scenario?

  2. Can I prevent this problem some how? I mean when 5GB are not enough for 3-5 parallel uploads how much resources do I need for hundreds of parallel uploads?

  3. Is my app so bad or is it normal that file upload takes so much resources?

Here is the code that handles the upload in a Grails Controller:

CommonsMultipartFile file = (CommonsMultipartFile) request.getFile('image')
file.transferTo(new File("${storagePath}${fullFileName}"))

After the upload I do a lot of Image Processing. Is there a way to queue the process?

2 Answers 2

1

To be honest, 5G's of heap is already quite a lot. Show us the code path that handles the upload and provide some info about how large and many files are the users typically uploading.

This might also help you (if you are using commons fileupload with Spring's MultipartFile): https://stackoverflow.com/questions/1693810/how-can-i-avoid-outofmemoryerrors-when-using-commons-fileuploads-diskfileitem-t

1
  • I updated my code. Does this helps you?
    – Michael
    Sep 3, 2013 at 20:40
1

Memory use depends on what the app has been designed to do and what all the users are doing. So that really nobody could comment on whether this app needs a specified amount of memory. As you said your solution is to do as the error message says and up the amount of Java heap space.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .