java.lang.outofmemoryerror: java heap space when creating ZIP archives in Google App Engine ( Java)

890 views
Skip to first unread message

Ibrahim Ali

unread,
May 17, 2019, 12:48:23 PM5/17/19
to Google App Engine

Creating ZIP archives in Google App Engine (Java) <br />
I am got
this error in the gae cloud logs:  <br>

java
.lang.OutOfMemoryError: Java heap space <br>
at java
.util.Arrays.copyOf(Arrays.java:2271)
at java
.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
at java
.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java
.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
<br><br>


Creating ZIP archives in Google App Engine (Java) <br />
I am got this error in the gae cloud logs:  <br>

java.lang.OutOfMemoryError: Java heap space <br>
at java.util.Arrays.copyOf(Arrays.java:2271)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113) 
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
<br><br>

I face this problem when zipping many files on the production server, 
so what should I do to fix it ? is there something can help in GAE 
or can I save zip file containing one file on the storage then open 
and edit it ? ( to min memory usage) 


ByteArrayOutputStream zipBaos = new ByteArrayOutputStream();
    ZipOutputStream zipOut = new ZipOutputStream(zipBaos);
    byte[] tmpBuf = new byte[1024];

while end of files{ byte[] fileContents = getFileContent(); // it is OK zipOut.putNextEntry(new ZipEntry(fileNameStr)); ByteArrayInputStream in = new ByteArrayInputStream(fileContents); int len; while ((len = in.read(tmpBuf)) > 0) { out.write(tmpBuf, 0, len); } zipOut.closeEntry(); } zipOut.close();

George (Cloud Platform Support)

unread,
May 18, 2019, 4:17:58 PM5/18/19
to Google App Engine
Hello Ibrahim, 

Which version of Java do you use? To avoid out-of-memory errors, you may consider setting a higher instance class in the appengine-web.xml configuration file, using <instance-class</instance-class>. If you use Java 8, you could ask for more memory in the same configuration file, by means of: 

   <env-variables>       
        <env-var name="GAE_MEMORY_MB" value="1024M" />
        <env-var name="HEAP_SIZE_RATIO" value="90" />
    </env-variables>

Increasing memory might not provide a proper solution. If your app suffers from memory leaks, increasing allocated memory might prove just a temporary solution. You should first undertake a thorough investigation, to establish where the origin of these error is to be found. 

This discussion group is oriented more towards general opinions, trends, and issues of general nature touching App Engine and Cloud SQL. For coding and programming architecture, as well as solving Java memory leaks, you may be better served in dedicated forums such as stackoverflow, where experienced programmers are within reach and ready to help.  

Ibrahim Ali

unread,
May 19, 2019, 11:36:35 AM5/19/19
to google-a...@googlegroups.com
Hello, Thanks for your reply.
Can I save zip file in the storage, then add files to it dynamically on run time ? it will help and prevent this error, but how can i do it using app engine services ?

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/321c9e04-b9a6-4618-9423-b3188e8dbb47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages