Sunday, January 27, 2013

Data Access Optimization in ADF with Oracle Coherence

ADF BC is accessing database each time user is loading new page or accessing new Web session. Once data is retrieved, data is cached usually for the duration of the current session. If there are lots of users accessing the same data  - we may encounter performance bottleneck in querying database each time for new user access. To optimize this, we can use Oracle Coherence - data will be loaded and cached in the middle-tier, it will be served for all users without accessing database each time. Data in Coherence cache can be updated, removed and synchronized back with the database - but this is out of scope for current post. I would like to explain today how to apply Coherence for ADF project in really simple and understandable way - it can be as a startup for your more advanced research and performance tuning.

Here you can download ADF (11g R2) sample application with Coherence cache enabled - ADFCoherenceApp.zip. This sample is quite straightforward - it implements ADF BC for Employees database table:


There are two different UI's implemented in ViewController - one is standard based on ADF BC Data Control, another one is based on POJO Data Control retrieving data from Coherence Cache. In the next post I plan to stress test both task flows with JMeter and to see performance boost by Coherence:


Coherence task flow contains default Method Call activity. Method Call is responsible to load Employees data from ADF BC into Coherence cache. Once data will be loaded to Coherence cache, ADF BC will not be accessed by any subsequent session, data always will be retrieved from Coherence cache:


You can see that from the source code of initialization Method call activity. ADF BC is accessed if only Coherence cache size is equal zero - Employees VO is queried and Coherence cache is populated:


I will describe now how to setup Coherence library for ADF application (I recommend to read this article on OTN - Creating Oracle Coherence Caches in Oracle JDeveloper). Firstly add Coherence Runtime library to your project:


Once library is added - coherence-cache-config.xml file will be created automatically. Config file is empty by default, I have defined basic cache config for EmployeesCache used in this sample app:


In the project Run options, add Java Option to point to coherence-cache-config.xml file (you will need to modify this path in the sample application, according to your environment):


POJO class exposed as Data Control contains a method where we are accessing Coherence cache - EmployeesCache and populating Data Control:


Data collection is loaded on ADF UI as a table:


During first access to Coherence cache - Coherence server is starting, we are reading data from ADF BC and populating it into cache:


This happens in ADF task flow (for Coherence) initialization  Method Call. When fragment is loaded, data already exists in the cache:


Other users who are accessing the same data, will retrieve it directly from Coherence cache. ADF BC Application Module will not be even created and no database access will be established - data will be loaded directly from the cache - this should optimize page load time significantly:

10 comments:

Dave Felcey said...

Hi Andrejus,

Have you ever considered injecting the Coherence "caching" functionality by extending the BC4J base components? - as outlined here http://docs.oracle.com/cd/E16162_01/web.1112/e16182/bcadvgen.htm#BABCGFIE

Andrejus Baranovskis said...

Certainly. I consider it for the next posts. I'm working on it. Stay tuned.

Andrejus

Anonymous said...

Hi Andrejus,

great work.
Just a remark you can push to development: why not working on an integration with Coherence, like TopLink did? They just need to add annotations to the class(es) they want to cache. Maybe an extra tuning option in the view tuning section to integrate Coherence and let the ADF BC framework handle the relationship between Coherence and the views.

HTH

Filip Huysmans

Andrejus Baranovskis said...

Hi Filip,

Yes, good point. This would make ADF BC so fast. I know they were working on this 2-3 years ago - but there was never any outcome. Who knows, if we push - may be it will be available one day.

Andrejus

Prateek Kumar shaw said...

Hi Andrejus,

Nice post :)

Anonymous said...

Hi Andrejus,

Is it supported on 11.1.2.x also? Or just 11.1.1.x is supported?

Andrejus Baranovskis said...

This sample is implemented with 11.1.2.x.

Andrejus

Anonymous said...

How would you compare this to using a Shared AM (where data is shared between user sessions)?

Andrejus Baranovskis said...

Shared AM have restricted usage, can be used mostly only from LOV's. There is no option to use Shared AM from Data Control. From this perspective Coherence is much more flexible and gives more options.

Andrejus

Vivek Singh said...

Hi Andrehus,

I am looking for an option to access Coherence Cache data from OBIEE. Let me know if it is possible.

Thanks
Vivek