Recently am able to see while accesssing pages are loading very slow and in error.log file cache, memory leakage related errors, which landed me in a question How many JCR Sessions an AEM instance can handle.?
Asked
Active
Viewed 587 times
2
-
It depends on so many factors, that there is no answer possible. For example: what is the cause of the leaks? – Florian Salihovic Mar 15 '17 at 17:35
-
@FlorianSalihovic we have a DEV box where all the users are gets connected and trying to execute/test the developed code base. (most of the Code snippets has JCR Sessions to establish and retrieve data kind use cases), wo while testing the pages are almost dead to load. So is there a way to find out the JCR Sessions how many has established and max limit that an AEM server can handle .? – VAr Mar 15 '17 at 17:37
-
Do you see things like "CacheManager: resizeAll" in your logs? If yes, then try following command: jmap -histo
| grep SessionImpl which should give you a list of sessions. I think it's down to 2 main factors, rate of open vs rate of closing of sessions. Bad code that does not closes sessions. If there are too many long running operations then even well written code can cause an increase in JCR sessions (for example on slow Mongo deployments) and system slows down to halt. – Imran Saeed Mar 15 '17 at 21:33
1 Answers
1
- Use the
ResourceResolver
interface and avoid usingSession
. - If a
ResourceResolver
is provided to your Service, Servlet or Model (Sling Model, WCMUse) or you create one instance via adaptation: don't close it. - If you have to create a ResourceResolver manually via
ResourceResolverFactory
, it should be short lived and closed after you're done. - Same applies to a
Session
.
Example:
package io.salihovic.florian.examples;
import javax.annotation.CheckForNull;
interface ResourceResolverTemplate {
@CheckForNull ResourceResolver getResourceResolver();
default void usage() {
final ResourceResolver resolver = this.getResourceResolver();
if (resolver != null) {
// do something
resolver.close();
}
}
}

Florian Salihovic
- 3,921
- 2
- 19
- 26