views:

229

answers:

3

We are facing serious problems with performance in the database. After making a lot of changes in the procedures, trying to minimize locks, we still have some problems of performance.

When I make a sp_who2 in the database, there are several connections in sleeping mode, "Awaiting command".

Maybe if I close these connections automatically after closing them, we could have a positive impact on the server performance.

And my question is: How to make connection pooling in ADO.NET close my connections when I call the close, instead of maintaining them in sleeping mode?

PS: I know handling performance is a large topic, we are analyzing more than just this.

+1  A: 

You could disable the connection pool, but that would not increase performance.

The connection pool hangs on the the connections, so that the application doesn't have to create a new connection each time. Reusing a connection is a lot faster than opening a new one.

So, the sleeping connections is an indication that the connection pool works, and you should not try to get rid of it.

Guffa
But I have around 400 connections, a lot awaiting command. My application is having a lot of timeouts. Isn't the connection pool making my application run slower?
Victor Rodrigues
No, unused connections uses very little resources. A large number of created connections is rather a sympthom of the timeouts, not the cause.
Guffa
+2  A: 

The point of connection pooling is to keep connections open so that when you want a new connection it is there. The reason to do this is that opening a connection is a costly business. Keeping a sleeping connection does not usually cost much.

If you want to close the connection fully then turn connection pooling off.

Mark
A: 

Well, one potential problem you could have it too many connection pools!

Connection pool will be based on the exact connection string - if two connection strings differ only by a space, they'll be considered different, and one connection pool will be created for each. So make sure all your connection strings are absolutely identical.

Also, one connection pool will be created per Windows identity - so if you use

server=myServer;Database=MyDatabase;integrated security=SSPI

then for each separate Windows user that will connect, a connection pool is being created.

See the relevant MSDN documentation for this (fourth paragraph from the top):

Connections are separated into pools by connection string, and by Windows identity when integrated security is used.

So in a heavy loaded production environment, it might be a better idea to use a single "application user" and have just a single connection pool:

server=myServer;Database=MyDatabase;user id=MyAppUser;pwd=MyAppUserPwd

If you make sure all client machines are all using this exact same connection string, only a single connection pool will be created.

Marc

marc_s
hmm, thanks, I didn't know it, but this is not the cause. I have only one connection string for the whole application. Note: Even trying to set Pooling=false, it is not working, pooling continues.
Victor Rodrigues
hmm [2], this can be a problem. I have around 20 connection pools in my application (in fact there are application instances, all of them with the same connection string, but in different sites in IIS). Can this be incredibly harmful for the database?
Victor Rodrigues
note: the IIS server is not 100% CPU, it is good actually. The Sql server that is 100% Cpu.
Victor Rodrigues
No, even 20 pools, if not fully used, aren't harmful
marc_s
They are actually between 40 and 60 connection pools. I'm not seeing in perfmon a way to list all of them, only per instance.
Victor Rodrigues
It wasn't a problem with pooling, as expected... I fixed some indexes and the database is running super fast \o/
Victor Rodrigues
@Victor: excellent! Yes, indices are both a god-send (you can't speed up a database more than by having the right indices), but at the same time, you can also screw up more than anything else with the wrong (or missing) indices :-)
marc_s