Connection Pooling in the WCF LOB ASDK based adapters.

I was recently contacted by a customer using the SAP Adapter. They were using the Adapter directly via a WCF proxy (i.e., without using BizTalk) from within an ASP.NET application. Their complaint was that the throughput was very low. On investigating further, I found that the reason was due to connections being opened and closed, as well as metadata being retrieved from SAP, for every call. All this in spite of the binding property “EnableConnectionPooling” being true. That’s strange you might think, but not once you know the details of how the ASDK functions …


In the WCF LOB ASDK, there was a need for maintaining a pool of open connections to the LOB, since opening connections to LOB systems is usually expensive. When a connection is required by a channel to a particular LOB server (as determined by the URI), with a specific set of credentials, then the appropriate connection is picked up from the pool and used; when the channel is closed, the connection is returned back to the pool.


In the current ASDK design,  the connection pools are maintained at the channel factory instance. (The exact reasons of why this design was chosen – topic of another blog post). What this means is that if you have two channel factory instances, then each channel factory has its own set of connection pools. i.e., for a server A, each channel factory will have one connection pool for this server. Connections from the pools in one channel factory cannot be used by another channel factory.


Another set of objects which are cached are metadata objects. The adapters, at runtime, when receiving a message (corresponding to some LOB operation), first connect to the LOB to obtain metadata for the operation. This is required in order to understand how to parse the request message (for example – how many parameters does the function have? What are their names? etc). Once metadata is obtained from the LOB, this metadata is cached within the ASDK. There are a number of settings (exposed by the ASDK to the adapter) which determine for how long is the metadata cached, where is it cached, etc. The adapter has control over whether the ASDK should cache the metadata at an AppDomain level (i.e., “static”), or per channel factory instance. The SAP Adapter instructs the ASDK to cache the metadata per channel factory instance. (Why? Another blog post).


At this point, here’s what we know – in the SAP Adapter, both, the connection pools, as well as the metadata caches, are maintained within each channel factory object. If you have two channel factories, then you will have a separate set of connection pools and metadata objects. The connection pools and metadata objects are freed up only when the channel factory object is closed.


Now, when you use the Metadata Search Browse tool (using “Add Adapter Service Reference”) in your application, we generate an interface (which is the ServiceContract), as well as a client proxy. For example, if you generated the client proxy for RFC_CUSTOMER_GET, you would see a proxy class generated named RfcClient, as well as an interface named Rfc. To use the generated proxy, you would have code similar to:


RfcClient client = new RfcClient(binding, endpointAddress);
client.Open();
client.RFC_CUSTOMER_GET();
//do work here
client.Close();


Now, here’s something which you might not know – every time you create an instance of RfcClient, this causes a new channel factory to be created, and then, from that channel factory, a channel is created. When you close the RfcClient object, the channel is closed, as well as the channel factory. This leads to the connection pool being closed (i.e., all connections in the pool are closed), and the metadata objects are freed up. When you create a new instance of RfcClient, another channel factory is created, which comes with its own pool and metadata cache. Therefore, effectively, connections are not being pooled, (and neither is the metadata cache acting as a cache), since they are freed up the moment the RfcClient object is closed.


So, how do you get around this? One way would be to cache the RfcClient object, and then use that from multiple threads (for example). However, this really doesn’t help. The reason being, that the RfcClient object not only represents one channel factory, but also just one channel (which ultimately maps to one LOB connection). Therefore, if you have, say, 50 threads accessing the same RfcClient object, they will all ultimately end up using the same LOB connection, which will definitely not be good for performance.


What you really want to do, is open one channel factory, cache that, and then, open and close channels at will from that channel factory. When you open a channel, a connection will be obtained from the connection pool; and when you close the channel, the connection will be released back to the pool. Plus, the metadata cache will be shared across the channels, since they are part of the same channel factory.


So, how do you this? You can’t use the RfcClient proxy. Instead, you need to use the ChannelFactory<> class, and use the generated ServiceContract (which will be named Rfc if you added only RFCs in the “Add Adapter Service Reference” wizard). (You can always figure out the name of the interface, by looking up the definition of the generated proxy, and seeing which interface it implements). Thus, you need to do something like:


