You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Donald Ball <ba...@webslingerZ.com> on 2001/01/18 06:16:46 UTC

idle thoughts in caching in c2

when an environment is processed by a sitemap, a new ResourcePipeline is
constructed, then the environment is associated with a pipeline in the
sitemap, and the ResourcePipeline is configured to match that pipeline,
and the environment is processed by the pipeline object.

to add caching behavior, the first thing to do is re-use ResourcePipeline
objects. for instance, if this (generated) test is successful:

if ((map = wildcardMatch(matcher_wildcard_N138_expr,objectModel)) != null) {

we should operate on ResourcePipeline_N138, or a clone thereof if it's not
threadsafe. The ResourcePipeline should store the results of each of its
stages (let's call those results snapshots) when the following criteria
are met:

1. it is likely that the snapshot will be valid for another Environment

2. the cost of matching an Environment to a snapshot plus the cost of
determining if the snapshot is not stale plus the cost of retieving the
snapshot from storage is less than the cost of generating the snapshot
anew

for a first pass, i think we can assume that (1) will be true for
components like the FileGenerator, but not true for components like the
ServerPagesGenerator. in another iteration, perhaps we can define some way
in which server pages and other dynamic components can tell the sitemap
what environmental conditions cause their results to vary (e.g. a specific
request parameter and a specific cookie), but i think that would just add
complexity right now.

cacheable components could be wrapped with a general purpose component
wrapper, which would take its incoming SAX events, store them in some
fashion (using XMLCompiler maybe?), and retrieve them on demand. the
underlying component would have to provide a method by which the wrapper
component could determine if its stored snapshot was valid for a given
environment.

snapshots would be referenced via strong references if they're frequently
used, and downgraded to soft references if the cache gets larger than
desired. any number of algorithms could be used to decide which snapshot
references to soften, and it should be easy to change algorithms.

so good so far? i reckon this is a fairly obvious approach to those
experienced c2 developers who've given any thought to this. anyone see any
holes in it? worth taking any further?

- donald


Re: idle thoughts in caching in c2

Posted by Donald Ball <ba...@webslingerZ.com>.
On Mon, 22 Jan 2001, Giacomo Pati wrote:

> > * Sergio Carvalho (scarvalho@criticalsoftware.com) wrote :
> > > On Fri, 19 Jan 2001 13:44:42 -0500 (EST)
> > > Donald Ball <ba...@webslingerZ.com> wrote:
> > > > do you mean that the caching components should be explicitly put in the
> > > > pipeline in the sitemap:
> > > >
> > > > <map:cache type="lru"/>
> > > Yes. A Cache interface could be defined, so that classes implementing
> > > caching are identified. Then, these are placed in the pipeline,
> > > between each data-producer (or processor) and the subsequent
> > > data-consumer.
> >
> > That makes sense.
>
> Are you sure? Is a sitemap maintainer skilled to specify where to cache
> intermediate pipeline results? I doubt.

that's my worry, honestly.

- donald


Re: idle thoughts in caching in c2

Posted by Paul Russell <pa...@luminas.co.uk>.
* Giacomo Pati (giacomo@apache.org) wrote :
> Paul Russell wrote:
> > * Sergio Carvalho (scarvalho@criticalsoftware.com) wrote :
> > > On Fri, 19 Jan 2001 13:44:42 -0500 (EST)
> > > Donald Ball <ba...@webslingerZ.com> wrote:
> > > > do you mean that the caching components should be explicitly put in the
> > > > pipeline in the sitemap:
> > > > <map:cache type="lru"/>
> > > Yes. A Cache interface could be defined, so that classes implementing
> > > caching are identified. Then, these are placed in the pipeline,
> > > between each data-producer (or processor) and the subsequent
> > > data-consumer.
> > That makes sense. 
> Are you sure? Is a sitemap maintainer skilled to specify where to cache
> intermediate pipeline results? I doubt.

If a sitemap manager isn't, who is? The sitemap managers' job is very
definately a skilled position.

I am more than happy that the sitemap should decide on caching policies
when we can either:
 * get to the point that either we can write sensible heuristics
   for this;
 * write sensible learning algorithms to let the system decide on
   the parameters for caching.
   
However, I think we should give sitemap managers the option to override
these decisions, in case we (or the programs we write) get it wrong. I'd
be interested in how other people visualise this? Should we make it
*totally* explicit (I'm -0 on this -- I'd rather we let the engine
'play'), should we make it totally implicit (and risk sub-optimal
performance)? Anything else?


P.

-- 
Paul Russell                                 Email:   paul@luminas.co.uk
Technical Director                             Tel:  +44 (0)20 8553 6622
Luminas Internet Applications                  Fax:  +44 (0)870 28 47489
This is not an official statement or order.    Web:    www.luminas.co.uk

Re: idle thoughts in caching in c2

Posted by Giacomo Pati <gi...@apache.org>.
Paul Russell wrote:
> 
> * Sergio Carvalho (scarvalho@criticalsoftware.com) wrote :
> > On Fri, 19 Jan 2001 13:44:42 -0500 (EST)
> > Donald Ball <ba...@webslingerZ.com> wrote:
> > > do you mean that the caching components should be explicitly put in the
> > > pipeline in the sitemap:
> > >
> > > <map:cache type="lru"/>
> > Yes. A Cache interface could be defined, so that classes implementing
> > caching are identified. Then, these are placed in the pipeline,
> > between each data-producer (or processor) and the subsequent
> > data-consumer.
> 
> That makes sense. 

Are you sure? Is a sitemap maintainer skilled to specify where to cache
intermediate pipeline results? I doubt.

Giacomo

> Would we then stick a binary cache on the output
> regardless, or should that be explicit too? (Or do we not put a binary
> cache on at all, and leave it to an http level cache?)
> 
> Paul.
> 
> --
> Paul Russell                                 Email:   paul@luminas.co.uk
> Technical Director                             Tel:  +44 (0)20 8553 6622
> Luminas Internet Applications                  Fax:  +44 (0)870 28 47489
> This is not an official statement or order.    Web:    www.luminas.co.uk
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org

Re: AW: [C2]: Proposal for caching

Posted by Sergio Carvalho <sc...@criticalsoftware.com>.
On Thu, 25 Jan 2001 08:19:31 -0500
Berin Loritsch <bl...@apache.org> wrote:

<snip/>
> FileGenerator {
>    Validator validator = new FileChangedValidator();
> 
>    ......
>  
>    generate() {
>       if (validator.hasChanged(file) {
>           // normal processing
>       } else {
>           // retrieve from cache.
>       }
>    }
> }

No, I don't like this. Imagining that every component must have this generate() code with cache handling in there seems awkward. A component just has to be able to tell if it's dirty. If it is not, then Cocoon handles cache retrieving.

And yes, Validator substitution is important. It does not clutter the sitemap as most of the times the default Validator is used. When you do need a different Validator, it's definitely better to be able to change it on the sitemap instead of subclassing the Generator just to replace the Validator. 

> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org
> 


-- 
--
Sergio Carvalho
---------------
scarvalho@criticalsoftware.com

If at first you don't succeed, skydiving is not for you

Re: AW: [C2]: Proposal for caching

Posted by Tagunov Anthony <at...@nnt.ru>.
On Thu, 25 Jan 2001 08:19:31 -0500, Berin Loritsch wrote:

>Carsten Ziegeler wrote:
>
>> OK, now I get what you meant. I think it is really a good idea. It would
>> lead to a repository of possible, configurable validators (equivalent
>> to the repository of generators, transformers etc.) and the sitemap
>> designer chooses the right validator for the component.
>> But it is not possible to write validators which are usable for any
>> component as only the component knows which data to test. So you
>> have a tight coupling between a component and its validators.
>
>If there is a tight coupling between validators, then we need to look at
>coupling them.  More down below.
>
>> Quickly thinking I see a possible solution:
>> Each component declares his own usable validators which can only be used
>> with this component:
>> 
>> <map:generators>
>>     <map:generator label="content" name="file" src="org.apache.cocoon.generation.FileGenerator">
>>         <map:validators>
>>            <map:validator name="fileChangedValidator" class ="org.apache.cocoon.validation.FileChangedValidator"/>
>>            ....
>>         </map:validators>
>>     </map:generator>
>> <map:generators>
>> ...
>>    <map:match="test">
>>      <map:generate src="http://myserver/resource.xml"
>>           type="http"
>>            validator="fileChangedValidator">
>>      </map:generate>
>>       ...
>>    </map:match>
>> 
>> What do you think about this?
>
>I think that modifying the sitemap like this only serves to make
>things more confusing or at least cluttered.  I understand the
>idea of swapping Validators, but I think that might be flexibility
>syndrome.  How many ways is a FileGenerator going to invalidate
>a cache entry for a File?  I do think they should be external
>components, but I also think that they should be hard-wired to
>the Component.
>
>FileGenerator {
>   Validator validator = new FileChangedValidator();
>
>   ......
> 
>   generate() {
>      if (validator.hasChanged(file) {
>          // normal processing
>      } else {
>          // retrieve from cache.
>      }
>   }
>}
>

Feel a little awkward to object (I'm a lurker :), but actully because of this we maybe will have
to derive our own implementations of Components, just to change the caching policy.

Plz, see my prev e-mail with our use-case and how we changed the caching policy
for XInclude from URL-s. BTW: as for databases, I feel very much that my
components should be able to accept some kind of "INVALIDATE" singnal from outside,
called when a particular table in the DB gets changed.. I'm not sure on how to do it,
maybe, provide some CORBA interface for my Cocon component, EJB interface,
or explore CRUDLET architecture, but for me it is very desireable to have FLEXIBLE
caching policy.. BTW: even for a File we can imaging using the "hard"/"soft"+timeout
caching policy we have developed for URL's (see my prev e-mail). 

Best regards, Tagunov Anthony

P.S. Someone on the list has spoken of some "OO" way of caching and lots of 
flexibility connected with it. Sorry, can't find that e-mail, what was it?



AW: [C2]: Proposal for caching

Posted by Carsten Ziegeler <cz...@sundn.de>.
> Berin Loritsch wrote
> > OK, now I get what you meant. I think it is really a good idea. It would
> > lead to a repository of possible, configurable validators (equivalent
> > to the repository of generators, transformers etc.) and the sitemap
> > designer chooses the right validator for the component.
> > But it is not possible to write validators which are usable for any
> > component as only the component knows which data to test. So you
> > have a tight coupling between a component and its validators.
> 
> If there is a tight coupling between validators, then we need to look at
> coupling them.  More down below.
> 
> > Quickly thinking I see a possible solution:
> > Each component declares his own usable validators which can only be used
> > with this component:
> > 
> > <map:generators>
> >     <map:generator label="content" name="file" 
> src="org.apache.cocoon.generation.FileGenerator">
> >         <map:validators>
> >            <map:validator name="fileChangedValidator" class 
> ="org.apache.cocoon.validation.FileChangedValidator"/>
> >            ....
> >         </map:validators>
> >     </map:generator>
> > <map:generators>
> > ...
> >    <map:match="test">
> >      <map:generate src="http://myserver/resource.xml"
> >           type="http"
> >            validator="fileChangedValidator">
> >      </map:generate>
> >       ...
> >    </map:match>
> > 
> > What do you think about this?
> 
> I think that modifying the sitemap like this only serves to make
> things more confusing or at least cluttered.  I understand the
> idea of swapping Validators, but I think that might be flexibility
> syndrome.  How many ways is a FileGenerator going to invalidate
> a cache entry for a File?  I do think they should be external
> components, but I also think that they should be hard-wired to
> the Component.
> 
> FileGenerator {
>    Validator validator = new FileChangedValidator();
> 
>    ......
>  
>    generate() {
>       if (validator.hasChanged(file) {
>           // normal processing
>       } else {
>           // retrieve from cache.
>       }
>    }
> }
> 
OK, perhaps a file generator is a bad example, lets take the SQLTransformer.
There might be different use cases for it:
- The content is invald every day at 6 in the morning
- The content is valid four 3 hours
- On weekdays the content is valid for 2 hours and never changes on sat./sun.
Perhaps this is FS using different validator classes. My first thoughts
were, that there is a base abstract ValidatorClass which can handle all of that
above. Each component is coupled with its own validator (like in your example 
above) and it can (not must) be configured in the sitemap:
    <map:match="test">
     <map:generate src="http://myserver/resource.xml" type="http">
		<map:parameter name="validator_valid_period" value="3 hours"/>
     </map:generate>
            or
     <map:generate src="http://myserver/resource.xml" type="http">
		<map:parameter name="validator_invalidate_at" value="6 in the morning"/>
     </map:generate>      ...
   </map:match>
But in this case it is required that each validator has some basic functions like
them above.
I like this approach more than the pool of validators as the sitemap designer
has not to care about validators. He uses only some simple parameters.
The pool-approach is more flexible and allows custom validators which can do
whatever they want.


Carsten


Re: AW: [C2]: Proposal for caching

Posted by Berin Loritsch <bl...@apache.org>.
Carsten Ziegeler wrote:

> OK, now I get what you meant. I think it is really a good idea. It would
> lead to a repository of possible, configurable validators (equivalent
> to the repository of generators, transformers etc.) and the sitemap
> designer chooses the right validator for the component.
> But it is not possible to write validators which are usable for any
> component as only the component knows which data to test. So you
> have a tight coupling between a component and its validators.

If there is a tight coupling between validators, then we need to look at
coupling them.  More down below.

> Quickly thinking I see a possible solution:
> Each component declares his own usable validators which can only be used
> with this component:
> 
> <map:generators>
>     <map:generator label="content" name="file" src="org.apache.cocoon.generation.FileGenerator">
>         <map:validators>
>            <map:validator name="fileChangedValidator" class ="org.apache.cocoon.validation.FileChangedValidator"/>
>            ....
>         </map:validators>
>     </map:generator>
> <map:generators>
> ...
>    <map:match="test">
>      <map:generate src="http://myserver/resource.xml"
>           type="http"
>            validator="fileChangedValidator">
>      </map:generate>
>       ...
>    </map:match>
> 
> What do you think about this?

I think that modifying the sitemap like this only serves to make
things more confusing or at least cluttered.  I understand the
idea of swapping Validators, but I think that might be flexibility
syndrome.  How many ways is a FileGenerator going to invalidate
a cache entry for a File?  I do think they should be external
components, but I also think that they should be hard-wired to
the Component.

FileGenerator {
   Validator validator = new FileChangedValidator();

   ......
 
   generate() {
      if (validator.hasChanged(file) {
          // normal processing
      } else {
          // retrieve from cache.
      }
   }
}

RE: [C2]: Proposal for caching

Posted by Torsten Curdt <tc...@dff.st>.
> Hi all,
> 
> is noone else except Sergio and me interested in having a 
> caching mechanism? 

No, me too, me too!!
Unfortunately I don't have enough insight for useful comments.
I guess this applies to some other lurkers as well ;)

Keep it up :)
--
Torsten

AW: [C2]: Proposal for caching

Posted by Carsten Ziegeler <cz...@sundn.de>.
Hi all,

is noone else except Sergio and me interested in having a 
caching mechanism? 
I repeat it: I have NOW time to do some work, but WE need
a concept which all agree on. So please join in and give
your comments. Personally I would like some "+1"s to
start :-)...

> Sergio Carvalho wrote:
> 
> I agree with you, *if* we can't make the assumption that 
> transformers depend only on their XML input. I am really treading 
> on unkown territory here, as I don't know C2 basic design 
> principles. If transformers get data from sources other than 
> those declared in the sitemap, you are 100% right. If, on the 
> other hand, transformers get data from sources declared on the 
> sitemap, then you can check if sources are dirty and deduce when 
> the transformer's output is dirty. And you can cache only the 
> final result on the pipeline. Aggregators aggregate pipelines, so 
> each aggregated pipeline has a cache.
> 
Some transformers get data from sources other than those declared in 
the sitemap ,e.g the SQLTransformer or the XIncludeTransformer.
Especially for the SQLTransformer it is not visible in the sitemap
where the data comes from. If someone can judge if the content has 
changed in this case the transformer is the one.
The scheme applies for all transformer which get "external" data,
e.g. a transformer for querying EJBs, doing RMI, Corba etc.
>....
> Our discussion really revolves around what is a transformer. Can 
> a transformer get data on its own, or is all data fed by Cocoon 
> to the transformer? This applies to  question 8 also. 
> 
Yes, I agree. I think the scenario above gives the answer.
Perhaps some other can help us out here?
>... 
> Why wondering which parameters you may want to pass to the 
> validator when you can just replace the whole validator if you 
> design it to be replaceable. Something like:
>   <map:match="test">
>     <map:generate src="http://myserver/resource.xml" type="http">
>         <parameter name="validator_class" 
> value="com.criticalsoftware.web.FooBarValidator"/>
>     </map:generate>
> What do you have against this?
>
OK, now I get what you meant. I think it is really a good idea. It would
lead to a repository of possible, configurable validators (equivalent
to the repository of generators, transformers etc.) and the sitemap
designer chooses the right validator for the component.
But it is not possible to write validators which are usable for any 
component as only the component knows which data to test. So you
have a tight coupling between a component and its validators.

Quickly thinking I see a possible solution:
Each component declares his own usable validators which can only be used
with this component:

<map:generators>
    <map:generator label="content" name="file" src="org.apache.cocoon.generation.FileGenerator">
        <map:validators>
           <map:validator name="fileChangedValidator" class ="org.apache.cocoon.validation.FileChangedValidator"/>
           ....
        </map:validators>
    </map:generator>
<map:generators>
...
   <map:match="test">
     <map:generate src="http://myserver/resource.xml" 
          type="http" 
           validator="fileChangedValidator">
     </map:generate>
      ...
   </map:match>

What do you think about this?

Carsten


Re: AW: [C2]: Proposal for caching

Posted by Sergio Carvalho <sc...@criticalsoftware.com>.
On Wed, 24 Jan 2001 08:24:49 +0100
"Carsten Ziegeler" <cz...@sundn.de> wrote:

> > > 2. The most static part of the pipeline should be cached.
> > ?!? The end result should be cached. 
>
> If only the end result is cached, many pipelines would never be cached,
> as the pipeline is only "static" up to a specific point.
> Imagine a pipeline with a generator, four transformer and one serializer
> at the end. The generator reads a static file, the first three transformers
> do "static" transformations and only the forth is dynamic.
> Then it would be possible to cach the result of the generator and the
> three transformations. 
> This approach is necessary for content aggreation, as there is no serializer
> at the end of each pipeline.

I agree with you, *if* we can't make the assumption that transformers depend only on their XML input. I am really treading on unkown territory here, as I don't know C2 basic design principles. If transformers get data from sources other than those declared in the sitemap, you are 100% right. If, on the other hand, transformers get data from sources declared on the sitemap, then you can check if sources are dirty and deduce when the transformer's output is dirty. And you can cache only the final result on the pipeline. Aggregators aggregate pipelines, so each aggregated pipeline has a cache.

> > 
> > > 4. If a component is cacheable it should implement an interface 
> > Cacheable.
> > > 5. Caching is done until the first component in the pipeline is 
> > not Cacheable.
> > Rephrasing: Caching is done if every component in the pipeline is 
> > Cacheable. Remember, no caching on each stage.
> OK, I didn't mean caching on each stage, see point 2 for an example. 
> The caching is not done at each stage, only at one specific stage in 
> the pipeline. Until this stage the content is "more" static than
> in the rest of the pipeline.
> But this stage is not necessarily the last stage after the serializer.
>

It should be the last stage, but that is a design decision that is probably done by now. We just need to check if generators depend only on their declared inputs. It is crucial.


> > 
> > > 6. Identifying if the cache contains the response (or the most 
> > static part
> > >    of it) can be done by a unique key. The Cacheable interface 
> > implements
> > >    a getKey() method. The keys of all Cacheable components are 
> > chained together
> > >    and build the unique key for the cache.
> > -1. If Stuart is right, and transformers' output depends only on 
> > their input, then you just need to check the inputs, and you just 
> > need to cache the final output.
> Ok, in some way the transformers output depends only on their input.
> But what is the input of a transformer? On the one hand the XML stream,
> which comes from the previous component in the pipeline.
> But e.g. the SQL Transformer fetches data from a database. The XML 
> stream for specifying which table and rows to fetch is static and 
> changes never. So the XML stream is static. But the result of the
> fetch changes over time as the data in the database changes.
> So this "input" can be highly dynamic. 

Our discussion really revolves around what is a transformer. Can a transformer get data on its own, or is all data fed by Cocoon to the transformer? This applies to  question 8 also. 


> > 
> > > 7. Cacheable also delivers a Validator object (getValidator()) 
> > which contains all
> > >    information required for this component to test if the 
> > content has changed
> > >    since the last caching.
> > >    The FileGenerator e.g. puts the last modification date into 
> > the Validator.
> > >    The Cache stores all Validators together with the unique key.
> > +1. I'd like to see a setValidator also, so that the Validator 
> > can be overriden.
> > 
> > 
> > > 8. All Cacheable components are now asked hasChanged(Validator). If all
> > >    respond with false, the cache value is valid and is used. 
> > >    If the first responds with true, a new response is 
> > generated, the validators 
> >    are get and the result is put in the cache.
> > 
> > -1. See 6. Only the inputs (generators) must be checked.
> > 
> I disagree, see 6. and also the RT for caching: 
> http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=97300662426038&w=2)
> and some of the mails from the XSP Generator task:
> http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=97661659323627&w=2
> 
> > > 
> > > This approach is very flexible. Each component nows if it is 
> > cacheable and when
> > > it is invalid. Using the Validator object it is possible to 
> > specify something 
> > > like: This component is really 6 hours valid wether it changes or not.
> > 
> > Please, allow the Validator to be overriden. I'm imagining 
> > situations like an HTTPGenerator where the Generator doesn't know 
> > if it is valid and can only safely assume it is not. In these 
> > cases, there are situations where I'd like to override this 
> > default behaviour.
> OK, can you please explane, who exactly will override this behaviour.
> I could imagine a configuration for the HTTPGenerator which 
> configures the way the Validator is build. E.g. a simple approach would
> be, that the HTTPGenerator only reads the input once and assumes that
> that is static. A configuration (or better a parameter in the pipeline)
> could tell the HTTPGenerator that a specific HTTP request is not
> static, but changes all 3 hours, so it could look like:
> <map:match="test">
>     <map:generate src="http://myserver/resource.xml" type="http">
>         <parameter name="content_validation_period" value="3 hourse"/>
>     </map:generate>
> 
> The validator object would contain the last time, the HTTP request was
> done, checks if the 3 hours have expired since then and responds
> according to this information to the hasChanged() method.
> 
> The same configuration is possible/usable for transformers, e.g. the
> SQL Transformer. The SQL Transformer knows, when to refetch data
> from a database by a configuration.

Why wondering which parameters you may want to pass to the validator when you can just replace the whole validator if you design it to be replaceable. Something like:
  <map:match="test">
    <map:generate src="http://myserver/resource.xml" type="http">
        <parameter name="validator_class" value="com.criticalsoftware.web.FooBarValidator"/>
    </map:generate>
What do you have against this?

-- 
Sergio Carvalho
---------------
scarvalho@criticalsoftware.com

If at first you don't succeed, skydiving is not for you

Re: [C2]: Proposal for caching

Posted by Tagunov Anthony <at...@nnt.ru>.
And getValidator() also might becom a member of the Dinamic interface? ---

--- definetly NO:  cause Dinamic are those components that have inputs other then official XML ins..




Re: [C2]: Proposal for caching

Posted by Tagunov Anthony <at...@nnt.ru>.
On Sat, 27 Jan 2001 23:45:33 +0300, Tagunov Anthony wrote:

>On Tue, 23 Jan 2001 17:08:13 +0000, Sergio Carvalho wrote:
>
>>> 6. Identifying if the cache contains the response (or the most static part
>>>    of it) can be done by a unique key. The Cacheable interface implements
>>>    a getKey() method. The keys of all Cacheable components are chained together
>>>    and build the unique key for the cache.
>>-1. If Stuart is right, and transformers' output depends only on their input, then you just need to check the inputs, and you just need to cache the final 
output.
>Please excuse my boldness, but those that are dinamic transformes also should be quired. 
>[RT]: maybe the component is static or dinamic not judging by isDinamic(), but have some
>label interface Dinamic (actually empty) and for components that are]
>instanceof Dinamic perform the query?

So getKey() might be a method of Dinamic interface.
And getValidator() also might becom a member of the Dinamic interface?

Hmm.. intresting thing.. looks like even the XSLT processor, if it get access to 
request parameters, cookies and http headers as it did for C1 becomes dinamic in
this sence and should return getKey()!! 

Tricky but I think this would be even beautifull!


(Or we could regturn getKey()== null if are not actually dinamic.)

Again Tagunov Anthony



Re: [C2]: Proposal for caching

Posted by Tagunov Anthony <at...@nnt.ru>.
On Tue, 23 Jan 2001 17:08:13 +0000, Sergio Carvalho wrote:

>> 6. Identifying if the cache contains the response (or the most static part
>>    of it) can be done by a unique key. The Cacheable interface implements
>>    a getKey() method. The keys of all Cacheable components are chained together
>>    and build the unique key for the cache.
>-1. If Stuart is right, and transformers' output depends only on their input, then you just need to check the inputs, and you just need to cache the final output.
Please excuse my boldness, but those that are dinamic transformes also should be quired. 
[RT]: maybe the component is static or dinamic not judging by isDinamic(), but have some
label interface Dinamic (actually empty) and for components that are]
instanceof Dinamic perform the query?



AW: [C2]: Proposal for caching

Posted by Carsten Ziegeler <cz...@sundn.de>.
> Sergio Carvalho wrote:
> > 
> > 1. Caching should not take place after each stage in the pipeline.
> +1. 
> 
> Caching should take place at the end of every simple pipeline. 
> Content aggregation causes the aggregation of several simple 
> pipelines, and each of these must have a separate cache, or else 
> the invalidation of one of these invalidates all the others -- 
> Not Good(TM)
> 
> > 2. The most static part of the pipeline should be cached.
> ?!? The end result should be cached. 
If only the end result is cached, many pipelines would never be cached,
as the pipeline is only "static" up to a specific point.
Imagine a pipeline with a generator, four transformer and one serializer
at the end. The generator reads a static file, the first three transformers
do "static" transformations and only the forth is dynamic.
Then it would be possible to cach the result of the generator and the
three transformations. 
This approach is necessary for content aggreation, as there is no serializer
at the end of each pipeline.
> 
> > 3. The logic for caching is either in the ResourcePipeline or "above"
> The logic that decides if the result has changed should be on the 
> producer(s) and should be overridable.
Producer? Do you mean generator (the C2 equivalent of a producer)?
I didn't mean the logic for hasChanged, but the logic which calls all
hasChanged and all the other methods required.
> 
> > 4. If a component is cacheable it should implement an interface 
> Cacheable.
> > 5. Caching is done until the first component in the pipeline is 
> not Cacheable.
> Rephrasing: Caching is done if every component in the pipeline is 
> Cacheable. Remember, no caching on each stage.
OK, I didn't mean caching on each stage, see point 2 for an example. 
The caching is not done at each stage, only at one specific stage in 
the pipeline. Until this stage the content is "more" static than
in the rest of the pipeline.
But this stage is not necessarily the last stage after the serializer.
> 
> > 6. Identifying if the cache contains the response (or the most 
> static part
> >    of it) can be done by a unique key. The Cacheable interface 
> implements
> >    a getKey() method. The keys of all Cacheable components are 
> chained together
> >    and build the unique key for the cache.
> -1. If Stuart is right, and transformers' output depends only on 
> their input, then you just need to check the inputs, and you just 
> need to cache the final output.
Ok, in some way the transformers output depends only on their input.
But what is the input of a transformer? On the one hand the XML stream,
which comes from the previous component in the pipeline.
But e.g. the SQL Transformer fetches data from a database. The XML 
stream for specifying which table and rows to fetch is static and 
changes never. So the XML stream is static. But the result of the
fetch changes over time as the data in the database changes.
So this "input" can be highly dynamic. 
> 
> > 7. Cacheable also delivers a Validator object (getValidator()) 
> which contains all
> >    information required for this component to test if the 
> content has changed
> >    since the last caching.
> >    The FileGenerator e.g. puts the last modification date into 
> the Validator.
> >    The Cache stores all Validators together with the unique key.
> +1. I'd like to see a setValidator also, so that the Validator 
> can be overriden.
> 
> 
> > 8. All Cacheable components are now asked hasChanged(Validator). If all
> >    respond with false, the cache value is valid and is used. 
> >    If the first responds with true, a new response is 
> generated, the validators 
>    are get and the result is put in the cache.
> 
> -1. See 6. Only the inputs (generators) must be checked.
> 
I disagree, see 6. and also the RT for caching: 
http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=97300662426038&w=2)
and some of the mails from the XSP Generator task:
http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=97661659323627&w=2

