2

My problem is that my ASP.NET website is running slower on my production server comparatively on my development server.

A page that executes in 120ms in my development environment takes 400ms to execute on the server. I've monitored the SQL server with the profiler and the query being run on the page taking 400ms on the server only takes around 50ms to finish - so I've convinced myself that my problem does not lie with the SQL server.

My development machine is an Intel I7 with 6GB RAM, the production server is a 2x AMD Quad Core with 16GB ram.

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
cralexns
  • 53
  • 1
  • 2
  • 9
  • How are you measuring the speed? – AnthonyWJones Aug 27 '09 at 10:42
  • Stopwatch in a HttpModule, basically the time measured is how long it takes going from the BeginRequest to the EndRequest event. – cralexns Aug 27 '09 at 11:37
  • I tried running a few tests on a blank page in my project on the server. 1. I setup a simple loop with a very simple calculation inside, this would actually execute faster on the server than on my development machine. 2. I changed the loop to call a function from my classlib that pulls information from the database.. this was slower on the server. 3. I changed it again but this time calling a function that has no interaction with the server, again it was slower on the server. Perhaps it has something to do with my class lib? Any good ideas on how to troubleshoot it? – cralexns Aug 27 '09 at 11:55
  • on the third test, by no interaction with the server, I meant no interaction with the database. – cralexns Aug 27 '09 at 11:56
  • Just for clarification, the whole website is slower not just the one page used in the example. – cralexns Aug 27 '09 at 12:47
  • Same OS/IIS version on dev and prod? – chris Aug 27 '09 at 14:49
  • Almost, both are running IIS7 on Windows 2008 - different editions though, server is web because that's all it needs to run. I just tested my web application on a friend's system with about the same specs as my dev PC, it runs as smoothly as my dev PC and this is a vista machine. I'm starting to worry that the server actually just can't process it fast enough? Does anyone have some good way to measure this and compare with my dev system? – cralexns Aug 27 '09 at 23:03
  • measure your website performance using this website http://www.websiteoptimization.com/services/analyze/ – Muhammad Akhtar Aug 28 '09 at 04:04
  • No sorry, that's going to tell me what I already know - the server is 3 times slower, what I would like to ascertain is if the server is slower due to hardware or something else because it doesn't make sense to me. Even if there's some difference to the specs between my dev and the production server should it be 3x slower? Seems absurd. – cralexns Aug 28 '09 at 11:29
  • .. posting a follow up as an answer to make it easier to read! :) – cralexns Sep 03 '09 at 14:44
  • It's worth noting that I ran into a similar issue with another project and another server recently. Randomly thought about core parking and used the http://coderbag.com/Programming-C/CPU-core-parking-manager utility to turn min speed to 100%, it removed the performance difference I was seeing between dev and production. – cralexns May 07 '15 at 07:19
  • @cralexns: did you fix this issue yet? I'm having a similar problem, and my guess is that it's the security configuration from the production server. It must be some external thing to slow down the app so much – Hoàng Long Jan 20 '16 at 03:34
  • @HoàngLong I don't know what your setup is like, I was using a dedicated server with root access so the configuration between prod and dev was virtually identical. I alleviated my issue by switching to a faster server, one more closely matching the speed of my development machine. Whether it was poor optimization or not, the CPU speed had a significant impact on page cycle speed. – cralexns Jan 25 '16 at 11:50

10 Answers10

17

There are some point you can consider for performance improvment of your website.

  1. Set debug=false
  2. Turn off Tracing unless until required
  3. Turn off Session State, if not required. ASP.NET Manages session state automatically. However, in case you dont require Sessions, disabling it will help in improving the performance
  4. Disable ViewState as and when not required.
  5. Avoid Frequent round trips to the Database
  6. Avoid Throwing Exceptions. Exceptions are a greate way to handle errors that occur in your application logic. However, throwing exceptions is a costly resource and must be avoided. Use specific exceptions and use as minimal as possible to avoid resource overhead
  7. Use Caching to improve the performance of your application.
  8. Use Finally Method to kill resources

Edit: measure your website performance using this website http://www.websiteoptimization.com/services/analyze/
http://www.websitepulse.com/

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
  • 5
    Those are all great tips for sure but before optimizing anything I would like my server to actually perform somewhat close to what my dev machine does, and not be up to 3 times slower - which is ridiculous! – cralexns Aug 28 '09 at 00:22
6

Have you checked that the debug=false in your web.config?

Is the server 64bit? Try to create a dedicated application pool for your application and set the application pool to run in 32bit classic mode. Makes that any difference?

Is you class pre-compiled or have you set it up to compile at runtime?

