C# 生产服务器上的 ASP.NET 网站性能下降
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1340218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET Website Slow Performance on production server
提问by cralexns
My problem is that my ASP.NET website is running slower on my production server comparatively on my development server.
我的问题是我的 ASP.NET 网站在我的生产服务器上运行速度比在我的开发服务器上慢。
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.
在我的开发环境中执行 120 毫秒的页面需要 400 毫秒才能在服务器上执行。我已经使用探查器监视了 SQL 服务器,并且在服务器上运行 400 毫秒的页面上运行的查询只需要大约 50 毫秒即可完成 - 所以我确信我的问题不在于 SQL 服务器。
My development machine is an Intel I7 with 6GB RAM, the production server is a 2x AMD Quad Core with 16GB ram.
我的开发机器是带有 6GB RAM 的 Intel I7,生产服务器是带有 16GB RAM 的 2x AMD Quad Core。
回答by Magnus Johansson
Have you checked that the debug=false in your web.config?
您是否检查过 web.config 中的 debug=false ?
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?
服务器是64位的吗?尝试为您的应用程序创建一个专用的应用程序池,并将应用程序池设置为在 32 位经典模式下运行。这有什么区别吗?
Is you class pre-compiled or have you set it up to compile at runtime?
您是预编译课程还是将其设置为在运行时编译?
回答by lingvomir
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.
在您的页面中设置 Trace="true" (<%@ Page Trace="true"...),当它在浏览器中加载时,您将在页面底部获得很多有用的信息。您将确切知道在服务器上处理请求需要多长时间。如果时间足够短,则问题可能出在 IIS 设置中。将它们与您的开发环境中的进行比较。
回答by Mike McClelland
Is your SQL server on another server on production, but local on development?
您的 SQL 服务器是否在另一台生产服务器上,但在本地开发?
回答by Stephen Newman
Massive viewstate causing transmission delay?
大量视图状态导致传输延迟?
回答by Cyril Gupta
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.
这是您服务器上唯一的网站吗?16 GB 是相当不错的内存,但如果同一台服务器上有许多流行的网站,它们可能会占用资源和 CPU 时间。
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?
你检查索引了吗?他们都在服务器上?
回答by Muhammad Akhtar
There are some point you can consider for performance improvment of your website.
您可以考虑提高网站性能的某些方面。
- Set debug=false
- Turn off Tracing unless until required
- 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
- Disable ViewState as and when not required.
- Avoid Frequent round trips to the Database
- 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
- Use Caching to improve the performance of your application.
- Use Finally Method to kill resources
- 设置调试=假
- 除非需要,否则关闭跟踪
- 如果不需要,请关闭会话状态。ASP.NET 自动管理会话状态。但是,如果您不需要会话,禁用它将有助于提高性能
- 在不需要时禁用 ViewState。
- 避免频繁往返数据库
- 避免抛出异常。异常是处理应用程序逻辑中发生的错误的好方法。但是,抛出异常是一种代价高昂的资源,必须避免。使用特定异常并尽可能少使用以避免资源开销
- 使用缓存来提高应用程序的性能。
- 使用 finally 方法杀死资源
Edit:measure your website performance using this website
http://www.websiteoptimization.com/services/analyze/
http://www.websitepulse.com/
编辑:使用本网站衡量您的网站性能
http://www.websiteoptimization.com/services/analyze/
http://www.websitepulse.com/
回答by Greg
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...
确保 web.config 在两个环境中相同。
确保两个环境都指向第三台机器上的同一个数据库服务器。
确保两个环境中的 IIS 版本相同。
确保 IIS 在两种环境中的配置相同。
在两种环境中运行相同的测试数据。
等等...
回答by Martin
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.
通过阅读所有建议,似乎没有任何效果,开始一点一点地从您的网站中取出代码,看看这如何影响时间。一次删除大约 10 行代码或 HTML,看看是否有巨大的差异。
Otherwise, it probably has to do with IIS, and sorry, I ain't no IIS guru.
否则,它可能与 IIS 有关,抱歉,我不是 IIS 专家。
回答by cralexns
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.
我从基于 AMD 的解决方案更改为基于英特尔的解决方案(至强!),获得了 0.3GHz 和更快的磁盘。
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.
我还获得了性能提升,而不是像我的开发机器一样慢 x3,它现在下降到像 x0.75 一样慢——显然仍然不是我的开发机器能够达到的闪电速度,但它越来越近了。
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.
在进一步调试时,我注意到大部分性能消耗(这并不奇怪)来自必须编译查询的 LINQ to SQL,对我来说似乎很奇怪的是,一旦我尝试预编译 LINQ 查询并在我的两台机器,开发机器都变得更快了。