[CMA-16] Improve the readContentIntoStream(..) method in ContentService Created: 17/Jun/08  Updated: 15/Oct/10

Status: Open
Project: Remote Alfresco API rivet
Component/s: CMA API
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: Nazem Attar [X] (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CMA-23 Uploading large files throws OutOfMem... Open

 Description   
Improve the readContentIntoStream(..) method in ContentService to prevent an OutOfMemoryError because the stream from Alfresco to CMA fills up faster than the stream from CMA to the client is flushing. Currently, a quick fix would be to increase the memory in the JVM running CMA, or to run CMA on a different box than Alfresco (to make it slower).

With default settings for memory, and if running both JVMs on the same machine, the CMA JVM is out of memory when downloading a file of size around 32MB.

 Comments   
Comment by skhaja [ 10/Feb/09 ]
This error is probably occuring here in the RestExecuterImpl.java

       executeHttpMethod(httpMethod);
       String responseType = getResponseType(httpMethod);
if (responseType.equals(CmaConstants.RESPONSE_BINARY)) {
writeToStream(httpMethod.getResponseBodyAsStream(), output);

When this call is made, getResponseBodyAsStream is the whole file that is already loaded into the memory.

Java 1.5 HttpURLConnection supports something called setChunkedStreamingMode

http://java.sun.com/j2se/1.5.0/docs/api/java/net/HttpURLConnection.html#setChunkedStreamingMode(int)

Also HttpURLConnection of commons httpClient supports this from the super class.

http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/util/HttpURLConnection.html

This may solve the issue that we have with OutOfMemoryError.

-Shagul
 
Comment by skhaja [ 10/Feb/09 ]
CMA-16 and CMA-23 are related. Solving one may solve the other.
Comment by skhaja [ 11/Feb/09 ]
This issue is fixed and happens only while using seam with richfaces on the client side.

RestExecuterImpl execute method is reading from an input stream and writing into an output stream.

There is no obvious buffering.

When using seam with richfaces, all output stream pass through the ajax4jsf filter which was doing the buffering.

The hint was in the stackTrace.

Caused by: java.lang.OutOfMemoryError: Java heap space
        at org.ajax4jsf.io.ByteBuffer.<init>(ByteBuffer.java:54)
        at org.ajax4jsf.io.ByteBuffer.append(ByteBuffer.java:112)
        at org.ajax4jsf.io.FastBufferOutputStream.write(FastBufferOutputStream.java:107)

Adding the below to components.xml prevents the filter from being applied to /seam/resource/alfdocument* pattern.

   <web:ajax4jsf-filter force-parser="true"
                     enable-cache="true"
                     log4j-init-file="log4j.xml"
                     regex-url-pattern="^(?:[^/]|/(?!seam/resource/alfdocument))*$"
                     />

In earlier versions while using just ajax4jsf these filter exceptions can be placed in web.xml.

Change the regular expression accordingly to avoid ajax4jsf filter.

So the issue is not with Raar buffering. Further testing is being done to see if all other ajax calls from the apps are working.

Any finding will be updated here.

-Shagul
Comment by skhaja [ 11/Feb/09 ]
If you get an error like

java.lang.NoClassDefFoundError: org/cyberneko/html/HTMLAugmentations

Add the below dependency to your seam/richfaces project.

             <dependency>
   <groupId>nekohtml</groupId>
   <artifactId>nekohtml</artifactId>
   <version>0.9.5</version>
</dependency>

Any other NoClassDefFoundError, include the appropriate maven dependencies/jars.

-Shagul
Generated at Sat Feb 10 05:51:19 GMT 2024 using Jira 8.1.3#801003-sha1:6b6f07cffadda9a0d6efe24639daed8ce94dcdd6.