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 - 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:


Dave Felcey said...

Hi Andrejus,

Have you ever considered injecting the Coherence "caching" functionality by extending the BC4J base components? - as outlined here

Andrej Baranovskij said...

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


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.


Filip Huysmans

Andrej Baranovskij 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.


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?

Andrej Baranovskij said...

This sample is implemented with 11.1.2.x.


Anonymous said...

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

Andrej Baranovskij 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.


Unknown said...

Hi Andrehus,

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


Anonymous said...

Hey ! Great post! How did you start the cache server? Did you do any configurations from the WebLogic console?

Madhur said...

Hi Andrejus
I am looking for a way to cache the VO objects using coherence . I want to know how did you start the cache server . Are you making use of coherence servers to cache the ADF BC ? If yes what changes did you make to the console ?

Andrej Baranovskij said...


I think it starts automatically by default, there was no need to do any extra steps on JDEV embedded WLS.