You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rohit Kelapure <ke...@gmail.com> on 2012/07/18 15:38:30 UTC

HIGH CPU inflating bytes in ResourceHandlerImpl.handleResourceRequest

In a high concurrency load test with Apache MyFaces + RichFaces component
library we found that under peak load majority of our web container threads
were stuck in this call stack

at java/util/zip/Inflater.inflateBytes(Native Method)
at java/util/zip/Inflater.inflate(Inflater.java:249(Compiled Code))
at
java/util/zip/InflaterInputStream.read(InflaterInputStream.java:146(Compiled
Code))
at
java/util/zip/InflaterInputStream.read(InflaterInputStream.java:116(Compiled
Code))
at java/io/FilterInputStream.read(FilterInputStream.java:77(Compiled Code))
at java/io/FilterInputStream.read(FilterInputStream.java:77(Compiled Code))
at java/io/PushbackInputStream.read(PushbackInputStream.java:133(Compiled
Code))
at
org/apache/myfaces/shared_impl/resource/ResourceImpl$ValueExpressionFilterInputStream.read(ResourceImpl.java:117(Compiled
Code))
at java/io/InputStream.read(InputStream.java:175(Compiled Code))
at java/io/InputStream.read(InputStream.java:97(Compiled Code))
at
org/apache/myfaces/application/ResourceHandlerImpl.pipeBytes(ResourceHandlerImpl.java:402(Compiled
Code))
at
org/apache/myfaces/application/ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:357(Compiled
Code))
at
org/richfaces/resource/ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:257(Compiled
Code))
at javax/faces/webapp/FacesServlet.service(FacesServlet.java:183(Compiled
Code))
at
org/richfaces/webapp/ResourceServlet.httpService(ResourceServlet.java:110(Compiled
Code))
at
org/richfaces/webapp/ResourceServlet.service(ResourceServlet.java:105(Compiled
Code))

After looking at the src code of
 org.apache.myfaces.application.ResourceHandlerImpl.handleResourceRequest(FacesContext)
 I can see that the ResourceHandlerCache caches the Resource metadata ;
however the actual output of the resource which is written to the
outputstream in ResourceHandlerImpl.pipeBytes is NEVER cached.

This causes a scalability problem in our case because each access to the
resource involves cracking open a jar, inflating the bytes and parsing a
stream of bytes. This is done multiple times for the same resource(say a
css file) inside the richfaces jar inspite of the resource not changing.

I propose a much needed performance optimization wherein we cache the
output of the Resource handled and stash the output byte[] it as
softReference in the ResourceHandlerCache.ResourceValue.

I have attached a patch that does the same and would like your feedback on
my proposal.
These patches are from src taken from Apache MyFaces 2.0.5

-cheers,
Rohit Kelapure,
Apache Open WebBeans committer

Re: HIGH CPU inflating bytes in ResourceHandlerImpl.handleResourceRequest

Posted by Leonardo Uribe <lu...@gmail.com>.
Hi

Please create an issue under myfaces issue tracker, and attach the files
there (selecting the option to accept license it under ASL), so any
committer can check them and include them if possible.

regard,

Leonardo
On Jul 18, 2012 3:39 PM, "Rohit Kelapure" <ke...@gmail.com> wrote:

>
> In a high concurrency load test with Apache MyFaces + RichFaces component
> library we found that under peak load majority of our web container threads
> were stuck in this call stack
>
> at java/util/zip/Inflater.inflateBytes(Native Method)
> at java/util/zip/Inflater.inflate(Inflater.java:249(Compiled Code))
> at
> java/util/zip/InflaterInputStream.read(InflaterInputStream.java:146(Compiled
> Code))
> at
> java/util/zip/InflaterInputStream.read(InflaterInputStream.java:116(Compiled
> Code))
> at java/io/FilterInputStream.read(FilterInputStream.java:77(Compiled Code))
> at java/io/FilterInputStream.read(FilterInputStream.java:77(Compiled Code))
> at java/io/PushbackInputStream.read(PushbackInputStream.java:133(Compiled
> Code))
> at
> org/apache/myfaces/shared_impl/resource/ResourceImpl$ValueExpressionFilterInputStream.read(ResourceImpl.java:117(Compiled
> Code))
> at java/io/InputStream.read(InputStream.java:175(Compiled Code))
> at java/io/InputStream.read(InputStream.java:97(Compiled Code))
> at
> org/apache/myfaces/application/ResourceHandlerImpl.pipeBytes(ResourceHandlerImpl.java:402(Compiled
> Code))
> at
> org/apache/myfaces/application/ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:357(Compiled
> Code))
> at
> org/richfaces/resource/ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:257(Compiled
> Code))
> at javax/faces/webapp/FacesServlet.service(FacesServlet.java:183(Compiled
> Code))
> at
> org/richfaces/webapp/ResourceServlet.httpService(ResourceServlet.java:110(Compiled
> Code))
> at
> org/richfaces/webapp/ResourceServlet.service(ResourceServlet.java:105(Compiled
> Code))
>
> After looking at the src code of
>  org.apache.myfaces.application.ResourceHandlerImpl.handleResourceRequest(FacesContext)
>  I can see that the ResourceHandlerCache caches the Resource metadata ;
> however the actual output of the resource which is written to the
> outputstream in ResourceHandlerImpl.pipeBytes is NEVER cached.
>
> This causes a scalability problem in our case because each access to the
> resource involves cracking open a jar, inflating the bytes and parsing a
> stream of bytes. This is done multiple times for the same resource(say a
> css file) inside the richfaces jar inspite of the resource not changing.
>
> I propose a much needed performance optimization wherein we cache the
> output of the Resource handled and stash the output byte[] it as
> softReference in the ResourceHandlerCache.ResourceValue.
>
> I have attached a patch that does the same and would like your feedback on
> my proposal.
> These patches are from src taken from Apache MyFaces 2.0.5
>
> -cheers,
> Rohit Kelapure,
> Apache Open WebBeans committer
>