//do this only once
ChannelFactory<Rfc> factory = new ChannelFactory<Rfc>(binding);
factory.Open();
//cache the “factory” object somewhere.


//When you need to make a call to SAP:
Rfc channel = factory.CreateChannel(endpointAddress);
channel.RFC_CUSTOMER_GET();
((
IChannel)channel).Close();
//that’s all.


//When you ultimately want to free up
//all connections in the pool, and free
//up all the stored metadata,
factory.Close();

Connection Pooling in the WCF LOB ASDK based adapters.

I was recently contacted by a customer using the SAP Adapter. They were using the Adapter directly via a WCF proxy (i.e., without using BizTalk) from within an ASP.NET application. Their complaint was that the throughput was very low. On investigating further, I found that the reason was due to connections being opened and closed, as well as metadata being retrieved from SAP, for every call. All this in spite of the binding property “EnableConnectionPooling” being true. That’s strange you might think, but not once you know the details of how the ASDK functions …


In the WCF LOB ASDK, there was a need for maintaining a pool of open connections to the LOB, since opening connections to LOB systems is usually expensive. When a connection is required by a channel to a particular LOB server (as determined by the URI), with a specific set of credentials, then the appropriate connection is picked up from the pool and used; when the channel is closed, the connection is returned back to the pool.


In the current ASDK design,  the connection pools are maintained at the channel factory instance. (The exact reasons of why this design was chosen – topic of another blog post). What this means is that if you have two channel factory instances, then each channel factory has its own set of connection pools. i.e., for a server A, each channel factory will have one connection pool for this server. Connections from the pools in one channel factory cannot be used by another channel factory.


Another set of objects which are cached are metadata objects. The adapters, at runtime, when receiving a message (corresponding to some LOB operation), first connect to the LOB to obtain metadata for the operation. This is required in order to understand how to parse the request message (for example – how many parameters does the function have? What are their names? etc). Once metadata is obtained from the LOB, this metadata is cached within the ASDK. There are a number of settings (exposed by the ASDK to the adapter) which determine for how long is the metadata cached, where is it cached, etc. The adapter has control over whether the ASDK should cache the metadata at an AppDomain level (i.e., “static”), or per channel factory instance. The SAP Adapter instructs the ASDK to cache the metadata per channel factory instance. (Why? Another blog post).


At this point, here’s what we know – in the SAP Adapter, both, the connection pools, as well as the metadata caches, are maintained within each channel factory object. If you have two channel factories, then you will have a separate set of connection pools and metadata objects. The connection pools and metadata objects are freed up only when the channel factory object is closed.


Now, when you use the Metadata Search Browse tool (using “Add Adapter Service Reference”) in your application, we generate an interface (which is the ServiceContract), as well as a client proxy. For example, if you generated the client proxy for RFC_CUSTOMER_GET, you would see a proxy class generated named RfcClient, as well as an interface named Rfc. To use the generated proxy, you would have code similar to:


RfcClient client = new RfcClient(binding, endpointAddress);
client.Open();
client.RFC_CUSTOMER_GET();
//do work here
client.Close();


Now, here’s something which you might not know – every time you create an instance of RfcClient, this causes a new channel factory to be created, and then, from that channel factory, a channel is created. When you close the RfcClient object, the channel is closed, as well as the channel factory. This leads to the connection pool being closed (i.e., all connections in the pool are closed), and the metadata objects are freed up. When you create a new instance of RfcClient, another channel factory is created, which comes with its own pool and metadata cache. Therefore, effectively, connections are not being pooled, (and neither is the metadata cache acting as a cache), since they are freed up the moment the RfcClient object is closed.


So, how do you get around this? One way would be to cache the RfcClient object, and then use that from multiple threads (for example). However, this really doesn’t help. The reason being, that the RfcClient object not only represents one channel factory, but also just one channel (which ultimately maps to one LOB connection). Therefore, if you have, say, 50 threads accessing the same RfcClient object, they will all ultimately end up using the same LOB connection, which will definitely not be good for performance.


