473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.ConnectionString = DB.GetDBConn();
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}

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
Jun 27 '08 #1
7 1483
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" <dn**@yahoo.comschreef in bericht
news:eA**************@TK2MSFTNGP03.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.ConnectionString = DB.GetDBConn();
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}

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
Jun 27 '08 #2
On Mon, 21 Apr 2008 20:18:27 -0700, Danny Ni <dn**@yahoo.comwrote:
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.ConnectionString = DB.GetDBConn();
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}

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 "functionality
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.ConnectionString = DB.GetDBConn();
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
cmd.Dispose();
dbconn.Dispose();
return reader;
}

Or perhaps preferable even:

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

using (SqlCommand cmd = new SqlCommand(Sql, dbconn))
{
return
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}
}
}

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
Jun 27 '08 #3
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]" <no************@planet.nlwrote in message
news:8A**********************************@microsof t.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" <dn**@yahoo.comschreef in bericht
news:eA**************@TK2MSFTNGP03.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.ConnectionString = DB.GetDBConn();
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}

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

Jun 27 '08 #4
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" <Np*********@nnowslpianmk.comschreef in bericht
news:op***************@petes-computer.local...
On Mon, 21 Apr 2008 20:18:27 -0700, Danny Ni <dn**@yahoo.comwrote:
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.ConnectionString = DB.GetDBConn();
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}

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 "functionality
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.ConnectionString = DB.GetDBConn();
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
cmd.Dispose();
dbconn.Dispose();
return reader;
}

Or perhaps preferable even:

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

using (SqlCommand cmd = new SqlCommand(Sql, dbconn))
{
return
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}
}
}

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

Jun 27 '08 #5
On Mon, 21 Apr 2008 21:32:18 -0700, Cor Ligthert[MVP]
<no************@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
Jun 27 '08 #6
"Danny Ni" <dn**@yahoo.comwrote in message
news:eA**************@TK2MSFTNGP03.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.ConnectionString = DB.GetDBConn();
dbconn.Open();
SqlCommand cmd = new SqlCommand(Sql, dbconn);
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}

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.

Jun 27 '08 #7
On Apr 21, 11:18*pm, "Danny Ni" <d...@yahoo.comwrote:
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.ConnectionString = DB.GetDBConn();
* * * * * * dbconn.Open();
* * * * * * SqlCommand cmd = new SqlCommand(Sql, dbconn);
* * * * * * return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
* * * * }

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
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: | last post by:
newbie code -------------------------- #include <iostream> using namespace std; #include <cstring> class aaa {
1
by: Donna | last post by:
How can I stop the asp_wp process on my computer? Each time I 'm stopping it in the taskmanager the process is started automatical again! Thanks Donna
0
by: GregO | last post by:
Windows 2000 Server SP3 ..NET Framework 1.1 I have a problem opening the control panel on a number of servers. Only when we kill the asp_wp.exe does the control panel kick into life. Is it...
4
by: Rich Denis | last post by:
Hello, We are having some issues with our .NET web applications. Every so often a computer will peg its CPU at 100% for some period of time. I am told anywhere between 30mins and 2 hours. I...
1
by: prem | last post by:
Hi, I need roles and activities of asp_wp.exe,aspnet_wp.exe and aspnet_isapi.dll. can any one please give description about how they are working and how they coordinate each other and when. ...
6
by: =?Utf-8?B?VGhvbWFzWg==?= | last post by:
Hi, Is it possible to read a file in reverse and only get the last 100 bytes in the file without reading the whole file from the begining? I have to get info from files that are in the last 100...
3
by: Przemo Karlikowski | last post by:
Hello! How can I change the identity of asp_wp.exe (Asp.Net 2.0) process on Windows 2000 Server from ASPNET to LocalSystem? I want to do it to bypass SeTcbPrivelege privelege problem. ...
6
by: tcurdts | last post by:
Greetings, I'm using WindowsXP Pro v5.1and am writing a BAT file to loop through a list of files (contained in a .txt file) and pass them (actually variables derived from them) to another program...
8
by: Nicolas | last post by:
Hi, I was suffering for few days, I has 1 asp.net application running in window xp. the application is used for generate the reports. The problem is, when i try to run a report is open many...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.