Poor performance under IIS

  • Thread starter Thread starter Ilyas
  • Start date Start date
I

Ilyas

Hi all

I have an application which brings back 1000 records from a sql server
database. Under the local asp.net development server provided with
Visual Studio 2008, it takes about 1.8 seconds

When I place this application in IIS it takes 16 seconds for the exact
bit of code. I have narrowed the code down to loopoing around the
dataset and creating an object for every row in the dataset. My
question is why does it take so long under IIS but not under the local
asp.net development server?

Any ideas? How can I get this 16 seconds down to a more acceptable
level eg 2-3 seconds? Is this a configuration issue? I have tried
deploying this to 2 different IIS servers and the same bit of code
takes 16 seconds on both IIS boxes

The application is developed using .net framewor 3.5 and c#, asp.net

Ilyas
 
1) When the code is running on the development server, is the database it's
connecting to also on the development server?

2) When the code is running on the remote server, is the database it's
connecting to on a different remote server? If so, have you got networking
issues. Also, what database is it and how are you connecting to it?

3) Can you be a bit more specific about what you mean by "looping around the
dataset"? What is actually happening here?

4) Can you confirm that, wherever the bottleneck is, it's not in the actual
retrieval of the data from the database...?

They are no networking issues as there is no problems fetching the
data.

Yes the same database is being used throughtout. I have used Sql
Prolfiler and can definatly confirm that its not sql server causing
the delay. Sql server splits out the record in under a second

By looping around the dataset, I mean for each row in the dataset,I am
creating a business object, and setting its properties. The problem is
when the code to do this is deployed in IIS the code it takes about 16
seconds while under asp.net development server (built in visual studio
2008 web server) it takes 2 seconds. I have determined this using
trace.axd with custom messages that I have written at various stages
of this process. Why is there such a big difference in the times?

Surly IIS would give better timings than this as its an enterprise web
server...?
 
re:
!> when the code to do this is deployed in IIS the code it takes about 16
!> seconds while under asp.net development server (built in visual studio
!> 2008 web server) it takes 2 seconds. I have determined this using
!> trace.axd with custom messages that I have written at various stages
!> of this process. Why is there such a big difference in the times?

How isolated is your application in the IIS Server ?

In the ASP.NET Development Server, your app can use up to 100% of the CPU time.

In the IIS Server :

1. Is the app running in its own Application Pool ?
If the app is sharing the Application Pool with other applications,
that could have an impact on performance.

Simply isolating the app in its own App Pool will improve performance.

2. How many processors does the IIS Server have ?
If the application is critical enough, and you have a quad processor,
for example, you could allocate 2 processors to ASP.NET

Look up the processModel and cpuMask configuration parameters in machine.config.

ASP.NET launches one worker process for each qualified CPU.

If the webGarden attribute is configured to true,
doing this limits worker processes to the number of qualified CPUs.

The maximum for worker processes is equal to the number of CPUs.
If webGarden is false, this attribute is ignored and only one worker process will run.

This is the default behavior, which is why it needs to be configured
to be able to take advantage of your unused processing power.

Be careful when configuring the cpuMask, as it needs a hexadecimal value.
The default is "0xffffffff", which enables one processor only.

The cpuMask hexadecimal value 0x0d represents the bit pattern 1101.

On a computer with four CPUs, this indicates that ASP.NET
processes can be scheduled on CPUs 0, 2, and 3, but not on CPU 1.

Make sure you use the correct hexadecimal value desired if you're configuring the cpuMask.

Note that, if you want to use the cpuMask, you must set "Webgarden" to true.

Otherwise, the cpuMask parameters will be ignored, and Windows will schedule
cpu usage to its convenience, which means that other processes might get more
priority, instead of ASP.NET being the most prioritized Windows process.

See :
http://msdn.microsoft.com/en-us/library/5dws599a.aspx

<quote>
When an ASP.NET Web page calls an external resource, such as when performing database access requests,
the page request stops until the external resource responds, freeing the CPU to process other threads.

If another request is waiting to be processed and a thread is
free in the thread pool, the waiting request begins processing.

The result can be a high number of concurrently executing requests and many waiting threads
in the ASP.NET worker process or application pool, which hinders the Web server's throughput,
adversely affecting performance.

To work around that, you can manually set the limit on the number of threads in the process by changing
the MaxWorkerThreads and MaxIOThreads attributes in the processModel section of the machine.config file.
</quote>

Be very careful when you do this...and test each Max parameter you change, in isolation.

You might want to, initially, set the processModel to autoConfig="true".
The built-in parameters usually provide enough performance.

You did not reply to Mark when he asked you whether SQL Server
is located on the same machine as the IIS web server.

If you need more processing power, and your IIS server has 2 processors, and if SQL Server
is located on the same machine as the IIS web server, you might want to set the cpuMask
so that one processor is used by ASP.NET and the other is specialized for SQL Server.

You can set the SQL Server's processor affinity in Task Manager.

Also in Task Manager, you can increase the Priority for the ASP.NET process (w3wp.exe)for your app.
That will effectively dedicate more cpu time to ASP.NET/IIS.

The throughput gains by configuring the above suggestions are mind-boggling.

3. Have you disabled Debug mode for the application ?
IIS responds more slowly when applications are running in Debug mode.
Make sure you disable debugging for the IIS application in the app's web.config

I hope these tips help you configure your IIS web server to achieve more throughput.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
1800 milliseconds is a very long time for a web response
anything longer than 100 milliseconds is bad news

profile your code using NProf or add some timing code - then you have
your answer

juan has highlighted some interesting points but playing with those
settings is just guesswork

