1

I am working with eclipselink*(version 4.0.4)* L2 cache optimization. For that I have implemented static weaving as Wildfly*(version 32.0.1.Final)*/Jboss server doesn't support dynamic weaving (as mentioned here : https://eclipse.dev/eclipselink/documentation/4.0/solutions/solutions.html#how-to-disable-or-enable-weaving-in-a-jakarta-ee-environment) so that Lazy loading can be implemented for JPAs. I am using a external Database configured using datasource subsystem of wildfly with min-pool-size : 40 and max-pool-size : 400, and blocking-timeout-millis : 800 ms.

I have multiple JPAs which have multiple nested bidirectional @oneToMany and @oneToOne mapping. I have made every reverse directional @manyToOne mapping as LAZY loaded and confirmed that the LAZY loaded relations are not being loaded unnecessarily. I have only kept those relation as EAGER which are absolutely use together.

My code uses [read only] connection outside of transactional context and the only [default] connections are used inside the transactional context and at the end of the code I use executor service to run different processes for seperate processes. In this seperate proccesses. My only interation with the persistence context is using @local Dao interface whose @Stateless @EJB DaoImpl bean contains these :

@PersistenceContext(unitName = "contextName")
EntityManager em;

The executor service threads also uses the Dao interface by doing a Bean lookup for using some methods DaoImpl which are only read operations.

Now when I proccess single request and check for my request throughput it has significantly improved. But when I throw mutiple request at some throughput my connection pool is getting exhausted while with the same code without any changes my connection pool is able to hold the throughput.

Why is this happening? I have searched on web and was not able to find any definite solution. I am very new to stackoverflow, please do tell me if I need to provide anything else. Help is much appreciated.

I have analysed that I have a JPA1 with some @oneToOne and @oneToMany bidirectional mappings with LAZY loading and later used with the reverse @oneToOne and @manyToOne mappings are LAZY loaded and never used and thus not loaded. In the end of the transactional context I use a Named Query to find all the JPA1 entries related to a some "parentID" attribute. These kind of queries don't hit L2 cache and thus always go to DB. After that the executor service calls some threads and these threads use these JPA1 entry's LAZY loaded relations of the earlier loaded entities. Eclipselink supports the loading of LAZY relationships even if the entity manager closes. I suspect that these are the cause of DB exhaustion but even if I make these entities EAGER loaded the DB exhaustion probelem still remains.

I have also tried using @JoinFetch(JoinFetchType.OUTER) and @JoinFetch(JoinFetchType.INNER) but the connection problem still remains but the number of connection getting used are reduced.

I have tried counting the number of connection used before the change and after the change but the connections are used less in case where I have done the LAZY loading and static weaving change. Then why was the connection pool exhausted in the case where less connections are being used?

Below are my datasource statistics from widlfy admin console :
Datasource Statistics without the weaving and lazyloading changes

Datasource Statistics with the weaving and lazyloading changes

5
  • Is there a reason to use EclipseLink instead of the provided Hibernate for the Jakarta Persistence implementation? Commented May 29 at 17:49
  • No particular reason but my code was written by early developers with eclipselink and thus I am working with it. Commented May 29 at 18:01
  • 1
    You will want to look at what you are doing with your entities that are fetched. Serialization or mapping to a DTO for instance might traverse your lazy relationships. Even toString operations in logging might be accessing them, and inadvertantly causing an extra DB connection to be required to fetch the relationship, increasing load on your connection pool. Turn on EclipseLink logging wiki.eclipse.org/EclipseLink/Examples/JPA/Logging and maybe look at each request to figure out the calls to the DB being made, and how long it is keeping the connection for. Commented May 29 at 18:01
  • I have also verified that there is no lazy loading accuring due to Serialization or mapping to DTO and toString which are overrriden don't use the relationship collections from JPA and all the @manyToOne LAZY loaded entities reverse relation of the bidirectional mappings are never loaded which I verified using eclipselink PerformanceProfiler. Commented May 30 at 16:55
  • EclipseLink profiling and logging should record when it obtains a connection from a pool, and when it releases it back. Check one single, simple, process flow and ensure that it is doing that where you would expect, as the EntityManager (perstenceContext) should likely lazily obtain a connection and release it when done with its query unless it is in a transaction - or is using special configuration like exclusive connection pooling. Also verify the context is being closed by the container (it should, but you have the logs and config) Commented Jun 3 at 19:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.