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 Alexander Klimetschek <ak...@adobe.com> on 2014/04/09 03:20:09 UTC
Session concurrency warning
Hi,
if I get this warning below, does "another thread is concurrently writing" mean that the other threads is using session WRITE methods?
Or could it happen just because a session was shared between two threads, one only READing from the session, the other writing.
*WARN* org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate Attempt to perform Adding node [....] while another thread is concurrently writing to session-3831. Blocking until the other thread is finished using this session. Please review your code to avoid concurrent use of a session.
java.lang.Exception: Stack trace of concurrent access to session-3831
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:269)
at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.addNode(NodeImpl.java:253)
Cheers,
Alex
Re: Session concurrency warning
Posted by Alexander Klimetschek <ak...@adobe.com>.
On 10.04.2014, at 01:44, Michael Dürig <md...@apache.org> wrote:
>> So when 2 threads use the same session for read operations, then you
>> get another warning ("concurrent access")?
>
> Right but only at debug level.
>
>> If the threads are synchronized, so one finishes its session
>> operations, then the other thread uses it (not in parallel), and when
>> that other thread has finished, the first one again reads from the
>> session, would you get a warning then? AFAIC, the messages are
>> triggered only when it has to wait for another thread.
>
> Exactly. Each operation tries to acquire a lock and logs a warning if it fails before eventually blocking on that lock:
Ok, thanks for the info. Then I know that my code is messed up :)
Cheers,
Alex
Re: Session concurrency warning
Posted by Michael Dürig <md...@apache.org>.
On 10.4.14 2:24 , Alexander Klimetschek wrote:
> On 09.04.2014, at 07:15, Michael Dürig <md...@apache.org> wrote:
>
>> On 9.4.14 4:12 , Rob Ryan wrote:
>>> It would be appropriate to change the warning to warn about
>>> concurrent reads as well. That would help highlight performance
>>> risks.
>>
>> There is such a warning actually. The discussion here was about the
>> incorrect warning that is issued when writing concurrently.
>
> So when 2 threads use the same session for read operations, then you
> get another warning ("concurrent access")?
Right but only at debug level.
>
> If the threads are synchronized, so one finishes its session
> operations, then the other thread uses it (not in parallel), and when
> that other thread has finished, the first one again reads from the
> session, would you get a warning then? AFAIC, the messages are
> triggered only when it has to wait for another thread.
Exactly. Each operation tries to acquire a lock and logs a warning if it
fails before eventually blocking on that lock:
if (!lock.tryLock()) {
// log concurrent access
lock.lock();
}
try {
// repository operation
} finally {
lock.unlock();
}
See
https://github.com/apache/jackrabbit-oak/blob/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java#L264
Michael
>
> I know, concurrent use of sessions must be avoided. I am just curious
> to fully understand the issue I am seeing.
>
> Cheers, Alex
>
Re: Session concurrency warning
Posted by Alexander Klimetschek <ak...@adobe.com>.
On 09.04.2014, at 07:15, Michael Dürig <md...@apache.org> wrote:
> On 9.4.14 4:12 , Rob Ryan wrote:
>> It would be appropriate to change the warning to warn about
>> concurrent reads as well. That would help highlight performance
>> risks.
>
> There is such a warning actually. The discussion here was about the incorrect warning that is issued when writing concurrently.
So when 2 threads use the same session for read operations, then you get another warning ("concurrent access")?
If the threads are synchronized, so one finishes its session operations, then the other thread uses it (not in parallel), and when that other thread has finished, the first one again reads from the session, would you get a warning then? AFAIC, the messages are triggered only when it has to wait for another thread.
I know, concurrent use of sessions must be avoided. I am just curious to fully understand the issue I am seeing.
Cheers,
Alex
Re: Session concurrency warning
Posted by Michael Dürig <md...@apache.org>.
On 9.4.14 4:12 , Rob Ryan wrote:
> It would be appropriate to change the warning to warn about
> concurrent reads as well. That would help highlight performance
> risks.
There is such a warning actually. The discussion here was about the
incorrect warning that is issued when writing concurrently.
Michael
>
> -Rob
>
>
> -----Original Message----- From: Michael Dürig
> [mailto:mduerig@apache.org] Sent: Wednesday, April 09, 2014 12:27 AM
> To: oak-dev@jackrabbit.apache.org Subject: Re: Session concurrency
> warning
>
>
>
> On 9.4.14 3:20 , Alexander Klimetschek wrote:
>> if I get this warning below, does "another thread is concurrently
>> writing" mean that the other threads is using session WRITE
>> methods?
>
> The message is actually misleading if not wrong. This warning is
> issued if *this* thread does a write operation while another thread
> is already doing some other operation (read or write). I logged
> https://issues.apache.org/jira/browse/OAK-1703.
>
> Michael
>
RE: Session concurrency warning
Posted by Rob Ryan <rr...@adobe.com>.
It would be appropriate to change the warning to warn about concurrent reads as well. That would help highlight performance risks.
-Rob
-----Original Message-----
From: Michael Dürig [mailto:mduerig@apache.org]
Sent: Wednesday, April 09, 2014 12:27 AM
To: oak-dev@jackrabbit.apache.org
Subject: Re: Session concurrency warning
On 9.4.14 3:20 , Alexander Klimetschek wrote:
> if I get this warning below, does "another thread is concurrently
> writing" mean that the other threads is using session WRITE methods?
The message is actually misleading if not wrong. This warning is issued if *this* thread does a write operation while another thread is already doing some other operation (read or write). I logged https://issues.apache.org/jira/browse/OAK-1703.
Michael
Re: Session concurrency warning
Posted by Michael Dürig <md...@apache.org>.
On 9.4.14 3:20 , Alexander Klimetschek wrote:
> if I get this warning below, does "another thread is concurrently
> writing" mean that the other threads is using session WRITE methods?
The message is actually misleading if not wrong. This warning is issued
if *this* thread does a write operation while another thread is already
doing some other operation (read or write). I logged
https://issues.apache.org/jira/browse/OAK-1703.
Michael
Re: Session concurrency warning
Posted by Michael Dürig <md...@apache.org>.
On 9.4.14 4:55 , Rob Ryan wrote:
> I can't comment to the exact meaning of the warning, but I can say
> the impact of reading from multiple threads with one session is a
> significant concern in itself given the current implementation of
> Oak. Under high throughput conditions the lock contention quickly
> becomes a significant performance bottleneck.
Right. In general the situation is no different from Jackrabbit 2:
sessions should not be accessed concurrently from multiple threads. The
repository will not corrupt if doing so but wont make any guarantees
beyond that.
More specifically, concurrent session access actually *is* more prone to
lock contention in Oak as it was for Jackrabbit 2 even though the
granularity of the lock is the same. In Oak there are more operations
where we need to acquire that lock so we can make scalability guarantees
elsewhere. One example is Node#getNodes(), which return an Iterator of
that node's child nodes. In Jackrabbit 2 the implementation could just
return a list of child nodes eagerly pre-fetched. Since in Oak we need
to support large numbers of child nodes this approach would not scale
and we need to return an Iterator that lazily fetches its children,
acquiring the lock each time.
Michael
RE: Session concurrency warning
Posted by Rob Ryan <rr...@adobe.com>.
I can't comment to the exact meaning of the warning, but I can say the impact of reading from multiple threads with one session is a significant concern in itself given the current implementation of Oak. Under high throughput conditions the lock contention quickly becomes a significant performance bottleneck.
-Rob
-----Original Message-----
From: Alexander Klimetschek [mailto:aklimets@adobe.com]
Sent: Tuesday, April 08, 2014 6:20 PM
To: oak-dev@jackrabbit.apache.org
Subject: Session concurrency warning
Hi,
if I get this warning below, does "another thread is concurrently writing" mean that the other threads is using session WRITE methods?
Or could it happen just because a session was shared between two threads, one only READing from the session, the other writing.
*WARN* org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate Attempt to perform Adding node [....] while another thread is concurrently writing to session-3831. Blocking until the other thread is finished using this session. Please review your code to avoid concurrent use of a session.
java.lang.Exception: Stack trace of concurrent access to session-3831
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:269)
at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113)
at org.apache.jackrabbit.oak.jcr.session.NodeImpl.addNode(NodeImpl.java:253)
Cheers,
Alex