find the problem - then fix it

IMO datasets should be avoided as they very inefficient
 
re:
!> profile your code using NProf or add some timing code - then you have your answer

John, Ilyias already knows where the problem is, according to what he posted :

!> I have narrowed the code down to looping around the
!> dataset and creating an object for every row in the dataset.

The problem, as I see it, is that Ilyias stated that the *same*
code works slower in IIS than in the ASP.NET Dev Server.

His question boils down to :
!> why does it take so long under IIS but not under the local asp.net development server?

That's why I suggested a few things he could look into, germane to his problem.

re:
!> juan has highlighted some interesting points but playing with those settings is just guesswork

Profiling under IIS *will* reveal the problem, as you say.
The *solution*, however, is probably found in the tips I suggested.

The tips offered target the possible causes for the same
code to work slower in IIS than in the ASP.NET Dev Server.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
randomly changing settings in IIS till the problem stops = guessing

none of the things you mentioned would cause such a huge slow down

he does not know where the delay is EXACTLY

if he profiled or timed his code he could identify a method call where
a delay is caused
from there he could determine the actual cause of the delay

it is probably some nonsense concerning microsoft networking or
authentication or that pig Kerberos

combining the data from profiling his code with a sql profile he could
match up the timestamps and KNOW
for sure the delay occurs after the dataset is filled etc.

the real challenge in developing is not writing code - but debugging
and profiling it

use NProf - use SQL Profiler - use WireShark - use TDIMon etc. etc.
and you will find a real answer

plus you will learn the skills you need to debug ANYTHING

thrashing around in IIS settings like a wild bull in a china shop
hoping your problem will disappear is not the right approach
 
re:
!> randomly changing settings in IIS till the problem stops = guessing
!> none of the things you mentioned would cause such a huge slow down

For someone who has a grand total of 106 posts to
43 newsgroups, in the last 3 years, you sure are opinionated.

Can't you consider that you might, possibly,
not be as correct as you think you are ?





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
For someone who has a grand total of 106 posts to
43 newsgroups, in the last 3 years, you sure are opinionated.

Yes of course - that is the most important thing

not years of study - not years of practical experience - but number of
posts!
How very convenient for you - in your own value system you are king

You are just hoping for a lucky guess so you can get a "ooh thanks
Juan you are the best" post

And what do you propose the OP should do after trying your ideas and
the problem remains?

I could easily get a list of 100 random changes you could make to
IIS / Windows / SQL Server etc. etc.
that might fix the problem - should he try those too?
In what order should he try them? What combinations?

If you are so great let us see your work - URLs please
 
re:
!> what do you propose the OP should do after trying your ideas and the problem remains?

What will you do if he tries them ...and they work ?
After all, the techniques I outlined have been *proven* to increase throughput.

re:
!> random changes

What leads you to believe that the fixes proposed are "random changes" ?
Every suggestion I made will improve performance.

re:
!> If you are so great let us see your work - URLs please

Here's a few :

http://www.amazon.com/Beginning-ASP...=sr_1_5?ie=UTF8&s=books&qid=1214281145&sr=1-5

http://www.amazon.com/Beginning-ASP...=sr_1_3?ie=UTF8&s=books&qid=1214281145&sr=1-3

http://www.amazon.com/Beginning-ASP...=sr_1_2?ie=UTF8&s=books&qid=1214281145&sr=1-2

http://www.amazon.com/Beginning-Act...=sr_1_4?ie=UTF8&s=books&qid=1214281145&sr=1-4

http://www.amazon.com/Beginning-Act...=sr_1_1?ie=UTF8&s=books&qid=1214281145&sr=1-1

Now, show me yours.

Uh-oh, I already know : you don't have any, and are trying out for a career in being
antagonistic online about people and programming issues that you hardly know about.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
"After all, the techniques I outlined have been *proven* to increase
throughput."
he does not have a "throughput" problem - he has a serious blocking
issue with one request
your tips are for increasing throughput of a busy web server

BTW those urls you provided are for books - not websites
All of which include the word "Beginning" in the title and I would not
buy or recommend

I do not need to provide URLs because I am not camping on this
newsgroup like I own it
handing out copy and paste responses which are mostly rubbish. You are
not helping anybody.

What actual commercial experience do you have?

I am only antagonistic towards you because you give bad information
and I doubt your skill, knowledge and experience.

Three years was the last time I visited this newsgroup and you were a
fool then - to quote you:
"If you intend to use IHttpHandlers for a web app, exactly how are you
going to do that without an ASPX page?"
you may as well have written "I do not know anything about ASP.NET"

In three years not much has improved - if you have time to write all
these posts and co-author books why have you not created some
demonstration websites - showing how it should be done?
 
re:
!> You are not helping anybody

I have HUNDREDS of thank-you notes from grateful
programmers whom I have given very specific help.

You love to flame, huh ?

Talk to yourself from now on.

<plonk>



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
- Juan says randomly change settings in IIS - you might get lucky
- John says use profiling and timers and debugging tools to determine
the EXACT cause of the issue and then resolve it
- Juan says because he has posted so many messages on the internet he
is qualified to say that John's approach should NOT be used

Here is another thank-you note from me "Thankyou for providing a few
moments amusement and making me feel superior"

When you get round to building something using ASP.NET please let me
know
 
I am not "flaming"

I am criticising you - with good reason

You have the opportunity to respond to the criticism and either:

- illustrate why I am wrong - and I will learn something
- or agree that I have a point - and you will learn something

But you have not done either - you have just run away

And this topic will be here for the next 10 years as proof of your
folly
 
Back
Top