Page: http://wiki.cocoondev.org/Wiki.jsp?page=Main , version: 185 on Wed May 14 09:33:30 2003 by SylvainWallez
- * May 13, 2003 ? ^ + * May 14, 2003 ? ^ Page: http://wiki.cocoondev.org/Wiki.jsp?page=WritingPipelineComponents , version: 3 on Wed May 14 09:18:24 2003 by SylvainWallez + * __[Writing components for maximum cache efficiency|WritingForCacheEfficiency]__ Page: http://wiki.cocoondev.org/Wiki.jsp?page=WritingForCacheEfficiency , version: 1 on Wed May 14 09:27:57 2003 by SylvainWallez New page created: + Pipeline components can be made cacheable by implementing {{CacheableProcessingComponent}}. This allows the component to give a cache key and validity used to avoid useless reprocessing if the pipeline result would be unchanged. + + However, achieving maximum performance to deliver cached content needs some careful coding. + + Looking at {{TraxTransformer.setup()}} (as of 13 may 2003), we can see that it gets the validity _and_ and a TransformerHandler at the same time. And if the validity is still valid, the TransformerHandler is simply not used since the content is retrieved from the cache. So I hacked a bit to separate these, and obtained again a speed increase ranging from 5% to 30%. + + This leads to some importants recommendations in order to achieve the maximum cache efficiency : __the {{setup()}} method must avoid performing operations that are necessary only if the content is not cached__. Otherwise, its just a waste of speed to deliver cached content. + + Here's a reminder of the various steps that occur when handling a request :\\ + __1__ - the sitemap is executed, meaning we create a pipeline object, and pipeline components : generator, transformers, and serializer.\\ + __2__ - the {{setup()}} method of all pipeline components is called (except serializer which doesn't have one)\\ + __3__ - the {{getKey()}} method of all pipeline components is called + + Knowing the key, the pipeline can get the associated cache entry and its validity. If the cache validity either is invalid or needs a fresh validity object to be compared with, then :\\ + __4__ - the {{getValidity()}} method of all pipeline components is called + + The pipeline can then know if the cache entry is valid. If it's valid, it delivers the cached content. If it's invalid, then :\\ + __5__ - the pipeline is connected. This means {{setXMLConsumer()}} is called on transformers and {{setOutputStream()}} is called on the serializer\\ + __6__ - the generator's {{generate()}} method is called, and starts the SAX stream processing, resulting first in {{startDocument()}} being called on transformers and serializer. + + What we can see above, is that we must defer as much as possible to points 5 or 6 the creation or lookup of resources that are used to process the content. Doing it before is only waste of resources. And that's what TraxTransformer is doing : it creates a TransformerHandler at point 2. + + Be aware of that and inspect cacheable components for possible enhancements. This is key for an increased performance ! + + -- [SylvainWallez] +