What you really want to do, is open one channel factory, cache that, and then, open and close channels at will from that channel factory. When you open a channel, a connection will be obtained from the connection pool; and when you close the channel, the connection will be released back to the pool. Plus, the metadata cache will be shared across the channels, since they are part of the same channel factory.


So, how do you this? You can’t use the RfcClient proxy. Instead, you need to use the ChannelFactory<> class, and use the generated ServiceContract (which will be named Rfc if you added only RFCs in the “Add Adapter Service Reference” wizard). (You can always figure out the name of the interface, by looking up the definition of the generated proxy, and seeing which interface it implements). Thus, you need to do something like:


//do this only once
ChannelFactory<Rfc> factory = new ChannelFactory<Rfc>(binding);
factory.Open();
//cache the “factory” object somewhere.


//When you need to make a call to SAP:
Rfc channel = factory.CreateChannel(endpointAddress);
channel.RFC_CUSTOMER_GET();
((
IChannel)channel).Close();
//that’s all.


//When you ultimately want to free up
//all connections in the pool, and free
//up all the stored metadata,
factory.Close();

First it was QCSI, Now Trizetto, Is Apax Partners next?

Some official news:

http://www.247wallst.com/2008/04/trizetto-gets-a.html

Apax Partners is taking healthcare software company TriZetto Group Inc. private in a cash deal valued at roughly $1.4 billion, TriZetto said Friday, April 11.

In one of the few take-privates in recent months, shareholders will receive $22 per share in cash, a 25% premium to TriZetto’s closing price Thursday of $17.67.

BlueCross BlueShield of Tennessee and Regence Group, both customers of TriZetto, are helping to fund the buyout with an undisclosed amount of equity. Regence is a combination of several BlueCross BlueShield operations in the U.S.

TriZetto’s stock closed Friday up 15% to $20.39, near a 52-week high of $20.85. That gave it a market capitalization of $875 million. Its 52-week low is $14.52. The Newport Beach, Calif., company had $391 million of long-term debt and lease obligations on Dec. 31.

TriZetto provides software to health insurance plans and benefits administrators. Last year it booked $452 million of revenue, up 30% from 2006, a spokesman for the company said. Adjusted Ebitda, meanwhile, jumped 45%, from $67 million to $97 million, he said.

The bulk of its growth came from sales of its core administration software product, he said. Among other things, it helps manage healthcare claims and membership enrollment.

“A number of BlueCross and BlueShield plans signed up,” he said, adding that these new customers drove most of the gains in 2007.

TriZetto’s $1.4 billion take-private includes stock options and shares related to its outstanding convertible notes.

RBC Capital Markets is the sole underwriter for the debt financing, TriZetta said.

The U.S. healthcare system is disconnected, a TriZetto spokesman said, adding that the company’s software helps it “work more smoothly” by linking consumers, providers, employers and brokers.

We see the confluence of healthcare and information technology as a key area of focus for strategic investments,” Buddy Gumina, the head of U.S. healthcare at Apax Partners, said in a statement. TriZetto, he added, is poised to “drive positive changes in organized systems of healthcare, both in the U.S. and abroad.”

The same day the TriZetto take-private was announced, Aurora Capital Group‘s Mitchell International Inc. said it would merge with CCC Information Services Inc., which is owned by Investcorp, in an all-stock deal valued at $1.4 billion. The drive to utilize technology better in the healthcare sector, meanwhile, drove Nuance Communications Inc.‘s $400 million, April 8 deal to buy medical transcription software maker eScription Inc.

TriZetto said it does not anticipate any material changes in its product offerings, staffing or facility locations as a result of the buyout.

The company, founded in 1997 as MC Health Holdings, has made a number of acquisitions, including the 2007 purchase of Quality Care Solutions Inc., a deal valued at up to $146.2 million. In November 2005 it bought Boston-based CareKey Inc., an advanced-care management software maker, for $60 million with an add-on of up to $40 million if certain financial targets were met.

For financial advice on the take-private, Apax Partners turned to Deutsche Bank Securities Inc.‘s Sarah Bradley, Ravi Sachdev and Raul Gutierrez.

For counsel, it tapped Kirkland & Ellis LLP‘s Kirk Radke, Kimberly Taylor and Susan Zachman.