> > 
> > This approach is very flexible. Each component nows if it is 
> cacheable and when
> > it is invalid. Using the Validator object it is possible to 
> specify something 
> > like: This component is really 6 hours valid wether it changes or not.
> 
> Please, allow the Validator to be overriden. I'm imagining 
> situations like an HTTPGenerator where the Generator doesn't know 
> if it is valid and can only safely assume it is not. In these 
> cases, there are situations where I'd like to override this 
> default behaviour.
OK, can you please explane, who exactly will override this behaviour.
I could imagine a configuration for the HTTPGenerator which 
configures the way the Validator is build. E.g. a simple approach would
be, that the HTTPGenerator only reads the input once and assumes that
that is static. A configuration (or better a parameter in the pipeline)
could tell the HTTPGenerator that a specific HTTP request is not
static, but changes all 3 hours, so it could look like:
<map:match="test">
    <map:generate src="http://myserver/resource.xml" type="http">
        <parameter name="content_validation_period" value="3 hourse"/>
    </map:generate>

The validator object would contain the last time, the HTTP request was
done, checks if the 3 hours have expired since then and responds
according to this information to the hasChanged() method.

The same configuration is possible/usable for transformers, e.g. the
SQL Transformer. The SQL Transformer knows, when to refetch data
from a database by a configuration.


