asp_wp.exe utilized 100% of CPU

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Danny Ni

    asp_wp.exe utilized 100% of CPU

    Hi,

    I inherited a web project from other programmer. I notice on my dev
    machine every time I request a page in IE or FF the CPU jumps to 100%, all
    utilized by asp_wp.exe.

    I did some researches on the web, somebody suggests this could be due to
    database connection not properly disposed. I happened to see the following
    code snippet in my web project:

    static public IDataReader GetRS(String Sql)
    {
    SqlConnection dbconn = new SqlConnection() ;
    dbconn.Connecti onString = DB.GetDBConn();
    dbconn.Open();
    SqlCommand cmd = new SqlCommand(Sql, dbconn);
    return cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
    }

    I don't see dbconn.Dispose( ) or cmd.Dispose() getting called. Is this a
    problem? If it is, where should I put the cmd.Dispose() and
    dbconn.Dispose( )?

    TIA


  • Cor Ligthert[MVP]

    #2
    Re: asp_wp.exe utilized 100% of CPU

    Danny,

    It would be rare if this code would be the reason of your extreme use of the
    memory.

    The connection dispose was AFAIK in the 1.0 and 1.1 version important for
    the connection pool, as it was overloaded with the releasing of the string,
    the close should do the same now as they are the same. But the connection
    pool does in my idea nothing with a high memory use.

    But do you have other strange effects than that you see this somewhere in a
    kind of taskmanager?

    Cor

    "Danny Ni" <dndn@yahoo.com schreef in bericht
    news:eAJAIeCpIH A.4904@TK2MSFTN GP03.phx.gbl...
    Hi,
    >
    I inherited a web project from other programmer. I notice on my dev
    machine every time I request a page in IE or FF the CPU jumps to 100%,
    all utilized by asp_wp.exe.
    >
    I did some researches on the web, somebody suggests this could be due to
    database connection not properly disposed. I happened to see the following
    code snippet in my web project:
    >
    static public IDataReader GetRS(String Sql)
    {
    SqlConnection dbconn = new SqlConnection() ;
    dbconn.Connecti onString = DB.GetDBConn();
    dbconn.Open();
    SqlCommand cmd = new SqlCommand(Sql, dbconn);
    return cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
    }
    >
    I don't see dbconn.Dispose( ) or cmd.Dispose() getting called. Is this a
    problem? If it is, where should I put the cmd.Dispose() and
    dbconn.Dispose( )?
    >
    TIA
    >

    Comment

    • Peter Duniho

      #3
      Re: asp_wp.exe utilized 100% of CPU

      On Mon, 21 Apr 2008 20:18:27 -0700, Danny Ni <dndn@yahoo.com wrote:
      I inherited a web project from other programmer. I notice on my dev
      machine every time I request a page in IE or FF the CPU jumps to 100%,
      all
      utilized by asp_wp.exe.
      >
      I did some researches on the web, somebody suggests this could be due to
      database connection not properly disposed. I happened to see the
      following
      code snippet in my web project:
      >
      static public IDataReader GetRS(String Sql)
      {
      SqlConnection dbconn = new SqlConnection() ;
      dbconn.Connecti onString = DB.GetDBConn();
      dbconn.Open();
      SqlCommand cmd = new SqlCommand(Sql, dbconn);
      return cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
      }
      >
      I don't see dbconn.Dispose( ) or cmd.Dispose() getting called. Is this a
      problem? If it is, where should I put the cmd.Dispose() and
      dbconn.Dispose( )?
      Well, according to the docs, closing the connection is "functional ity
      equivalent" to disposing it. So I would expect the CloseConnection value
      passed to the ExecuteReader() method to handle that for you. However,
      that still leaves the SqlCommand instance undisposed.

      If you're concerned that CloseConnection might not be sufficient or that
      failure to dispose the SqlCommand is also a potential problem, you could
      always call Dispose() on them after calling ExecuteReader() and before
      returning:

      static public IDataReader GetRS(String Sql)
      {
      SqlConnection dbconn = new SqlConnection() ;
      IDataReader reader;

      dbconn.Connecti onString = DB.GetDBConn();
      dbconn.Open();
      SqlCommand cmd = new SqlCommand(Sql, dbconn);
      reader = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
      cmd.Dispose();
      dbconn.Dispose( );
      return reader;
      }

      Or perhaps preferable even:

      static public IDataReader GetRS(String Sql)
      {
      using (SqlConnection dbconn = new SqlConnection() )
      {
      dbconn.Connecti onString = DB.GetDBConn();
      dbconn.Open();

      using (SqlCommand cmd = new SqlCommand(Sql, dbconn))
      {
      return
      cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
      }
      }
      }

      If with those changes, you still have the high CPU problem, then obviously
      a simple lack of disposal isn't your problem. I suppose you might look
      into whether disabling connection pooling affects the behavior (which
      connection pooling, a close/dispose doesn't necessarily actually close the
      connection). But that doesn't necessarily mean you'd actually want to
      disable connection pooling; it's just a way of getting more information
      about what's going on.

      Is the high CPU usage actually causing a problem? If the process is at a
      low enough priority, I would expect it to not be an issue. If it's
      intentional, then hopefully the code is careful to run at a lower
      priority. If it's a bug, I suppose all bets are off...sorry for not
      having any specific knowledge about that particular behavior.

      Pete

      Comment

      • Danny Ni

        #4
        Re: asp_wp.exe utilized 100% of CPU

        Cori,

        The pages came out correctly even though CPU jumped to 100% then went down.
        However if I do some stress testing (simulate 10 simultaneous connections)
        to my machine, CPU stays at neayly 100 % at all time and I notice the
        response slows down quite a bit. I guessed it's just my dev machine then.


        "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
        news:8A1877D8-36F0-4297-B77B-4F55C32174B3@mi crosoft.com...
        Danny,
        >
        It would be rare if this code would be the reason of your extreme use of
        the memory.
        >
        The connection dispose was AFAIK in the 1.0 and 1.1 version important for
        the connection pool, as it was overloaded with the releasing of the
        string, the close should do the same now as they are the same. But the
        connection pool does in my idea nothing with a high memory use.
        >
        But do you have other strange effects than that you see this somewhere in
        a kind of taskmanager?
        >
        Cor
        >
        "Danny Ni" <dndn@yahoo.com schreef in bericht
        news:eAJAIeCpIH A.4904@TK2MSFTN GP03.phx.gbl...
        >Hi,
        >>
        >I inherited a web project from other programmer. I notice on my dev
        >machine every time I request a page in IE or FF the CPU jumps to 100%,
        >all utilized by asp_wp.exe.
        >>
        >I did some researches on the web, somebody suggests this could be due to
        >database connection not properly disposed. I happened to see the
        >following code snippet in my web project:
        >>
        > static public IDataReader GetRS(String Sql)
        > {
        > SqlConnection dbconn = new SqlConnection() ;
        > dbconn.Connecti onString = DB.GetDBConn();
        > dbconn.Open();
        > SqlCommand cmd = new SqlCommand(Sql, dbconn);
        > return cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
        > }
        >>
        >I don't see dbconn.Dispose( ) or cmd.Dispose() getting called. Is this a
        >problem? If it is, where should I put the cmd.Dispose() and
        >dbconn.Dispose ()?
        >>
        >TIA
        >>
        >

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: asp_wp.exe utilized 100% of CPU

          Peter,

          The command is AFAIK managed code that has no unmanaged resources.

          In my idea are you only spoiling time in by letting calling senseless times
          the dispose l. (It would not heart the processor probably for less then
          0.0001 procent, however).

          Using the using is in this sitation only helping that you are writing from a
          personal view maybe a little bit more elegant code (which than includes as
          in every for you generic created code some overhead, but that falls than in
          that 0.0001 procent).

          From the three ways of coding I have seen now in this thread, I found the
          way from Danny the nicest, so what is wrong with that?

          Cor

          "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.coms chreef in bericht
          news:op.t9zulia a8jd0ej@petes-computer.local. ..
          On Mon, 21 Apr 2008 20:18:27 -0700, Danny Ni <dndn@yahoo.com wrote:
          I inherited a web project from other programmer. I notice on my dev
          machine every time I request a page in IE or FF the CPU jumps to 100%,
          all
          utilized by asp_wp.exe.
          >
          I did some researches on the web, somebody suggests this could be due to
          database connection not properly disposed. I happened to see the
          following
          code snippet in my web project:
          >
          static public IDataReader GetRS(String Sql)
          {
          SqlConnection dbconn = new SqlConnection() ;
          dbconn.Connecti onString = DB.GetDBConn();
          dbconn.Open();
          SqlCommand cmd = new SqlCommand(Sql, dbconn);
          return cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
          }
          >
          I don't see dbconn.Dispose( ) or cmd.Dispose() getting called. Is this a
          problem? If it is, where should I put the cmd.Dispose() and
          dbconn.Dispose( )?
          Well, according to the docs, closing the connection is "functional ity
          equivalent" to disposing it. So I would expect the CloseConnection value
          passed to the ExecuteReader() method to handle that for you. However,
          that still leaves the SqlCommand instance undisposed.

          If you're concerned that CloseConnection might not be sufficient or that
          failure to dispose the SqlCommand is also a potential problem, you could
          always call Dispose() on them after calling ExecuteReader() and before
          returning:

          static public IDataReader GetRS(String Sql)
          {
          SqlConnection dbconn = new SqlConnection() ;
          IDataReader reader;

          dbconn.Connecti onString = DB.GetDBConn();
          dbconn.Open();
          SqlCommand cmd = new SqlCommand(Sql, dbconn);
          reader = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
          cmd.Dispose();
          dbconn.Dispose( );
          return reader;
          }

          Or perhaps preferable even:

          static public IDataReader GetRS(String Sql)
          {
          using (SqlConnection dbconn = new SqlConnection() )
          {
          dbconn.Connecti onString = DB.GetDBConn();
          dbconn.Open();

          using (SqlCommand cmd = new SqlCommand(Sql, dbconn))
          {
          return
          cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
          }
          }
          }

          If with those changes, you still have the high CPU problem, then obviously
          a simple lack of disposal isn't your problem. I suppose you might look
          into whether disabling connection pooling affects the behavior (which
          connection pooling, a close/dispose doesn't necessarily actually close the
          connection). But that doesn't necessarily mean you'd actually want to
          disable connection pooling; it's just a way of getting more information
          about what's going on.

          Is the high CPU usage actually causing a problem? If the process is at a
          low enough priority, I would expect it to not be an issue. If it's
          intentional, then hopefully the code is careful to run at a lower
          priority. If it's a bug, I suppose all bets are off...sorry for not
          having any specific knowledge about that particular behavior.

          Pete

          Comment

          • Peter Duniho

            #6
            Re: asp_wp.exe utilized 100% of CPU

            On Mon, 21 Apr 2008 21:32:18 -0700, Cor Ligthert[MVP]
            <notmyfirstname @planet.nlwrote :
            The command is AFAIK managed code that has no unmanaged resources.
            Based on what exactly? Have you investigated the actual implementation of
            SqlCommand and found it to have no need of actually being disposed? It
            has a Dispose() method. Therefore it is more correct to dispose than to
            not dispose.
            In my idea are you only spoiling time in by letting calling senseless
            times the dispose l. (It would not heart the processor probably for less
            then 0.0001 procent, however).
            Forgive me if I'm amused at your nitpicking of whether to dispose or not,
            based solely on some imagined wastefulness in calling a Dispose() method
            that you believe to do nothing. Especially since the OP specifically
            mentioned CPU time and your reply went on about memory usage (something
            that the OP never mentioned as being a problem). :)
            [...]
            From the three ways of coding I have seen now in this thread, I found
            the way from Danny the nicest, so what is wrong with that?
            He specifically mentioned finding references online saying that lack of
            disposal of the SqlConnection may lead to high CPU utilization. It stands
            to reason that explicitly disposing it would be worth trying. Likewise,
            disposing anything else in the code that implements IDisposable.

            So, that's "what is wrong with that". Telling the guy to just leave his
            code the way it is, that will guarantee that the issue will not be
            resolved. Will changing it fix the issue? I have no idea...it's not my
            code. Only the OP is in a position to see if the changes help. But it's
            worth a try.

            And it's a heck of a lot better than telling someone who is concerned
            about high CPU utilization that "It would be rare if this code would be
            the reason of your extreme use of the memory", when he never said anything
            at all about "extreme use of the memory" in the first place. :p

            Pete

            Comment

            • Willy Denoyette [MVP]

              #7
              Re: asp_wp.exe utilized 100% of CPU

              "Danny Ni" <dndn@yahoo.com wrote in message
              news:eAJAIeCpIH A.4904@TK2MSFTN GP03.phx.gbl...
              Hi,
              >
              I inherited a web project from other programmer. I notice on my dev
              machine every time I request a page in IE or FF the CPU jumps to 100%,
              all utilized by asp_wp.exe.
              >
              I did some researches on the web, somebody suggests this could be due to
              database connection not properly disposed. I happened to see the following
              code snippet in my web project:
              >
              static public IDataReader GetRS(String Sql)
              {
              SqlConnection dbconn = new SqlConnection() ;
              dbconn.Connecti onString = DB.GetDBConn();
              dbconn.Open();
              SqlCommand cmd = new SqlCommand(Sql, dbconn);
              return cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
              }
              >
              I don't see dbconn.Dispose( ) or cmd.Dispose() getting called. Is this a
              problem? If it is, where should I put the cmd.Dispose() and
              dbconn.Dispose( )?
              >
              TIA
              >

              Note that it's quite normal to see 100% CPU spikes if you run this all on a
              single machine with only a single CPU and a limited amount of RAM. A
              development box is not meant to run Web application benchmarks or
              performance tests.
              How long does the CPU stay at 100%? 1msec, 100 msec?
              What kind of CPU do you have it running on?
              How many CPU's do you have in this machine?
              How much RAM do you have installed in this box?
              How much memory is there reserved by SQL Server (this supposing it's running
              on the same box).
              Do you run this with VS loaded?
              Did you look at the page fault counters?


              Willy.

              Comment

              • Ignacio Machin ( .NET/ C# MVP )

                #8
                Re: asp_wp.exe utilized 100% of CPU

                On Apr 21, 11:18 pm, "Danny Ni" <d...@yahoo.com wrote:
                Hi,
                >
                I inherited a web project  from other programmer.  I notice on my dev
                machine  every time I request a page in IE or FF the CPU jumps to 100%,  all
                utilized by asp_wp.exe.
                >
                I did some researches on the web, somebody suggests this could be due to
                database connection not properly disposed. I happened to see the following
                code snippet in my web project:
                >
                        static public IDataReader GetRS(String Sql)
                        {
                            SqlConnection dbconn = new SqlConnection() ;
                            dbconn.Connecti onString = DB.GetDBConn();
                            dbconn.Open();
                            SqlCommand cmd = new SqlCommand(Sql, dbconn);
                            return cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
                        }
                >
                I don't see dbconn.Dispose( ) or cmd.Dispose() getting called. Is this a
                problem? If it is, where should I put the cmd.Dispose() and
                dbconn.Dispose( )?
                >
                TIA
                Find where that method is called and make sure that the connection is
                close, then repeat your test

                Comment

                Working...