UBS Investment Bank‘s Robert DiGia, James Brennan, Matt Kim and Brad White advised TriZetto, which relied on Gibson, Dunn & Crutcher LLP‘s Thomas Magill, Erik Greupner, Drew Bordages and Kevin Schubert for legal advice.

Co-investors BlueCross BlueShield of Tennessee and Regence were advised by Cain Brothers & Co. LLC.

The buyout by Apax is expected to close in four to six months, pending shareholder and regulatory approvals.

I’m an MVP!

I just got this award a few days ago. Can you imagine? Me ,an MVP in Biztalk !! I was absolutely gobsmacked to receive it and am over the moon now. Its going to take me a while to come down.
Here’s an excerpt from the email
Dear Santosh Benjamin,
Congratulations! We are pleased to present you with […]

New WCF Adapter Code Samples on MSDN!

Hi,
Microsoft has released a couple of new WCF Adapter Code Samples on MSDN. Get them from here:

WCF Message Intermediary
Dynamically channel an incoming Windows Communication Foundation (WCF) client call to the correct version of a WCF Service using a BizTalk Server custom pipeline as a WCF intermediary. Posted on 4/10/2008.

WCF Message Interceptor
Custom message interception during BizTalk […]

April 11th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight

Here is the latest in my link-listing series.  Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I’ve done myself in the past.

ASP.NET

  • More ASP.NET Security Tutorials: The last three of Scott Mitchell’s excellent ASP.NET security tutorials.  His final three articles cover how to select user accounts, recover and change passwords, and unlock and approve user accounts.

  • Building a VS 2008 Styled Grid with the ListView and DataPager Controls: Matt Berseth has a great article that talks about techniques you can use with the new ASP.NET 3.5 ListView control to create a nicely styled Grid UI – while preserving total control over the HTML and CSS used.  Also read his follow-up post here that talks about how to achieve the same UI with the GridView control.

  • 50 Useful CSS Tips and Tricks: A useful page that provides a nice listing of various CSS tips, tricks and tools you can use for common web scenarios.

  • Using a DataPager with the GridView Control – Implementing IPageableItemContainer: Matt Berseth has a cool article that shows how to use the new IPageableItemContainer interface to implement paging support with the new ASP.NET 3.5 DataPager control.

ASP.NET AJAX

  • Accessible UpdatePanel: Bertrand Le Roy from the ASP.NET team has an article that describes how to make the ASP.NET AJAX’s UpdatePanel control accessible for screen-readers.

  • ASP.NET AJAX Meets Virtual Earth: Alessandro Gallo, author of the excellent ASP.NET AJAX in Action book, has a nice series of articles that talks about using ASP.NET AJAX with Virtual Earth to implement mapping on your site.

  • 3 Tips for Working with ASP.NET AJAX’s TabContainer Control: Matt Berseth continues his great articles on ASP.NET AJAX with some tips on working with the TabContainer control in the ASP.NET AJAX Control Toolkit.

  • Building ASP.NET AJAX Components: Mike Ormond has written an excellent 8-part series that covers building re-usable ASP.NET AJAX components that work on both the client and server.

ASP.NET MVC

  • An Introduction to ASP.NET MVC using VB: Bill Burrows from www.MyVBprof.com has put together a great set of online videos that introduce ASP.NET MVC using Visual Basic.  Also make sure to check out his video series on LINQ to XML using VB and LINQ to SQL using VB.

  • ASP.NET MVC: Membership Starter Kit: Troy Goode has a built an awesome membership starter kit for ASP.NET MVC that provides registration and login pages for users to authenticate on your site, as well as a set of administration functionality that allows admins to create/manage users and roles.  Download it here.

  • ASP.NET MVC: Action Filter for Handling Errors: Troy Goode has another good post that provides some ASP.NET MVC action filters for catching and handling runtime errors.

  • How to Enable Pretty URLs with ASP.NET MVC and IIS6: James Geurts posts a useful article that describes how to enable extension-less URLs with ASP.NET MVC on IIS6 (note: you do not need to configure anything special with ASP.NET MVC on IIS7 to enable extension-less URL support).