Carsten


Re: [C2]: Proposal for caching

Posted by Sergio Carvalho <sc...@criticalsoftware.com>.
On Tue, 23 Jan 2001 17:21:02 +0100
"Carsten Ziegeler" <cz...@sundn.de> wrote:
 
> OK, lets start:
> 
> 1. Caching should not take place after each stage in the pipeline.
+1. 

Caching should take place at the end of every simple pipeline. Content aggregation causes the aggregation of several simple pipelines, and each of these must have a separate cache, or else the invalidation of one of these invalidates all the others -- Not Good(TM)

> 2. The most static part of the pipeline should be cached.
?!? The end result should be cached. 

> 3. The logic for caching is either in the ResourcePipeline or "above"
The logic that decides if the result has changed should be on the producer(s) and should be overridable.

> 4. If a component is cacheable it should implement an interface Cacheable.
> 5. Caching is done until the first component in the pipeline is not Cacheable.
Rephrasing: Caching is done if every component in the pipeline is Cacheable. Remember, no caching on each stage.

> 6. Identifying if the cache contains the response (or the most static part
>    of it) can be done by a unique key. The Cacheable interface implements
>    a getKey() method. The keys of all Cacheable components are chained together
>    and build the unique key for the cache.
-1. If Stuart is right, and transformers' output depends only on their input, then you just need to check the inputs, and you just need to cache the final output.

