You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Chetan Mehrotra <ch...@gmail.com> on 2013/12/17 18:26:08 UTC

Package deployment check for locking leading to large no of small branch commits

Hi,

While profiling slow deployment of some packages on CQ (using Oak)
running on Mongo I noticed that its creating lots of small branch
commits. Looking into the invocation flow following appears to be
happening

1. Package contains lots of small nodes (~7000)
2. DocViewSAXImporter.createNode creates a new ContentHandler per
    Node
3. This creates instance of org.apache.jackrabbit.oak.jcr.xml.ImporterImpl
    which checks if the given path is locked or not
4. org.apache.jackrabbit.oak.jcr.lock.LockManagerImpl#isLocked then uses
    LockOperation to do the check
5. LockOperation#perform does a Session refresh
6. Session refresh triggers purge of current pending changes leading to a
    branch commit

As this flow gets invoked per node the number of branch commits are
very high which causes performance loss. If I disable the session
refresh in LockManager then package import times drops from 230 sec to
26 sec

So not sure where the fix is to be done. Should lock check be also
restricted to version at which session is pinned or one needs to be at
latest revision?

Marcel suggested that checking for locks can probably be done as part
of CommitHook

Chetan Mehrotra

[1] https://svn.apache.org/repos/asf/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java

RE: Package deployment check for locking leading to large no of small branch commits

Posted by Marcel Reutegger <mr...@adobe.com>.
Hi,

> On Tue, Dec 17, 2013 at 12:26 PM, Chetan Mehrotra
> <ch...@gmail.com> wrote:
> > So not sure where the fix is to be done. Should lock check be also
> > restricted to version at which session is pinned or one needs to be at
> > latest revision?
> 
> Since the lock checks are normally used to synchronize work across
> sessions, it doesn't make much sense for it *not* to refresh.

I definitively agree when it comes to locking a node. this should be done
on a refreshed session. but what is the value in just checking if a node
is locked?

I don't think you can build reliable code with this behavior anyway. the
lock status of a node may change as soon the isLocked() method returns
and you cannot rely on what it reports. usually you have code that
must modify content only with a lock held. in this case you will have
to call lock() anyway, which performs a refresh.

> Instead I'd look for a fix in steps 3 or 6:
> 
> 3. Does the ImporterImpl really need to explicitly check for locking,
> or would that be better handled by a commit hook? The same applies BTW
> for the versioning check.
> 
> 6. Since there's no need for a branch to be visible to any other
> clients, a branch commit could (and probably should) remain in local
> memory unless or until the transient space grows too large. This way
> the performance overhead of the refresh should be minimal.

not sure here, but I think the reason why we push the changes into
the branch is that we can perform a rebase on the underlying store.
e.g. the MicroKernel. how would you rebase a branch partially in
memory and persisted?

Regards
 Marcel

Re: Package deployment check for locking leading to large no of small branch commits

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Tue, Dec 17, 2013 at 12:26 PM, Chetan Mehrotra
<ch...@gmail.com> wrote:
> So not sure where the fix is to be done. Should lock check be also
> restricted to version at which session is pinned or one needs to be at
> latest revision?

Since the lock checks are normally used to synchronize work across
sessions, it doesn't make much sense for it *not* to refresh.

Instead I'd look for a fix in steps 3 or 6:

3. Does the ImporterImpl really need to explicitly check for locking,
or would that be better handled by a commit hook? The same applies BTW
for the versioning check.

6. Since there's no need for a branch to be visible to any other
clients, a branch commit could (and probably should) remain in local
memory unless or until the transient space grows too large. This way
the performance overhead of the refresh should be minimal.

BR,

Jukka Zitting

Re: Package deployment check for locking leading to large no of small branch commits

Posted by Chetan Mehrotra <ch...@gmail.com>.
Created OAK-1294 to track this

Chetan Mehrotra
[1] https://issues.apache.org/jira/browse/OAK-1294

On Wed, Dec 18, 2013 at 3:15 PM, Chetan Mehrotra
<ch...@gmail.com> wrote:
> The patch works great!!
>
> With patch applied I get similar timings as I got by disabling session
> refresh in LockOperation.
> Chetan Mehrotra
>
>
> On Wed, Dec 18, 2013 at 2:47 PM, Michael Dürig <md...@apache.org> wrote:
>>
>>
>> On 18.12.13 10:12 , Marcel Reutegger wrote:
>>>>
>>>> We could rebase the branch and then rebase the in memory changes on top
>>>> of the rebased branch. This would get us rid of the branch commit. But
>>>> wouldn't get us rid of the rebase operation on the persisted branch. So
>>>> I'm not too sure this will gain us a lot.
>>>
>>>
>>> hmm, you are right. this may still result in a commit on the branch for
>>> the
>>> rebase. it should be possible to avoid it when the rebase is actually a
>>> no-op because there were no changes by other sessions.
>>
>>
>> I think this is already the case. See
>> org.apache.jackrabbit.oak.spi.state.AbstractNodeStoreBranch.Persisted#rebase
>>
>> For the other branch states rebasing is already entirely in memory. I
>> quickly hacked together a POC patch for above approach. Chetan agreed to do
>> a quick check with that.
>>
>> Michael
>>
>>>
>>> Regards
>>>   Marcel
>>>
>>

