Wednesday, June 25, 2008

Asynchronous Delegate in Serviced Component COM+

I’m currently assigned to optimize a COM+ performance which is storing some data in the cache. The loading time will take around 2-3 minutes.

Since it is loading data from different tables and they are not related one with another, I’m thinking of using Asynchronous Delegate for the loading process so they can be loaded in separate threads.

This is what we should get if we use delegates

Async Normal

Load Data A, Load Data B, and Load Data C are executed using delegates :

LoadDataDelegate loadDataA = new LoadDataDelegate(LoadDataA);
IAsyncResult result1 = loadDataA.BeginInvoke(null, null);

LoadDataDelegate loadDataB = new LoadDataDelegate(LoadDataB);
IAsyncResult result2 = loadDataB.BeginInvoke(null, null);

LoadDataDelegate loadDataC = new LoadDataDelegate(LoadDataC);
IAsyncResult result3 = loadDataC.BeginInvoke(null, null);

// Wait the results to complete
loadDataA.EndInvoke(result1);
loadDataB.EndInvoke(result2);
loadDataC.EndInvoke(result3);
  

 

Turned out after I deployed the component to COM+, all the delegates ran in only single thread as sequentially / synchronously.

Only if I create a new thread explicitly, it will create a new thread.

Async COM  

Load Data A is being executed in a new thread, Load Data B, and Load Data C are executed using delegates but they were executed in the same thread synchronously.

Thread loadDataA = new Thread(new ThreadStart(LoadDataA));
loadDataA.Start();

LoadDataDelegate loadDataB = new LoadDataDelegate(LoadDataB);
IAsyncResult result2 = loadDataB.BeginInvoke(null, null);

LoadDataDelegate loadDataC = new LoadDataDelegate(LoadDataC);
IAsyncResult result3 = loadDataC.BeginInvoke(null, null);

// Wait the results to complete
loadDataA.Join();
loadDataB.EndInvoke(result2);
loadDataC.EndInvoke(result3);
   

 

I haven’t really found the reason why for COM+ deployment will have this behavior for delegate asynchronous invocation :(

Note: I’m currently not using this asynchronous operation for shared resources reason which requires major changes.

So my dearest readers, please show me the light if you know the reason, thanks ;)

  

2 comments:

Anonymous said...

I wish I knew, running across the same problem. As far as I can see all asynchronous functionality for ServicedComponents centers around MSMQ. Which to me seems to be overkill, when I am just looking to have multiple threads participating in a single transaction.

So far I have not been able to find a sanctioned way to do this.

vitamin b said...

It is good to hear that you have got a project in which you have to optimize a COM+ performance which is storing some data in the cache. I think that the Multiple threads are not loaded properly in a single transaction.

Post a Comment