> 7. Cacheable also delivers a Validator object (getValidator()) which contains all
>    information required for this component to test if the content has changed
>    since the last caching.
>    The FileGenerator e.g. puts the last modification date into the Validator.
>    The Cache stores all Validators together with the unique key.
+1. I'd like to see a setValidator also, so that the Validator can be overriden.


> 8. All Cacheable components are now asked hasChanged(Validator). If all
>    respond with false, the cache value is valid and is used. 
>    If the first responds with true, a new response is generated, the validators >    are get and the result is put in the cache.

-1. See 6. Only the inputs (generators) must be checked.

> 
> This approach is very flexible. Each component nows if it is cacheable and when
> it is invalid. Using the Validator object it is possible to specify something 
> like: This component is really 6 hours valid wether it changes or not.

Please, allow the Validator to be overriden. I'm imagining situations like an HTTPGenerator where the Generator doesn't know if it is valid and can only safely assume it is not. In these cases, there are situations where I'd like to override this default behaviour.



--
Sergio Carvalho
---------------
scarvalho@criticalsoftware.com

If at first you don't succeed, skydiving is not for you

[C2]: Proposal for caching

Posted by Carsten Ziegeler <cz...@sundn.de>.
Hi,

as I and some others  are willing to implement a caching mechanism for C2
I would like to force the implementation of it by starting a proposal.
If we have finished the proposal, it could be implemented and then
we have a solution which could be prooved.

