cancel
Showing results for 
Search instead for 
Did you mean: 

.Net Connector Connection Pooling problem

Former Member
0 Kudos

Hi,

Facing some connection pooling issues.

Using the V2.0 of .Net connector.

Connection pool setting has been incorporated in to the Config file, and config file entries look like this.

UseAutoPooling="true"

MaxOpenConnections="10"

MaxCapacity="10"

MaxIdleTime="2"

CleanupInterval="2" />

<Destinations Default="SAP">

<Entry DestinationName="SAP" AppServerHost="sapai0ci.fm.intel.com" SystemNumber="0" Username="sapuser"

Password="*****" Client="250" />

</Destinations>

These settings are getting loaded once the AppServer starts up. I Could see these entries in the Watch window(during debugging). The problem we are facing is that the request for 11th connection is hanging. I could see that 10 connections are open(c:\netstat). 10 connections are already available in pool but the request for a new connection does not seem to be picked up from the pool.

here is the piece of code that we are using make the call.

SAPProxy1 local_obj_Proxy;

try

{

local_obj_Proxy = new SAPProxy1();

local_obj_Proxy.Connection = Connection.GetConnection(Config.Instance.GetDestinationByName("SAP"));//this should get a new connection pool according the documentation

//make the RFC call

}

catch(Exception e)

{

//exceptions

}

finally

{

local_obj_Proxy.Connection.Dispose();//this should hand the connection back to pool

}

No Exceptions are thrown, and AppServer works fine for first 10 connections and hangs forever for the 11th connection at the GetConnection() function.

Appreciate any help in resolving this issue.

Regards,

Ravi

Accepted Solutions (0)

Answers (1)

Answers (1)

reiner_hille-doering
Active Contributor
0 Kudos

This behavior is by design: You have set MaxOpenConnections to 10. This means that only 10 connection would be opened, the 11th try to open one would make the thread blocking until 1 is getting free. This is intended to limit the load to your application server caused by your NCo-based application.

Assume this order of calls:

1. GetConnectionFromPool(Dest)

...

10. GetConnectionFromPool(Dest)

11. GetConnectionFromPool(Dest) (this will block)

ReturnConnection() (this will stop 11. from blocking).

Former Member
0 Kudos

> This behavior is by design: You have set

> MaxOpenConnections to 10. This means that only 10

> connection would be opened, the 11th try to open one

> would make the thread blocking until 1 is getting

> free. This is intended to limit the load to your

> application server caused by your NCo-based

> application.

> Assume this order of calls:

> 1. GetConnectionFromPool(Dest)

> ...

> 10. GetConnectionFromPool(Dest)

> 11. GetConnectionFromPool(Dest) (this will block)

> ReturnConnection() (this will stop 11. from blocking).

Thanks for the quick reply Reiner,

Yes GetConnectionFromPool() and ReturnConnection() are being called in pair. From the documentation if Autopooling is enabled then Getconnection will always get a connection from pool and Connection.displose will hand it back to the pool.

The above code is a part of a function that is getting called through different threads(same process). The function call time is not more than few seconds. So if all the 10 threads were make simulteneasly, the 11th thread will only need to wait a few seconds before it can get a connection from the pool. but this is not the case, even though all the 10 threads are done with their function call, the 11 thread is waiting endlessly for a connection object.

Regards,

Ravi

reiner_hille-doering
Active Contributor
0 Kudos

Hm, this sound like a bug...

Can you please try the following things:

- Only to be sure, replace connection.Dispose by Connection.ReturnConnection.

- Create a log file where you write the GetConnection / ReturnConnection (mixed from all threads). This allows to see how the calls are interleaved.

Thanks,

Reiner.

Former Member
0 Kudos

Tried the same code by replacing 'GetConnection' with

1. GetConnectionFromPool

2. SAPConnection.GetConnectionFromPool

and 'Connection.dispose' with

1.ReturnConnection

2.SAPconnection.ReturnConnection

All the combination resulted the same..the 11th request hangs endlessly.

Thanks Again,

Ravi

Former Member
0 Kudos

Seems to be a bug. Dispose method or ReturnConnection should have added connection(in open state) back to the pool. This doesn't seem to be happening resulting in an new connection object creation and incrementing the count. Once the count increases to MaxOpenConnection, the next request for connection will hang forever.

The following single threaded code is also failing..

Set the MaxOpenConnections="10" and request for 11th connection hangs.

SAPProxy1 local_obj_Proxy = null;

try

