Practical Solution for optimizing the performance of websites on the Asp.net platform.

Source: Internet
Author: User
Source: http://www.cnblogs.com/chenkai/archive/2009/11/07/1597795.html

Preface
Recently, performance tuning has been performed on the platform operated by friends, and the effect is not bad. So let's write it out and talk about it. If you are aware of the error in this article, or do not understand it, please add the QQ group: 4656272. Please refer to and discuss it together. (PS: You have a poor understanding of your document. Please wait for more attention)

Background
Friend's platform website is vertical informationCommunityWebsite, originally used ASP.. NET 1.0 developed and later upgraded to ASP. NET 2.0, SQL Server 2000, Windows 2003 Server, two servers, one Web server, and one database server. Currently, there are about more than 0.3 million user accounts andArticleAnd more than 200 posts. As the data volume grows, the load increases, and access failures or slow access often occur.

Solution
Because it is already in the production environment, the premise of performance optimization is that it does not affect the existing business operations, and can be seamlessly deployed. If there is a problem, you can quickly roll back and recover. Therefore, I want to perform optimization several times, so that the performance can be improved securely without affecting normal business operations.

Step 1: optimize the running environment
This step is very important. In a healthy and stable environment, the maximum performance of the platform can be realized. Therefore, the platform should be provided with a healthy and stable environment.
1 ASP. NET environment Optimization
According to 10 ASP. NET performance and scalability secrets.

2. IIS environment Optimization
This reduces unnecessary ISAPI loading in IIS, simplifies the IIS access log format, and sets the expiration of IIS content for image files, JavaScript, CSS, and other files, the gzip compression function of IIS is enabled.

3 SQL Server Optimization
Upgrade SQL Server 2000 to SQL Server 2005, according to the "optimize SQL Server 2000 Settings" http://www.tech-q.cn/thread-1412-1-1.html described in the combined with the actual situation of settings, and modify the memory usage. My suggestion: if it is a separate database server, use SQL Server as much memory as possible.
After the first step of optimization, the performance has been improved, as shown in the reduction of access failures or access errors. So start step 2.

Step 2 collect data to find the performance weakness of the platform
According to the IIS access log, I made a 24-hour sampling. Find the top 10 most visited pages and 10 pages with long response time. According to the msdn application profiler optimization SQL Server database system http://www.microsoft.com/china/msdn/library/data/sqlserver/Profiler.mspx? In MFR = true, find the 10 most frequently executed SQL statements and the SQL statements that have been executed for a long time. Provide to developers and provide suggestions for optimization.
(1) frontend Optimization
The most visited pages are the final page of the article and the final page of the post. At this time, I would like to sacrifice the best client debugging tool firebug that is currently known, according to the "first knowledge of firebug full text-firebug use" http://www.tech-q.cn/thread-686-1-2.html and "34 website acceleration methods" http://www.tech-q.cn/thread-680-1-2.htmldescribed in optimization. These include:
A) refactor the final page with Div + CSS, reasonably set the validity period, and speed up client download and Dom engine rendering and rendering in the browser.
B) the platform uses the jquery library to directly reference JS files on Google, reducing the number of bytes transmitted and connections, and improving the access speed.
C) JavaScript and CSS compression, and image animation files put under a separate domain name, such as http://images.xxx.com, because the old browser for a domain name limit 2 concurrent connections, you can solve this problem by setting the validity period under this domain name.
D) disable unnecessary viewstate in ASP. NET to reduce transmission bytes.

(2) Platform System Optimization
It is found that most of the 10 SQL statements and SQL statements that have been executed for a long time are caused by similar updates to the number of access updates on the final page of the article and the final page of the post, first, I want to add a server for SQL Server image distribution, insert, update, and delete all operations on the same platform, and the other machine can only perform query operations.

However, the added servers can only be used as database servers, and the changes on the system are relatively large, which is not the best solution. After consideration, since the updated data operations do not need to be performed in real time, add a server to use centos 5.x, install memcached, and perform incremental updates. In addition, the remaining resources of the server can be used for other tasks, the implementation idea is to update it to memcached first. If the number of updates reaches a threshold value, update it to the database at a time. The online status of the platform's members has been changed from the database to memcached.

In order to improve the performance of the DaO layer, I suggest they develop and use the mature database application framework nhib.pdf and use the database connection pool to improve the reusability of database connections.

The SQL statement that has been executed for a long time is caused by fuzzy query. At this time, the added server is used again, And Lucene is installed on it to query the required information of the database, submit to Lucene, search all put in Lucene to do, the specific here will not be traced, interested in the http://www.tech-q.cn/forum-19-1.html here to find the relevant information.

After the second step of transformation, the performance is upgraded to a new stage. Access failure, access error or slow access has rarely occurred.
However, there is no end to optimization, and the current situation is only suitable for the current access situation. When the access volume is increased to several times, there will be problems, so I am ready to continue optimization.

Step 3 Architecture Optimization
Here, I used the new server again, installed the Squid cache server, improved the load capacity again after optimization, and installed nginx in front of squid, make full use of the epoll feature of nginx and move the previously set http://images.xxx.com/to the nginxdirectory. Nginx, squid, and memcached will not go into details about the installation and configuration process. There are many topics on http://www.tech-q.cn/forum-10-1.html. You can also add the QQ Group :4656272 to discuss them.

Others
In the process of log analysis, it is found that many access requests are generated by search engine spider, and the final page of the article on this platform is not static, therefore, many unnecessary database connections are caused. I used the following methods:
1. Configure robots.txt. For unknown or undesirable spider, rewrite the agent to a static page in nginx.
2. generate static pages based on requests to generate HTML.

So far, the performance of this platform has been significantly improved, and access failures and slow access never occur again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.