I reread all (or nearly) all of the mails regarding caching, most of them
were send in December. The comments, thoughs and proposals contained in the
mails lead me to this proposal, which is more or less a summary of what was
discussed then (I hope so at least)....

OK, lets start:

1. Caching should not take place after each stage in the pipeline.
2. The most static part of the pipeline should be cached.
3. The logic for caching is either in the ResourcePipeline or "above"
4. If a component is cacheable it should implement an interface Cacheable.
5. Caching is done until the first component in the pipeline is not Cacheable.
6. Identifying if the cache contains the response (or the most static part
   of it) can be done by a unique key. The Cacheable interface implements
   a getKey() method. The keys of all Cacheable components are chained together
   and build the unique key for the cache.
7. Cacheable also delivers a Validator object (getValidator()) which contains all
   information required for this component to test if the content has changed
   since the last caching.
   The FileGenerator e.g. puts the last modification date into the Validator.
   The Cache stores all Validators together with the unique key.
8. All Cacheable components are now asked hasChanged(Validator). If all
   respond with false, the cache value is valid and is used. 
   If the first responds with true, a new response is generated, the validators 
   are get and the result is put in the cache.

This approach is very flexible. Each component nows if it is cacheable and when
it is invalid. Using the Validator object it is possible to specify something 
like: This component is really 6 hours valid wether it changes or not.