Visual Studio

  • PowerCommands for Visual Studio 2008: A free set of useful extensions for VS 2008 that add a bunch of cool features to the IDE.

Silverlight

  • Dave Campbell’s Excellent Silverlight Link Series: Dave Campbell posts a regular series of links to new Silverlight articles and content on the web.  I highly recommend subscribing to his blog if you want to stay current with all the latest Silverlight articles and posts.

  • Silverlight 2 Map / DataGrid Tutorial: Jason Zander has a great two-part Silverlight tutorial that demonstrates how to build a nice data-driven application that integrates a map control with a datagrid to filter and analyze data.

Hope this helps,

Scott

April 11th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Visual Studio, Silverlight

Here is the latest in my link-listing series.  Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I’ve done myself in the past.

ASP.NET

  • More ASP.NET Security Tutorials: The last three of Scott Mitchell’s excellent ASP.NET security tutorials.  His final three articles cover how to select user accounts, recover and change passwords, and unlock and approve user accounts.

  • Building a VS 2008 Styled Grid with the ListView and DataPager Controls: Matt Berseth has a great article that talks about techniques you can use with the new ASP.NET 3.5 ListView control to create a nicely styled Grid UI – while preserving total control over the HTML and CSS used.  Also read his follow-up post here that talks about how to achieve the same UI with the GridView control.

  • 50 Useful CSS Tips and Tricks: A useful page that provides a nice listing of various CSS tips, tricks and tools you can use for common web scenarios.

  • Using a DataPager with the GridView Control – Implementing IPageableItemContainer: Matt Berseth has a cool article that shows how to use the new IPageableItemContainer interface to implement paging support with the new ASP.NET 3.5 DataPager control.

ASP.NET AJAX

  • Accessible UpdatePanel: Bertrand Le Roy from the ASP.NET team has an article that describes how to make the ASP.NET AJAX’s UpdatePanel control accessible for screen-readers.

  • ASP.NET AJAX Meets Virtual Earth: Alessandro Gallo, author of the excellent ASP.NET AJAX in Action book, has a nice series of articles that talks about using ASP.NET AJAX with Virtual Earth to implement mapping on your site.

  • 3 Tips for Working with ASP.NET AJAX’s TabContainer Control: Matt Berseth continues his great articles on ASP.NET AJAX with some tips on working with the TabContainer control in the ASP.NET AJAX Control Toolkit.

  • Building ASP.NET AJAX Components: Mike Ormond has written an excellent 8-part series that covers building re-usable ASP.NET AJAX components that work on both the client and server.

ASP.NET MVC

  • An Introduction to ASP.NET MVC using VB: Bill Burrows from www.MyVBprof.com has put together a great set of online videos that introduce ASP.NET MVC using Visual Basic.  Also make sure to check out his video series on LINQ to XML using VB and LINQ to SQL using VB.

  • ASP.NET MVC: Membership Starter Kit: Troy Goode has a built an awesome membership starter kit for ASP.NET MVC that provides registration and login pages for users to authenticate on your site, as well as a set of administration functionality that allows admins to create/manage users and roles.  Download it here.

  • ASP.NET MVC: Action Filter for Handling Errors: Troy Goode has another good post that provides some ASP.NET MVC action filters for catching and handling runtime errors.

  • How to Enable Pretty URLs with ASP.NET MVC and IIS6: James Geurts posts a useful article that describes how to enable extension-less URLs with ASP.NET MVC on IIS6 (note: you do not need to configure anything special with ASP.NET MVC on IIS7 to enable extension-less URL support).

Visual Studio

  • PowerCommands for Visual Studio 2008: A free set of useful extensions for VS 2008 that add a bunch of cool features to the IDE.

Silverlight

  • Dave Campbell’s Excellent Silverlight Link Series: Dave Campbell posts a regular series of links to new Silverlight articles and content on the web.  I highly recommend subscribing to his blog if you want to stay current with all the latest Silverlight articles and posts.

  • Silverlight 2 Map / DataGrid Tutorial: Jason Zander has a great two-part Silverlight tutorial that demonstrates how to build a nice data-driven application that integrates a map control with a datagrid to filter and analyze data.

Hope this helps,

Scott