[ 
https://issues.apache.org/jira/browse/SLING-3285?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13848688#comment-13848688
 ] 

Alexander Klimetschek commented on SLING-3285:
----------------------------------------------

Thinking about b) further: a central service actually makes sense as it could 
use the script user to get the exact same view as the script resolution about 
the resource type hierarchies. And while invalidation can be a bit tricky 
(needs another observation on the entire repository), it usually should only 
happen on code deployments. For a production system, where the performance 
issue with many parallel request only really comes up, types will be very 
stable.

The service / cache would:
- use the script user to do the lookups
- be invalidated by an observation listener on the sling search path (/apps, 
/libs...) (also script user)
- just set a dirty flag on events
- and force a refresh on the underlying jcr session, to make sure it sees the 
latest content (needed for Oak)
- do the necessary single lookup using that session and add this single entry 
to the cache

The only problem we might face is if the content modified by the production 
system overlaps with the areas where the types are:
- production requests make frequent "content" changes to /libs or /apps, 
leading to frequent invalidation (and we can't instruct the cache to only look 
at rt changes, because we need to take into account not only modifications of 
the sling:resourceSuperType properties, but also of creation or removal of 
resource type folders, as they can have an impact on the rt hierarchy)
- use of absolute resource types or super types pointing outside the search 
path (e.g. sling:resourceSuperType=/content/site/foo)

Both (especially the latter) seem an uncommon usage and the penalty of doing so 
could be ok.

> ResourceResolver.isResourceType() creates admin session for every call with 
> super type, slowing down processing
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: SLING-3285
>                 URL: https://issues.apache.org/jira/browse/SLING-3285
>             Project: Sling
>          Issue Type: Bug
>          Components: ResourceResolver
>    Affects Versions: Resource Resolver 1.0.6
>            Reporter: Alexander Klimetschek
>            Assignee: Carsten Ziegeler
>            Priority: Critical
>              Labels: Performance
>             Fix For: Resource Resolver 1.1.0
>
>
> SLING-2457 fixed the ACL issue with super type lookups, but at the cost of 
> creating a new admin resource resolver for every super type lookup. If an 
> inheritance chain contains multiple super types (N), a single call can 
> trigger the creation of N admin sessions. Often this also happens for a 
> number of resources per request, depending on the application, so you might 
> end up creating many Jackrabbit JCR sessions per request. While creating a 
> resource resolver / session is cheap, having too many at the same time has a 
> big performance impact on the read performance due to increased concurrency 
> in the JCR repository layer.
> This affects:
> * ResourceUtil.isA()
> * Resource.isResourceType()
> * ResourceResolver.isResourceType()
> * implementation in ResourceResolverImpl.isResourceType() and 
> getParentResourceType() [1]
> A simple fix could be to cache a single admin resolver for the duration of 
> the resource resolver containing it and reusing it for subsequent 
> isResourceType() calls.
> Another improvement could also be to cache the isResourceType() lookups - if 
> this is a typical short-lived request resource resolver. Within a request 
> resource type hierarchies are unlikely to change and should probably be 
> stable (and with Jackrabbit Oak the session won't refresh anyway). The cache 
> would simply be a map of "resource type" => "is also this resource type", so 
> that the super lookups don't have to be done again and again. Often an 
> application might iterate over a tree of data and looking for the same 
> resource type again and again, so the hit rate for the cache will be high.
> [1] 
> https://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?revision=1537136&view=markup



--
This message was sent by Atlassian JIRA
(v6.1.4#6159)

Reply via email to