Re: idle thoughts in caching in c2

Posted by Sergio Carvalho <sc...@criticalsoftware.com>.
On Mon, 22 Jan 2001 23:16:47 +0100
Giacomo Pati <gi...@apache.org> wrote:

<snip/>
> 
> I think this is not the concern of a sitemap maintainer. Instead an more
> intelligent ResourcePipeline class should be able to determine the
> caching strategy by looking at interfaces and calling methods on a
> generator/transformer.

Before anything else, I strongly disagree with automatic determination of caching strategy. It will make generator/transformer design more complex, and we'll get a less flexible system. I want to be able to choose caching strategy when I design the site, not when I design components. 

Imagine some generated content, which can be checked with 'last-modified', but that I *know* changes once a week. I can save 20ms/request (a standard HTTP header request) just by choosing my own cache policy for that content. 20ms is short, but if you're aiming to answer in 200ms (my own standard), you just saved almost 10% of the response time. And this special cache policy will be used only in this specific case and can't be defined when the generator is designed.

Ok, I guess I didn't see the sitemap maintainer the same way as you do. The sitemap lends itself to be associated to a visual tool, thus bringing web application development to the visual-RAD stage, which is great. This would bring sitemap maintenance to non-technical or just-technical-enough users. 

But, right now, you can't say that sitemap maintenance can be handed over to a non-technical user. It's a text-based interface, which is reason alone to scare most non-techies. Aiming textual sitemap maintenance to a non-techie is an utopy and an error, I believe. 

Assuming textual sitemap maintenance is for techies, then why not have the sitemap completely describe the page building process, and then build on top of it to get a non-techie user friendly interface to building sitemaps? I guess the whole question boils down to whether we wish non-techies to use the textual sitemap. I say we don't. 

We could reach middle ground here, by (optionally) associating each generator/transformer (geformer?) with a cache, on the sitemap. Cocoon uses the cache defined in the sitemap, if it is there, or uses deduced cache if the cache definition is missing.

