Sleeping process...

  • bytezone

    SSC-Addicted

    Points: 494

    Hi,

    Can anyone get back to me with tips regarding this.

    I am gettign connection pool error while using the .Net application. When i checked the Activity monitor on sql server 2005, i found that many process ID where presenet with status sleeping. When i check the details for these process ID, i found the SQL query in that. I then checked the applciation which executes the query..and found the connection is closing as well as doing a dispose() even on the connectin object. Then why does the activity monitor show so many process ID with sleeping status...??What does sleeping mean..???Any link i can refer to...??How to kill these process all togetther..??Now i restart when ever this prblem occurs..!!! or mnauly kill each process

    Looking forward to your suggestions..thanks...

  • Hans Lindgren

    SSChampion

    Points: 10494

    Hi,

    First of all; if you don't have thousands of sleeping connections you shouldn't worry about it.

    Sleeping means that it is, in that specific instance, not using CPU resources (amybe it will in 5 ms but not RIGHT now).

    .NET usually caches it's connection because it knows how expensive it is to open a new one (if you have done .Dispose() on it .NET 'knows' that you no longer need it and the GC will take care of it in time unless a new 'compatible' connection is requested).

    You can kill them manually or schedule a job (or something similar) to kill the SPIDs but I would definitly not recommend it for general use.

    Regards,

    Hanslindgren

  • K. Brian Kelley

    SSC Guru

    Points: 114465

    One thing to remember is that with pooling in effect, if you close a connection, the operating system is going to hold it open for a length of time (the default is 1 minute). It does this in case another connection request comes through with the same credentials. It'll then re-use the connection. This tends to be done for performance reasons: the connect/disconnect affects CPU/memory on both the client and SQL Server system. Of course, if the operating system needs to open more connections, it will, so you could potentially have a lot of sleeping connections and that be normal behavior over time (even though the application code explicitly closes out the connection). How long have the processes been sleeping and what is the exact error?

    K. Brian Kelley
    @kbriankelley

  • bytezone

    SSC-Addicted

    Points: 494

    Thanks everyone for all the suggestion. May be i was looking problem at a wrong place.

    I have an ASP.net application which sues SQL server 2005. After some time of its usage, users are getting error message as "Server pool reached..blah blah.." I thought this as got to do with SQl server, i guess from what i have learn so far...multiple conenctions are getting opened. I am now trying to go through each line of code to see if i am clsoing the connection.

    Any tips on this...i mean how to write a data access code so that this kind of pooling problem does not happen..????

    Also is there any way i can find the number of connection opened on IIS.???I mean the connection pool used..???

    Thanka in advance...

  • Maqsood Ahmad

    Old Hand

    Points: 368

    When I check in Activity Monitor of SQL Server 2005 I also see few connections in sleeping status. I understand if C#.NET application is using Pooling, for performance reason SQL Server does not destroy those connections for LIMITED TIME even if you have closed that connection. But what If C#.NET application is using pooling and closing connections after finishing with it but even after 6-7 days those connections are still in sleeping mode. I can tell this by Last Batch column from Activity Monitor.

    FYI once my application starts we don’t close that application until we have to restart our machine due to Windows updates, means our application runs for long period of time without restart.

    In the attached screenshot you can see that some connections were created at 27/08/2008 and their last batch was same time but even after 8 days they are still sleeping. Shouldn't they destroyed by SQL Server??

  • Hans Lindgren

    SSChampion

    Points: 10494

    Maqsood Ahmad:

    Why do you think that SQL Server would destroy your SPIDs? Having SQL Server doing that sounds rather absurd...

    Hanslindgren

  • Maqsood Ahmad

    Old Hand

    Points: 368

    Hanslindgren:

    I am just wondering that after 8 days these connection are still sleeping and might consume some resources. You think it is right behaviour of my SQL Server or my application

    Thanks

  • Hans Lindgren

    SSChampion

    Points: 10494

    Maqsood Ahmad: A sleeping connection at most cosumes a couple of KB of memory (totally neglible). If your application is not restarted then the connections will linger and save you on future connection costs (connection setups are quite expensive but leaving them open/sleeping is very very cheap).

    I.e. sleeping connections are not a problem in SQL Server.

    Regards,

    Hanslindgren

  • Maqsood Ahmad

    Old Hand

    Points: 368

    Its mean then I should now be worried about it

    Thanks

  • Ron McCullough

    SSC Guru

    Points: 63877

    Maqsood from:

    From: http://blogs.msdn.com/psssql/archive/2008/04/21/how-it-works-what-is-a-sleeping-awaiting-command-session.aspx%5B/url%5D

    This issue is as old as SQL Server. In fact, it goes back to Sybase days but continues to fool and puzzle administrators.

    A session with that status of sleeping / awaiting command is simply a client connection with no active query to the SQL Server.

    The table below shows the transitions from running to sleeping states for a session.

    Connect Running

    Connect Completed Sleeping / Awaiting Command

    select @@VERSION Running

    select completed Sleeping / Awaiting Command

    The question usually arises around a session that is holding locks and its state is sleeping / awaiting command.

    If the client has an open transaction and the client did not submit a commit or rollback command the state is

    sleeping / awaiting command.

    The situation can be caused by many other variations but it is always a situation where the SQL Server is

    waiting for the next command from the client.

    Outside a physical connection problem these are always application design issues.

    Hope this helps your understanding of what you have observed.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Anand S-265483

    SSC Enthusiast

    Points: 127

    Hi Brian,

    I am facing a similar problem in my project - I don't see the issue in development, but when we move to production the number of sleeping connections grow rapidly and sql server starts refusing new connections (the software is pretty useless at this stage).

    You mention that after closing, sql server holds the connection for a period of time (1 min or so). Is there any documentation that gives this information and also any idea whether this number is tunable/Changeable ?

    thanks

    Anand

  • Hans Lindgren

    SSChampion

    Points: 10494

    Anand S (5/8/2009)


    Hi Brian,

    I am facing a similar problem in my project - I don't see the issue in development, but when we move to production the number of sleeping connections grow rapidly and sql server starts refusing new connections (the software is pretty useless at this stage).

    You mention that after closing, sql server holds the connection for a period of time (1 min or so). Is there any documentation that gives this information and also any idea whether this number is tunable/Changeable ?

    thanks

    Anand

    Yes, there is documentation. You need to check the specific one for you development language/environment. The connection pooling is on your application side and not on your DB side... In most languages you can turn connection pooling off...

    (Maybe can be worth checking into your connection strings, that they are the same over the whole application. Constantly changing configuration strings makes connection pooling almost useless).

    Not using a DAL approach might also negate the use of connection pooling...

  • Anand S-265483

    SSC Enthusiast

    Points: 127

    Hi,

    I am using Asp.net webservice to invoke the connections. In this case does .Net provide connection pooling. I thought the db creates and manages the connection pool.

    We are creating the connection string using default values, so connection pooling is true. We use one single connection string , so the connections are for the same string.

    Not using a DAL approach might also negate the use of connection pooling...

    >> We are using a data access layer approach by having the connection,sql in a separate class

    The transactions are committed and disposed. Connections are closed on success (Also rollbacks, connection close on exceptions).

    The connections continue in "sleeping" status even after the close. What would cause that? and how is the time configurable - i.e. the time that sqlserver maintains a connection in active status after it is closed by .net ?

  • naga.rohitkumar

    SSCertifiable

    Points: 5470

    It may happen even if the user who executed the query in sql server may not closed the query window from long time once if the query window closed then you can't see the spid in the activity monitor

    Thanks
    Naga.Rohitkumar

  • reddysiri517

    SSC Journeyman

    Points: 92

    Hello All,

    Good day, please confirm sleeping sessions or stale session in sql server will use CPU.

    If we kill sleeping sessions,CPU will come down. Please elabrate on this topic, thanks a ton in advance.

    Regards,

    Sireesha.

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic. Login to reply