[jira] Created: (JCR-1216) Unreferenced sessions should get garbage collected

View: New views
8 Messages — Rating Filter:   Alert me  

[jira] Created: (JCR-1216) Unreferenced sessions should get garbage collected

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Unreferenced sessions should get garbage collected
--------------------------------------------------

                 Key: JCR-1216
                 URL: https://issues.apache.org/jira/browse/JCR-1216
             Project: Jackrabbit
          Issue Type: Improvement
          Components: jackrabbit-core
            Reporter: Thomas Mueller


If an application opens many sessions and doesn't close them, they are never garbage collected. After some time, the virtual machine will run out of memory. This code will run out of memory after a few thousand logins:

Repository rep = new TransientRepository();
for (int i = 0; ; i++) {
  rep.login(new SimpleCredentials("", new char[0]));
}

Using a finalizer to close SessionImpl doesn't work, because it seems there are references from the (hard referenced part of the cache) to the SessionImpl objects. Maybe it is possible to remove those references, or change them to weak references.


--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (JCR-1216) Unreferenced sessions should get garbage collected

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ https://issues.apache.org/jira/browse/JCR-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12616500#action_12616500 ]

Thomas Mueller commented on JCR-1216:
-------------------------------------

The problem seems to be TransientRepository.session, which is a HashSet.

> Unreferenced sessions should get garbage collected
> --------------------------------------------------
>
>                 Key: JCR-1216
>                 URL: https://issues.apache.org/jira/browse/JCR-1216
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: jackrabbit-core
>            Reporter: Thomas Mueller
>
> If an application opens many sessions and doesn't close them, they are never garbage collected. After some time, the virtual machine will run out of memory. This code will run out of memory after a few thousand logins:
> Repository rep = new TransientRepository();
> for (int i = 0; ; i++) {
>   rep.login(new SimpleCredentials("", new char[0]));
> }
> Using a finalizer to close SessionImpl doesn't work, because it seems there are references from the (hard referenced part of the cache) to the SessionImpl objects. Maybe it is possible to remove those references, or change them to weak references.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (JCR-1216) Unreferenced sessions should get garbage collected

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ https://issues.apache.org/jira/browse/JCR-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12616822#action_12616822 ]

Jukka Zitting commented on JCR-1216:
------------------------------------

I guess we could use weak references in TransientRepository, but that probably requires some updating of how the loggedOut() events are handled.