<snip/>
> > I don't think HTTP caches are a solution here. Cocoon doesn't use HTTP for
> > intermediate steps, so HTTP caches cache the whole page; which is useful but
> > doesn't go as far as we need. I want Cocoon caches to be able to store
> > intermediate steps (like menu generation, for example).
> 
> If your XML/XSP page is static (or static for a certain amount of time)
> and you put a http cache (proxy) between your clients and cocoon and
> you'll be able to use proxy headers (last-modified, exceeds) or might
> react on request header (if-modified-since) to speed up processing (as
> the ResourceReader class is doing). 

This doesn't go against what I say above. HTTP caches are useful, but not as useful as Cocoon caches can be, since Cocoon caches are part of the content generation and can cache document components (a database generated menubar is a recurrent example).

--
Sergio Carvalho
---------------
scarvalho@criticalsoftware.com

If at first you don't succeed, skydiving is not for you

Re: idle thoughts in caching in c2

Posted by Giacomo Pati <gi...@apache.org>.
Sergio Carvalho wrote:
> 
> On Mon, 22 Jan 2001 11:09:41 +0000
> Paul Russell <pa...@luminas.co.uk> wrote:
> 
> > * Sergio Carvalho (scarvalho@criticalsoftware.com) wrote :
> > > On Fri, 19 Jan 2001 13:44:42 -0500 (EST)
> > > Donald Ball <ba...@webslingerZ.com> wrote:
> > > > do you mean that the caching components should be explicitly put in the
> > > > pipeline in the sitemap:
> > > >
> > > > <map:cache type="lru"/>
> > > Yes. A Cache interface could be defined, so that classes implementing
> > > caching are identified. Then, these are placed in the pipeline,
> > > between each data-producer (or processor) and the subsequent
> > > data-consumer.

I think this is not the concern of a sitemap maintainer. Instead an more
intelligent ResourcePipeline class should be able to determine the
caching strategy by looking at interfaces and calling methods on a
generator/transformer.

> >
> > That makes sense. Would we then stick a binary cache on the output
> > regardless, or should that be explicit too? (Or do we not put a binary
> > cache on at all, and leave it to an http level cache?)
> 
> What are you calling a binary cache? Storage of the document in binary form?
> Is it possible to do a memory snapshot in Java, as it is sometimes used in C
> to avoid parsing cached data?
> 
> I don't think HTTP caches are a solution here. Cocoon doesn't use HTTP for
> intermediate steps, so HTTP caches cache the whole page; which is useful but
> doesn't go as far as we need. I want Cocoon caches to be able to store
> intermediate steps (like menu generation, for example).

If your XML/XSP page is static (or static for a certain amount of time)
and you put a http cache (proxy) between your clients and cocoon and
you'll be able to use proxy headers (last-modified, exceeds) or might
react on request header (if-modified-since) to speed up processing (as
the ResourceReader class is doing). 

> 
> There is another design refactoring possible here, but it is probably an
> overkill: In this caching model, a cache class handles two things, cache
> policies and cache storage. Truly, in OO design, these should be handled
> separately, and used through delegation. Something like having these classes:
> 
> - Policies:
>   TimeToLiveCachePolicy
>   FileDirtyCachePolicy
>   FooBarCachePolicy
> - Stores:
>   MemorySnapshotCacheStore
>   TextCacheStore
>   RDBMSCacheStore
> 
> And then have small&simple cache processors that delegate in one policy class
> and one store class:
>   TimeToLiveOnMemorySnapshotCache
>   TimeToLiveOnTextCache
>   FileDirtyOnMemorySnapshotCache
> 
> Again, this is probably an overkill.

Or future refinements/enhancements :)

> 
> I promise I'll implement/aid implementing some of these ideas in mid-february,
> if there's no cache in C2 by mid-february, when my current project finishes
> and I get time to breathe.

Cool, we'll remember this for sure :)

Giacomo

Re: idle thoughts in caching in c2

Posted by Sergio Carvalho <sc...@criticalsoftware.com>.
On Mon, 22 Jan 2001 11:09:41 +0000
Paul Russell <pa...@luminas.co.uk> wrote:

> * Sergio Carvalho (scarvalho@criticalsoftware.com) wrote :
> > On Fri, 19 Jan 2001 13:44:42 -0500 (EST)
> > Donald Ball <ba...@webslingerZ.com> wrote:
> > > do you mean that the caching components should be explicitly put in the
> > > pipeline in the sitemap:
> > > 
> > > <map:cache type="lru"/>
> > Yes. A Cache interface could be defined, so that classes implementing
> > caching are identified. Then, these are placed in the pipeline,
> > between each data-producer (or processor) and the subsequent
> > data-consumer. 
> 
> That makes sense. Would we then stick a binary cache on the output
> regardless, or should that be explicit too? (Or do we not put a binary
> cache on at all, and leave it to an http level cache?)

What are you calling a binary cache? Storage of the document in binary form? Is it possible to do a memory snapshot in Java, as it is sometimes used in C to avoid parsing cached data?

I don't think HTTP caches are a solution here. Cocoon doesn't use HTTP for intermediate steps, so HTTP caches cache the whole page; which is useful but doesn't go as far as we need. I want Cocoon caches to be able to store intermediate steps (like menu generation, for example). 

There is another design refactoring possible here, but it is probably an overkill: In this caching model, a cache class handles two things, cache policies and cache storage. Truly, in OO design, these should be handled separately, and used through delegation. Something like having these classes:

- Policies:
  TimeToLiveCachePolicy
  FileDirtyCachePolicy
  FooBarCachePolicy
- Stores:
  MemorySnapshotCacheStore
  TextCacheStore
  RDBMSCacheStore

And then have small&simple cache processors that delegate in one policy class and one store class:
  TimeToLiveOnMemorySnapshotCache
  TimeToLiveOnTextCache
  FileDirtyOnMemorySnapshotCache
  
Again, this is probably an overkill. 

I promise I'll implement/aid implementing some of these ideas in mid-february, if there's no cache in C2 by mid-february, when my current project finishes and I get time to breathe.