Magnus Johansson
  • 28,010
  • 19
  • 106
  • 164
  • Oridinarily that would be true on the development wouldn't it? – AnthonyWJones Aug 27 '09 at 10:45
  • I've tried changing this value, it doesn't make much of a difference. – cralexns Aug 27 '09 at 11:38
  • Added 2 more options in my answer. – Magnus Johansson Aug 27 '09 at 15:01
  • I've tried both pre-compiled and just copying the project files over, that only really makes a difference the first time a page runs. Both dev and production is 64bit, not sure exactly what you mean by 32bit classic mode but setting the pipeline to classic throws an exception with a configuration error, telling me it can't find one of my assemblies. I changed Enable 32-Bit Applications to TRUE, it was FALSE before, this seems to have incurred a performance boost, what was ~400ms before is now ~300ms, still not the 120ms of my dev server though. – cralexns Aug 27 '09 at 16:20
  • Also changed this on my development machine and it's even faster now but that also means the gab in performance is unchanged. :( Thanks for the tip though! :) – cralexns Aug 27 '09 at 16:51
  • I had this same issue -- setting the app pool to 32bit fixed the problem for me. Page load time went from 1.6s to 400ms ! Thank you. – Matthew M. Apr 26 '10 at 03:57
3

Set Trace="true" (<%@ Page Trace="true"...) in your page and you will get a lot of useful information at the bottom of the page when it loads in the browser. You will know exactly how much time is needed to process the request on the server. If the time is low enough, then the problem could be in the IIS settings. Compare them to the ones on your dev environment.

lingvomir
  • 2,554
  • 17
  • 14
2

Is your SQL server on another server on production, but local on development?

Mike McClelland
  • 193
  • 1
  • 5
1

From reading all the suggestions, and it seemingly like nothing is working, start taking code out of your site, little by little, and see how that affects time. Remove about 10 lines of code or HTML at a time, and see if there is a huge difference.

Otherwise, it probably has to do with IIS, and sorry, I ain't no IIS guru.

Martin
  • 11,031
  • 8
  • 50
  • 77
  • I've tried removing certain performance intensive functions from the website and while it obviously improves the performance not to have those it seems like the server is just generally slower at executing code, regardless.. Though, I did conduct a simple for loop test (commented this on my original post) where the server would handle the simple loop faster than my development machine, 10 million iteractions was faster on the production machine - but as soon as I was called some function residing in my class library the production server would be slower.. – cralexns Aug 28 '09 at 13:48
0

Massive viewstate causing transmission delay?

Stephen Newman
  • 1,977
  • 14
  • 18
  • I've tried disabling ViewState in the web.config, there may be a slight improvement but we're still taking 3x slower execution time on the server compared to the development machine... – cralexns Aug 27 '09 at 12:32
0

Is this the only website you have on the server? 16 GBs is pretty good memory, but if there are many popular websites on that same server they could be eating up the resources and CPU time.

Other than that I can't think of any reason why your website would be slow on production than in development.

Did you check out the indexes? They're all there on the server?

Cyril Gupta
  • 13,505
  • 11
  • 64
  • 87
0

You need to reduce the variables.

Try eliminating all of the differences between the two environments, then make changes one by one until you figure out what it is.

Make sure that the web.config is the same in both environments.
Make sure both environments point to the same database server on a 3rd box.
Make sure the same version of IIS is in both environments.
Make sure IIS is configured the same in both environments.
Run the same test data on both environments.
etc...

Greg
  • 16,540
  • 9
  • 51
  • 97
  • I'm trying but I'm at a loss on what more I can do at this point, I can check off everything on your list apart from running the database on a third server since that isn't an option for me. – cralexns Aug 27 '09 at 19:53
0

After banging my head against the wall for a long time concerning the performance difference of my development machine and the production machine, I finally caved in to the feeling I've been having deep down that the processor actually matter a lot more than you'd think.

I changed from an AMD based solution to an Intel based solution (Xeon!), gaining .3GHz and faster disks.

I also gained a performance boost, instead of being x3 as slow as my development machine it's now down to something like x0.75 slower - obviously still not the lightning speeds that my development machine is capable of but it's getting closer.

While debugging this further I noticed that most of the performance hog (which is no surprise really) is coming from LINQ to SQL having to compile queries, what seems odd to me is that once I tried precompiling a LINQ query and running the same thing on both my machines, the development machine turned out to be faster.

cralexns
  • 53
  • 1
  • 2
  • 9
  • 2
    I would think that the performance gain from switching from 'debug' to 'producion' would outweigh any negative processor difference. – UpTheCreek Oct 27 '09 at 14:35
  • Curious to know what your cpu utilization on your production server was before and after the processor switch? – Adam Feb 03 '15 at 02:06
0

If you have already looked into all the possible code optimzation and still facing performance issues this could be the reason:

Check your Web.config and remove the following.

 <system.codedom>
<compilers>
  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers></system.codedom>

These can be safely removed from the web.config if you do pre-compilation and only use the compiled assemblies on the webserver.

Yasir Ayaz
  • 91
  • 1
  • 5