> Unreferenced sessions should get garbage collected
> --------------------------------------------------
>
>                 Key: JCR-1216
>                 URL: https://issues.apache.org/jira/browse/JCR-1216
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: jackrabbit-core
>            Reporter: Thomas Mueller
>
> If an application opens many sessions and doesn't close them, they are never garbage collected. After some time, the virtual machine will run out of memory. This code will run out of memory after a few thousand logins:
> Repository rep = new TransientRepository();
> for (int i = 0; ; i++) {
>   rep.login(new SimpleCredentials("", new char[0]));
> }
> Using a finalizer to close SessionImpl doesn't work, because it seems there are references from the (hard referenced part of the cache) to the SessionImpl objects. Maybe it is possible to remove those references, or change them to weak references.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (JCR-1216) Unreferenced sessions should get garbage collected

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


    [ https://issues.apache.org/jira/browse/JCR-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12616938#action_12616938 ]

Thomas Mueller commented on JCR-1216:
-------------------------------------

Another idea is: Split SessionImpl into a 'end user class' and an 'core class' to allow garbage collection:

class SessionImpl implements Session {
    private InternalJackrabbitSession session;
    private Exception openStackTrace;
 
    SessionImpl(..) {
        session = ...
        openStackTrace = new Exception("Stack Trace");
    }

    public void finalize() {
        if (!closed) {
            LOG.error("Session not closed", openStackTrace);
            close();
        }
    }

}

class SessionCore implements InternalJackrabbitSession {
    ... basically what is now SessionImpl ...
}

Only SessionCore would be kept in the map, not SessionImpl. The InternalJackrabbitSession interface would be simpler than the Session interface. There could be multiple InternalJackrabbitSession implementations (a embedded implementation, a client-server implementation, a clustering implementation).

This split of 'user facing session' and 'internal session' is probably what we want to achieve with the 'Jackrabbit SPI' as well.


> Unreferenced sessions should get garbage collected
> --------------------------------------------------
>
>                 Key: JCR-1216
>                 URL: https://issues.apache.org/jira/browse/JCR-1216
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: jackrabbit-core
>            Reporter: Thomas Mueller
>
> If an application opens many sessions and doesn't close them, they are never garbage collected. After some time, the virtual machine will run out of memory. This code will run out of memory after a few thousand logins:
> Repository rep = new TransientRepository();
> for (int i = 0; ; i++) {
>   rep.login(new SimpleCredentials("", new char[0]));
> }
> Using a finalizer to close SessionImpl doesn't work, because it seems there are references from the (hard referenced part of the cache) to the SessionImpl objects. Maybe it is possible to remove those references, or change them to weak references.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (JCR-1216) Unreferenced sessions should get garbage collected

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ https://issues.apache.org/jira/browse/JCR-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Mueller updated JCR-1216:
--------------------------------

    Attachment: userSessionPatch.txt

This patch adds a UserSessionImpl (user facing session) that acts as a proxy/wrapper for a SessionImpl. The patch is just for reference. I don't plan to commit it, because there are some problems. For example if a session is not referenced any longer, but one of its nodes is, then the session can still get garbage (but should not).

I will try the original idea: Instead of referencing SessionImpl directly, use WeakReference objects.

> Unreferenced sessions should get garbage collected
> --------------------------------------------------
>
>                 Key: JCR-1216
>                 URL: https://issues.apache.org/jira/browse/JCR-1216
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: jackrabbit-core
>            Reporter: Thomas Mueller
>         Attachments: userSessionPatch.txt
>
>
> If an application opens many sessions and doesn't close them, they are never garbage collected. After some time, the virtual machine will run out of memory. This code will run out of memory after a few thousand logins:
> Repository rep = new TransientRepository();
> for (int i = 0; ; i++) {
>   rep.login(new SimpleCredentials("", new char[0]));
> }
> Using a finalizer to close SessionImpl doesn't work, because it seems there are references from the (hard referenced part of the cache) to the SessionImpl objects. Maybe it is possible to remove those references, or change them to weak references.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (JCR-1216) Unreferenced sessions should get garbage collected

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ https://issues.apache.org/jira/browse/JCR-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Mueller reassigned JCR-1216:
-----------------------------------

    Assignee: Thomas Mueller

> Unreferenced sessions should get garbage collected
> --------------------------------------------------
>
>                 Key: JCR-1216
>                 URL: https://issues.apache.org/jira/browse/JCR-1216
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: jackrabbit-core
>            Reporter: Thomas Mueller
>            Assignee: Thomas Mueller
>         Attachments: userSessionPatch.txt
>
>
> If an application opens many sessions and doesn't close them, they are never garbage collected. After some time, the virtual machine will run out of memory. This code will run out of memory after a few thousand logins:
> Repository rep = new TransientRepository();
> for (int i = 0; ; i++) {
>   rep.login(new SimpleCredentials("", new char[0]));
> }
> Using a finalizer to close SessionImpl doesn't work, because it seems there are references from the (hard referenced part of the cache) to the SessionImpl objects. Maybe it is possible to remove those references, or change them to weak references.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (JCR-1216) Unreferenced sessions should get garbage collected

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ https://issues.apache.org/jira/browse/JCR-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Mueller updated JCR-1216:
--------------------------------

    Attachment: weakReferencePatch.txt

This is a prove-of-concept patch that solves the problem.
It uses weak references to SessionImpl in
TransientRepository.sessions,
StateChangeDispatcher.listeners, and
StateChangeDispatcher.nsListeners.

The StateChangeDispatcher changes are a bit ugly,
and SessionImpl.finalize needs to be changed.

The following test case works now:

    Repository rep = new TransientRepository();
    while(true) {
      SimpleCredentials sc = new SimpleCredentials("", new char[0]);
      rep.login(sc);
    }


> Unreferenced sessions should get garbage collected
> --------------------------------------------------
>
>                 Key: JCR-1216
>                 URL: https://issues.apache.org/jira/browse/JCR-1216
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: jackrabbit-core
>            Reporter: Thomas Mueller
>            Assignee: Thomas Mueller
>         Attachments: userSessionPatch.txt, weakReferencePatch.txt
>
>
> If an application opens many sessions and doesn't close them, they are never garbage collected. After some time, the virtual machine will run out of memory. This code will run out of memory after a few thousand logins:
> Repository rep = new TransientRepository();
> for (int i = 0; ; i++) {
>   rep.login(new SimpleCredentials("", new char[0]));
> }
> Using a finalizer to close SessionImpl doesn't work, because it seems there are references from the (hard referenced part of the cache) to the SessionImpl objects. Maybe it is possible to remove those references, or change them to weak references.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (JCR-1216) Unreferenced sessions should get garbage collected

by JIRA jira@apache.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


     [ https://issues.apache.org/jira/browse/JCR-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Mueller updated JCR-1216:
--------------------------------

    Attachment: softReferencePatch.txt

This patch uses SoftReference instead of WeakReference, so leaks are detected a bit later. This patch passes the unit tests on my machine. Still it's not very nice, as I don't know what kind of ItemStateListener are registered in StateChangeDispatcher. Is there always a hard reference to required listeners?

> Unreferenced sessions should get garbage collected
> --------------------------------------------------
>
>                 Key: JCR-1216
>                 URL: https://issues.apache.org/jira/browse/JCR-1216
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: jackrabbit-core
>            Reporter: Thomas Mueller
>            Assignee: Thomas Mueller
>         Attachments: softReferencePatch.txt, userSessionPatch.txt, weakReferencePatch.txt
>
>
> If an application opens many sessions and doesn't close them, they are never garbage collected. After some time, the virtual machine will run out of memory. This code will run out of memory after a few thousand logins:
> Repository rep = new TransientRepository();
> for (int i = 0; ; i++) {
>   rep.login(new SimpleCredentials("", new char[0]));
> }
> Using a finalizer to close SessionImpl doesn't work, because it seems there are references from the (hard referenced part of the cache) to the SessionImpl objects. Maybe it is possible to remove those references, or change them to weak references.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

LightInTheBox - Buy quality products at wholesale price