> 
> Paul.
> 
> -- 
> Paul Russell                                 Email:   paul@luminas.co.uk
> Technical Director                             Tel:  +44 (0)20 8553 6622
> Luminas Internet Applications                  Fax:  +44 (0)870 28 47489
> This is not an official statement or order.    Web:    www.luminas.co.uk
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org
> 


-- 
-- 
Sergio Carvalho
---------------
scarvalho@criticalsoftware.com

If at first you don't succeed, skydiving is not for you


Re: idle thoughts in caching in c2

Posted by Paul Russell <pa...@luminas.co.uk>.
* Sergio Carvalho (scarvalho@criticalsoftware.com) wrote :
> On Fri, 19 Jan 2001 13:44:42 -0500 (EST)
> Donald Ball <ba...@webslingerZ.com> wrote:
> > do you mean that the caching components should be explicitly put in the
> > pipeline in the sitemap:
> > 
> > <map:cache type="lru"/>
> Yes. A Cache interface could be defined, so that classes implementing
> caching are identified. Then, these are placed in the pipeline,
> between each data-producer (or processor) and the subsequent
> data-consumer. 

That makes sense. Would we then stick a binary cache on the output
regardless, or should that be explicit too? (Or do we not put a binary
cache on at all, and leave it to an http level cache?)

Paul.

-- 
Paul Russell                                 Email:   paul@luminas.co.uk
Technical Director                             Tel:  +44 (0)20 8553 6622
Luminas Internet Applications                  Fax:  +44 (0)870 28 47489
This is not an official statement or order.    Web:    www.luminas.co.uk

Re: idle thoughts in caching in c2

Posted by Sergio Carvalho <sc...@criticalsoftware.com>.
On Fri, 19 Jan 2001 13:44:42 -0500 (EST)
Donald Ball <ba...@webslingerZ.com> wrote:

> On Fri, 19 Jan 2001, Sergio Carvalho wrote:
> 
> > In my opinion, caching components should be part of the pipeline,
> > allowing for different caching methods to be used, and combined with
> > the different processors. In this scenario, cache doesn't even need to
> > be snapshot-based.
> 
> do you mean that the caching components should be explicitly put in the
> pipeline in the sitemap:
> 
> <map:cache type="lru"/>

Yes. A Cache interface could be defined, so that classes implementing caching are identified. Then, these are placed in the pipeline, between each data-producer (or processor) and the subsequent data-consumer. 

Note that this doesn't invalidate a processor that handles its own caching (current C1 processors do this). They should be able to do just that, in cases where cache methods are heavily intertwined with the processing algorithm. But for all others (previously I used the xinclude processor as an example), cache handling is better off in a separate entity. 

> 
> or something else?
> 
> - donald
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org
> 


-- 
--
Sergio Carvalho
---------------
scarvalho@criticalsoftware.com

If at first you don't succeed, skydiving is not for you

Re: idle thoughts in caching in c2

Posted by Donald Ball <ba...@webslingerZ.com>.
On Fri, 19 Jan 2001, Sergio Carvalho wrote:

> In my opinion, caching components should be part of the pipeline,
> allowing for different caching methods to be used, and combined with
> the different processors. In this scenario, cache doesn't even need to
> be snapshot-based.

do you mean that the caching components should be explicitly put in the
pipeline in the sitemap:

<map:cache type="lru"/>

or something else?

- donald


Re: idle thoughts in caching in c2

Posted by Sergio Carvalho <sc...@criticalsoftware.com>.
Good analysis. I'd like to signal a warning that I've already pointed out on another thread, while discussing this issue with Giacomo: Current Cocoon 1 processors are responsible for answering to questions 1 and 2, and the algorith to answer cannot be defined at design time, as there is not enough information. 

In my opinion, caching components should be part of the pipeline, allowing for different caching methods to be used, and combined with the different processors. In this scenario, cache doesn't even need to be snapshot-based. 

On Thu, 18 Jan 2001 00:16:46 -0500 (EST)
Donald Ball <ba...@webslingerZ.com> wrote:

> when an environment is processed by a sitemap, a new ResourcePipeline is
> constructed, then the environment is associated with a pipeline in the
> sitemap, and the ResourcePipeline is configured to match that pipeline,
> and the environment is processed by the pipeline object.
> 
> to add caching behavior, the first thing to do is re-use ResourcePipeline
> objects. for instance, if this (generated) test is successful:
> 
> if ((map = wildcardMatch(matcher_wildcard_N138_expr,objectModel)) != null) {
> 
> we should operate on ResourcePipeline_N138, or a clone thereof if it's not
> threadsafe. The ResourcePipeline should store the results of each of its
> stages (let's call those results snapshots) when the following criteria
> are met:
> 
> 1. it is likely that the snapshot will be valid for another Environment
> 
> 2. the cost of matching an Environment to a snapshot plus the cost of
> determining if the snapshot is not stale plus the cost of retieving the
> snapshot from storage is less than the cost of generating the snapshot
> anew
> 
> for a first pass, i think we can assume that (1) will be true for
> components like the FileGenerator, but not true for components like the
> ServerPagesGenerator. in another iteration, perhaps we can define some way
> in which server pages and other dynamic components can tell the sitemap
> what environmental conditions cause their results to vary (e.g. a specific
> request parameter and a specific cookie), but i think that would just add
> complexity right now.
> 
> cacheable components could be wrapped with a general purpose component
> wrapper, which would take its incoming SAX events, store them in some
> fashion (using XMLCompiler maybe?), and retrieve them on demand. the
> underlying component would have to provide a method by which the wrapper
> component could determine if its stored snapshot was valid for a given
> environment.
> 
> snapshots would be referenced via strong references if they're frequently
> used, and downgraded to soft references if the cache gets larger than
> desired. any number of algorithms could be used to decide which snapshot
> references to soften, and it should be easy to change algorithms.
> 
> so good so far? i reckon this is a fairly obvious approach to those
> experienced c2 developers who've given any thought to this. anyone see any
> holes in it? worth taking any further?
> 
> - donald
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org
> 


-- 
Sergio Carvalho
---------------
scarvalho@criticalsoftware.com

If at first you don't succeed, skydiving is not for you