{

local_obj_Proxy = new SAPProxy1();

for(int i =1;i<12;i++)

{

local_obj_Proxy.Connection = Connection.GetConnectionFromPool(Config.Instance.GetDestinationByName("SAP"));

local_obj_Proxy.Connection.Open();

//local_obj_Proxy.Connection.Close();

local_obj_Proxy.Connection.Dispose();

//Connection.ReturnConnection(local_obj_Proxy.Connection);

}

}

catch(Exception e)

{

Console.Write(e.Message);

}

finally

{

}

reiner_hille-doering
Active Contributor
0 Kudos

I just tested your code and can't repro.

Can you please try the following things:

- Move the call to GetDestinationByName out of the loop:

Destination dest = Config.Instance.GetDestinationByName("SAP");

...

local_obj_Proxy.Connection = Connection.GetConnectionFromPool(dest);

- If this doesn't change the behavior, please turn on .NET Connection tracing and paste the result: In config file add an entry like:

<SAP>

<Connector>

<Trace Level="Info" File="Test.trc"/>

Former Member
0 Kudos

Tried your recommendations and the result is still the same.

here is the contents of trace file..

2005-03-18 15:49:57Z Trace file opened.

2005-03-18 15:49:57Z Allowed to fetch new.

2005-03-18 15:49:57Z AllocReservation: 0

2005-03-18 15:50:00Z Allowed to fetch new.

2005-03-18 15:50:00Z AllocReservation: 1

2005-03-18 15:50:03Z Allowed to fetch new.

2005-03-18 15:50:03Z AllocReservation: 2

2005-03-18 15:50:06Z Allowed to fetch new.

2005-03-18 15:50:06Z AllocReservation: 3

2005-03-18 15:50:09Z Allowed to fetch new.

2005-03-18 15:50:09Z AllocReservation: 4

2005-03-18 15:50:11Z Allowed to fetch new.

2005-03-18 15:50:11Z AllocReservation: 5

2005-03-18 15:50:14Z Allowed to fetch new.

2005-03-18 15:50:14Z AllocReservation: 6

2005-03-18 15:50:17Z Allowed to fetch new.

2005-03-18 15:50:17Z AllocReservation: 7

2005-03-18 15:50:20Z Allowed to fetch new.

2005-03-18 15:50:20Z AllocReservation: 8

2005-03-18 15:50:22Z Allowed to fetch new.

2005-03-18 15:50:22Z AllocReservation: 9

reiner_hille-doering
Active Contributor
0 Kudos

Ok, thanks.

From the trace it's obvious that either the collection is not put into pool at all after use (which I don't believe) or that it is not considered fitting when tried to fetch from pool. To check this, please try the following: replace GetConnectionFromPool(dest) with GetConnectionFromPool(dest.ConnectionString). My assumption is still that you are having (for some reason) different destinations in the pool which are not regarded fitting. The change would do the match by connectionString, which is a bit more tolerant.

Former Member
0 Kudos

Sorry again, the results are the same.. Can you share the trace file which is generated in your end?

reiner_hille-doering
Active Contributor
0 Kudos

Very strange. My log file looks like this:

2005-03-18 10:42:41Z Trace file opened.

2005-03-18 10:42:41Z Allowed to fetch new.

2005-03-18 10:42:41Z AllocReservation: 0

2005-03-18 10:42:42Z Found right now.

2005-03-18 10:42:43Z Found right now.

2005-03-18 10:42:44Z Found right now.

2005-03-18 10:42:45Z Found right now.

2005-03-18 10:42:46Z Found right now.

2005-03-18 10:42:46Z Found right now.

2005-03-18 10:42:46Z Found right now.

2005-03-18 10:42:47Z Found right now.

2005-03-18 10:42:47Z Found right now.

2005-03-18 10:42:48Z Found right now.

2005-03-18 10:46:01Z Releasing: 1

Is there a chance to debug on your machine (either via OSS or directly, e.g. with netmeeting)?

Former Member
0 Kudos

Netmeeting might not be possible as I am behind a firewall, I do have OSS access how do we debug through OSS?

reiner_hille-doering
Active Contributor
0 Kudos

OSS allows to setup service connections that also contain NetMeeting, Windows Terminal Services or pcAnywhere. But before you do so, perhaps you send me the repro program (complete VS-solution) via OSS ticket or as E-Mail (you should find my address somewhere in the forum).

Former Member
0 Kudos

I am unable to find your email-id in the forum. Please do send me a mail at ravikiran.vijaya@intel.com, then i can reply to that.

Thanks

Ravi