You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Simone Tripodi <si...@gmail.com> on 2010/01/24 16:45:34 UTC

[Cocoon 3] Optimizing resources creation on SAX pipeline components

Hi all guys,
I'd like to improve a little the resources creation into C3 SAX pipelines
components, saving consumed memory and components initialization time,
reusing already created resources.
I mean, instantiating the same kind of XSLTTransformer (or the
SchemaProcessorTransformer) twice, in different parts of the application,
with the same resource:

class Service1 {

    XSLTTransformer xsltTransformer =
new XSLTTransformer(this.getClass().getResource("myStyle.xsl"));
    ...
}

class Service2 {
    XSLTTransformer xsltTransformer =
new XSLTTransformer(this.getClass().getResource("myStyle.xsl"));
    ...
}

causes the "myStyle.xsl" resource has to be load twice, consuming memory. As
proposed time ago - also mentioned by Sylvain - I'd like to introduce an
InMemoryLRU cache that stores and maintains already loaded resources.

What do you think about it? It's a simple improvement I can realize quickly
and that's not hard to integrate in the existing code, obviously any kind of
help and suggestion is more than welcome! :)
Best regards,
Simo

http://people.apache.org/~simonetripodi/

Re: [Cocoon 3] Optimizing resources creation on SAX pipeline components

Posted by Reinhard Pötz <re...@apache.org>.
Simone Tripodi wrote:
> Hi Reinhard,
> Thanks for your reply! I wouldn't add a dependency but rather using a
> simple yet powerful ad-hoc implementation based on LinkedhashMap that
> allows realizing a memory based LRU cache, I already provided an
> implementation in Apache Commons Sandbox[1]. If you agree I can start
> adding it and modifying the components.

The question is whether we want this store to become a pluggable
component. In Cocoon 2.x it was configurable but I have never seen
another configuration but using an in-memory store for caching XSLT
templates.

Anyway, I suggest that you start with the implementation and we discuss
configuration issues afterwards.

> About making the mentioned components as CachingPipelineComponent: do
> you have any hint you can suggest to me please? I'd more than pleased to
> working on it!

See the org.apache.cocoon.transformation.TraxTransformer in Cocoon 2.2
and the implementation of getKey() and getValidity().
The tricky thing is that an XSLT stylesheet can have imports and
includes that can change too.

-- 
Reinhard Pötz                           Managing Director, {Indoqa} GmbH
                         http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member                  reinhard@apache.org
________________________________________________________________________

Re: [Cocoon 3] Optimizing resources creation on SAX pipeline components

Posted by Simone Tripodi <si...@gmail.com>.
Hi Reinhard,
Thanks for your reply! I wouldn't add a dependency but rather using a simple
yet powerful ad-hoc implementation based on LinkedhashMap that allows
realizing a memory based LRU cache, I already provided an implementation in
Apache Commons Sandbox[1]. If you agree I can start adding it and modifying
the components.

About making the mentioned components as CachingPipelineComponent: do you
have any hint you can suggest to me please? I'd more than pleased to working
on it!
Thanks in advance, best regards!!!
Simo

[1]
https://svn.apache.org/repos/asf/commons/sandbox/at-digester/trunk/src/java/org/apache/commons/digester/annotations/utils/InMemoryLRUCache.java

http://people.apache.org/~simonetripodi/


On Mon, Jan 25, 2010 at 8:20 AM, Reinhard Pötz <re...@apache.org> wrote:

> Simone Tripodi wrote:
> > Hi all guys,
> > I'd like to improve a little the resources creation into C3 SAX
> > pipelines components, saving consumed memory and components
> > initialization time, reusing already created resources.
> > I mean, instantiating the same kind of XSLTTransformer (or the
> > SchemaProcessorTransformer) twice, in different parts of the
> > application, with the same resource:
> >
> > class Service1 {
> >
> >     XSLTTransformer xsltTransformer =
> > new XSLTTransformer(this.getClass().getResource("myStyle.xsl"));
> >     ...
> > }
> >
> > class Service2 {
> >     XSLTTransformer xsltTransformer =
> > new XSLTTransformer(this.getClass().getResource("myStyle.xsl"));
> >     ...
> > }
> >
> > causes the "myStyle.xsl" resource has to be load twice, consuming
> > memory. As proposed time ago - also mentioned by Sylvain - I'd like to
> > introduce an InMemoryLRU cache that stores and maintains already loaded
> > resources.
> >
> > What do you think about it? It's a simple improvement I can realize
> > quickly and that's not hard to integrate in the existing code, obviously
> > any kind of help and suggestion is more than welcome! :)
>
> Yes, improvements in that area are very appreciated. What solution (api)
> do you propose?
>
> And when we are at it, it would also be great to support the
> CachingPipelineComponent interface in the XSLTTransformer and the
> SchemaProcessorTransformer.
>
> --
> Reinhard Pötz                           Managing Director, {Indoqa} GmbH
>                         http://www.indoqa.com/en/people/reinhard.poetz/
>
> Member of the Apache Software Foundation
> Apache Cocoon Committer, PMC member                  reinhard@apache.org
> ________________________________________________________________________
>

Re: [Cocoon 3] Optimizing resources creation on SAX pipeline components

Posted by Reinhard Pötz <re...@apache.org>.
Simone Tripodi wrote:
> Hi all guys,
> I'd like to improve a little the resources creation into C3 SAX
> pipelines components, saving consumed memory and components
> initialization time, reusing already created resources.
> I mean, instantiating the same kind of XSLTTransformer (or the
> SchemaProcessorTransformer) twice, in different parts of the
> application, with the same resource:
> 
> class Service1 {
> 
>     XSLTTransformer xsltTransformer =
> new XSLTTransformer(this.getClass().getResource("myStyle.xsl"));
>     ...
> }
> 
> class Service2 {
>     XSLTTransformer xsltTransformer =
> new XSLTTransformer(this.getClass().getResource("myStyle.xsl"));
>     ...
> }
> 
> causes the "myStyle.xsl" resource has to be load twice, consuming
> memory. As proposed time ago - also mentioned by Sylvain - I'd like to
> introduce an InMemoryLRU cache that stores and maintains already loaded
> resources.
> 
> What do you think about it? It's a simple improvement I can realize
> quickly and that's not hard to integrate in the existing code, obviously
> any kind of help and suggestion is more than welcome! :)

Yes, improvements in that area are very appreciated. What solution (api)
do you propose?

And when we are at it, it would also be great to support the
CachingPipelineComponent interface in the XSLTTransformer and the
SchemaProcessorTransformer.

-- 
Reinhard Pötz                           Managing Director, {Indoqa} GmbH
                         http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member                  reinhard@apache.org
________________________________________________________________________