Re: Package deployment check for locking leading to large no of small branch commits

Posted by Chetan Mehrotra <ch...@gmail.com>.
The patch works great!!

With patch applied I get similar timings as I got by disabling session
refresh in LockOperation.
Chetan Mehrotra


On Wed, Dec 18, 2013 at 2:47 PM, Michael Dürig <md...@apache.org> wrote:
>
>
> On 18.12.13 10:12 , Marcel Reutegger wrote:
>>>
>>> We could rebase the branch and then rebase the in memory changes on top
>>> of the rebased branch. This would get us rid of the branch commit. But
>>> wouldn't get us rid of the rebase operation on the persisted branch. So
>>> I'm not too sure this will gain us a lot.
>>
>>
>> hmm, you are right. this may still result in a commit on the branch for
>> the
>> rebase. it should be possible to avoid it when the rebase is actually a
>> no-op because there were no changes by other sessions.
>
>
> I think this is already the case. See
> org.apache.jackrabbit.oak.spi.state.AbstractNodeStoreBranch.Persisted#rebase
>
> For the other branch states rebasing is already entirely in memory. I
> quickly hacked together a POC patch for above approach. Chetan agreed to do
> a quick check with that.
>
> Michael
>
>>
>> Regards
>>   Marcel
>>
>

Re: Package deployment check for locking leading to large no of small branch commits

Posted by Michael Dürig <md...@apache.org>.

On 18.12.13 10:12 , Marcel Reutegger wrote:
>> We could rebase the branch and then rebase the in memory changes on top
>> of the rebased branch. This would get us rid of the branch commit. But
>> wouldn't get us rid of the rebase operation on the persisted branch. So
>> I'm not too sure this will gain us a lot.
>
> hmm, you are right. this may still result in a commit on the branch for the
> rebase. it should be possible to avoid it when the rebase is actually a
> no-op because there were no changes by other sessions.

I think this is already the case. See 
org.apache.jackrabbit.oak.spi.state.AbstractNodeStoreBranch.Persisted#rebase

For the other branch states rebasing is already entirely in memory. I 
quickly hacked together a POC patch for above approach. Chetan agreed to 
do a quick check with that.

Michael

>
> Regards
>   Marcel
>

RE: Package deployment check for locking leading to large no of small branch commits

Posted by Marcel Reutegger <mr...@adobe.com>.
> We could rebase the branch and then rebase the in memory changes on top
> of the rebased branch. This would get us rid of the branch commit. But
> wouldn't get us rid of the rebase operation on the persisted branch. So
> I'm not too sure this will gain us a lot.

hmm, you are right. this may still result in a commit on the branch for the
rebase. it should be possible to avoid it when the rebase is actually a
no-op because there were no changes by other sessions.

Regards
 Marcel

Re: Package deployment check for locking leading to large no of small branch commits

Posted by Michael Dürig <md...@apache.org>.

On 18.12.13 9:20 , Marcel Reutegger wrote:
> Hi,
>
>> Purging (should) only happen for refresh calls with the keepChanges
>> parameter set to true. This might be optimised however for the case
>> where the persisted branch has not yet been created (i.e.
>> org.apache.jackrabbit.oak.spi.state.AbstractNodeStoreBranch.InMemory) by
>> tweaking the way (Kernel|Mongo)NodeStoreBranch and
>> (Kernel|Mongo)RootBuilder interact.
>
> in the case described by Chetan the branch state is persisted pretty
> quickly because the package install consists of many nodes. the
> question is rather if there is a way to optimize the case when the
> branch state is persisted with in-memory changes on top of it
> and a refresh with keepChanges comes in.

We could rebase the branch and then rebase the in memory changes on top 
of the rebased branch. This would get us rid of the branch commit. But 
wouldn't get us rid of the rebase operation on the persisted branch. So 
I'm not too sure this will gain us a lot.

Michael

>
> Regards
>   Marcel
>

RE: Package deployment check for locking leading to large no of small branch commits

Posted by Marcel Reutegger <mr...@adobe.com>.
Hi,

> Purging (should) only happen for refresh calls with the keepChanges
> parameter set to true. This might be optimised however for the case
> where the persisted branch has not yet been created (i.e.
> org.apache.jackrabbit.oak.spi.state.AbstractNodeStoreBranch.InMemory) by
> tweaking the way (Kernel|Mongo)NodeStoreBranch and
> (Kernel|Mongo)RootBuilder interact.

in the case described by Chetan the branch state is persisted pretty
quickly because the package install consists of many nodes. the
question is rather if there is a way to optimize the case when the
branch state is persisted with in-memory changes on top of it
and a refresh with keepChanges comes in.

Regards
 Marcel

Re: Package deployment check for locking leading to large no of small branch commits

Posted by Michael Dürig <md...@apache.org>.

On 17.12.13 6:26 , Chetan Mehrotra wrote:
> 6. Session refresh triggers purge of current pending changes leading to a
>      branch commit

Purging (should) only happen for refresh calls with the keepChanges 
parameter set to true. This might be optimised however for the case 
where the persisted branch has not yet been created (i.e. 
org.apache.jackrabbit.oak.spi.state.AbstractNodeStoreBranch.InMemory) by 
tweaking the way (Kernel|Mongo)NodeStoreBranch and 
(Kernel|Mongo)RootBuilder interact.

Michael