Top 10 methods to improve Asp. Net application performance (translation) and top 10 asp.net

Source: Internet
Author: User

Top 10 methods to improve Asp. Net application performance (translation) and top 10 asp.net

This article has translated the Top Ten Methods for Improving Asp. Net applications. I think about each of them carefully and will talk about it with my project here.
Article 1: Return multiple result sets
Because all the SQL statements used to access the database in my project are implemented by calling the stored procedure, basically multiple result sets are returned after a stored procedure is completed, to get the desired data. yes !!
Article 2: Paging data
I wrote a general paging storage process for paging the displayed data. I wrote a project summary and published it on CSDN Based on the paging idea of Dino Esposito. after several projects, it is found that the efficiency of paging depends on the conditions used for paging. In general, the efficiency of using index fields for conditional paging is the highest, so in future projects, note the paging efficiency. I checked the paging STORAGE PROCESS IN csdn. The paging storage process of "Fengyun" is more common and efficient. I decided to use it later.
URL: http://community.csdn.net/Expert/topic/3587/3587201.xml? Temp =. 6331598.
Create procedure sp_page
@ Tb

Varchar (50), -- table name
@ Col

Varchar (50), -- pagination by this column
@ Coltype
Int,

-- @ Col column type, 0-digit type, 1-character type, 2-Date and Time Type
@ Orderby
Bit,

-- Sort, 0-order, 1-inverted
@ Collist
Varchar (800), -- List of fields to be queried, * indicates all fields
@ Pagesize int,

-- Number of records per page
@ Page
Int,

-- Specified page
@ Condition varchar (800), -- Query condition
@ Pages
Int OUTPUT -- total number of pages
AS
/*
Function Description: queries records that meet the specified conditions in a specified table by Page Based on the specified column. The page can be sorted in reverse order.
Query can specify the page size, specify any page to query, specify the list of output fields, and return the total number of pages
Work
By: pbsql
Version
Current: 1.10
Last modified: 2004-11-29
*/
DECLARE @ SQL nvarchar (4000), @ where1 varchar (800), @ where2 varchar (800)
IF @ condition is null or rtrim (@ condition) =''
BEGIN -- no query Conditions
SET @ where1 = 'where'
SET @ where2 =''
END
ELSE
BEGIN -- with query Conditions
SET @ where1 = 'where ('+ @ condition +') AND '-- this condition is added if conditions exist.
SET @ where2 = 'where ('+ @ condition +') '-- this condition is added if no conditions exist.
END
SET @ SQL = 'select @ pages = CEILING (COUNT (*) + 0.0)/'+ CAST (@ pagesize AS varchar) +
') FROM' + @ tb + @ where2
EXEC sp_executesql @ SQL, n' @ pages int output', @ pages OUTPUT -- calculate the total number of pages
IF @ orderby = 0
SET @ SQL = 'select TOP '+ CAST (@ pagesize AS varchar) + ''+ @ collist +
'From (SELECT "> '+ @ tb + @ where1 + @ col +'> (select max ('+ @ col +') '+
'From (select top '+ CAST (@ pagesize * (@ page-1) AS varchar) + ''+
@ Col + 'from' + @ tb + @ where2 + 'ORDER BY' + @ col + ') t) ORDER by' + @ col
ELSE
SET @ SQL = 'select TOP '+ CAST (@ pagesize AS varchar) + ''+ @ collist +
'From' + @ tb + @ where1 + @ col + '<(select min (' + @ col + ')' +
'From (select top '+ CAST (@ pagesize * (@ page-1) AS varchar) + ''+
@ Col + 'from' + @ tb + @ where2 + 'ORDER BY' + @ col + 'desc) t) ORDER by' +
@ Col + 'desc'
IF @ page = 1 -- first page
SET @ SQL = 'select TOP '+ CAST (@ pagesize AS varchar) + ''+ @ collist + 'from' + @ tb +
@ Where2 + 'ORDER BY' + @ col + CASE @ orderby WHEN 0 then' 'else' DESC 'end
EXEC (@ SQL)
GO

Article 3: Connection Pool
By default ,. NET uses the connection pool to manage connections. therefore, pay attention to two points in the project: one is to construct a class specifically used to return the connection string or connection object, so as to ensure that the connection string is the same, in order to effectively use the connection pool. the other is to close the EDGE connection immediately after the connection is used up.
Article 4, Article 5, and article 7: Make full use of various cache technologies in Asp. Net (the fourth, fifth, and seventh methods in this article use cache)
In the original project, the page output cache was used once, but it was not successful. Because the page is to be submitted, it cannot respond to the event in time. and then drop it down. I thought it was a cache problem. after reading this article, I can see that I don't know how to use it. so during this time, I was checking how to use the cached data. the cache usage should be well understood. in this way, the application efficiency can be improved more effectively. if you want to know the caching technology, I have found the following articles on the Msdn Chinese website:
ASP. NET cache: methods and best practices:
Http://www.microsoft.com/china/MSDN/library/WebServices/ASP.NET/ASP.NETCaching-TechniquesandBestPractiCEs.mspx
Supports database cache relevance in ASP. NET:
Http://www.microsoft.com/china/msdn/library/webservices/asp.net/DbCacheDepASPNET.mspx
Use cache to save money:
Http://www.microsoft.com/china/msdn/library/webservices/asp.net/aspnetasp11022004.mspx
Create cache configuration objects for ASP. NET:
Http://www.microsoft.com/china/MSDN/library/WebServices/ASP.NET/CreatingaCacheConfigurationObjectforASPNET.mspx
There is also a Microsoft blue book:
Improving. NET Application Performance and Scalability
It should be said that this book is the most complete and the best guide. Chapter 6 focuses on the cache and cache application guide. I am reading this chapter.
Article 6: processing in the background
This is a new solution I have come into contact with. It turns out that asp.net can also be used as a background scheduled trigger function. It will certainly be available in the future.
Use cache to save money:
Http://www.microsoft.com/china/msdn/library/webservices/asp.net/aspnetasp11022004.mspx
This article uses this technology for reference.
Article 8: use the new functions of IIS6
I have never paid attention to IIS6, but IIS5 is used. It seems that the server should be upgraded.
Article 10: conditional use of ViewState
ViewState has never been paid attention to. It seems that ViewState will be switched off as long as it is not required to be used in the future, especially when the DataGrid page is used.

In general, the use of Cache can better improve the performance of applications. If you use a database, remember to make full use of the Connection Pool, efficient paging; if windows 2003 is used, do not forget to open its Kernel Caching. finally, do not forget to turn off the EnableViewState attribute of the page or control without ViewState.


How to Improve ASPNET performance?

Do you use cache? Use the following exercise to evaluate your code using the ASP. NET cache function: ◆ do you have too many changes in the output cache? Check your webpage and use the output cache to ensure that there is a limit on the number of changes. Too many changes to the output cache page can increase the memory usage. The webpage that you can recognize outputs the cache using the search string "OutputCache. ◆ Can you use the output cache? When reviewing your webpage, start asking yourself: If you can cache the entire page. If the entire page cannot be cached, can it be cached? Even if the data is not static, you can consider using the output cache. If your content does not need to be transmitted in near real time, consider outputting the cache. Using the output cache, whether the entire page or part of the page can significantly improve the performance. ◆ Yes. Will static data be better stored in the cache? Identify whether the data at the application end is static or rarely updated. This type of data is stored in the cache as a great candidate. ◆ Do you check before the items in the cache are null? Check the items with null access to the cache, as shown in the following code snippet, you can improve performance. Object item = Cache ["myitem"]; if (item = null) {// repopulate the cache} This helps avoid any null exceptions. To find your code in your access cache. Are you using session status? Use the following exercise to review the usage session Status of the Code: ◆ disable the session status if you do not need it? By default, the session status remains. If your application does not use the session Status, disable it on the Web. the config file is as follows: if some parts of your application require session status and are sure not to use it, these pages disable it by using the following page-Level Attribute pages. ◆ Minimizes the session status used and increases the performance of applications. ◆ Do you have a page that does not write a session? Page requests that use session Status use ReaderWriterLock internally to manage access to session status. For a webpage with read-only session data, set EnableSessionState to ReadOnly. <% @ Page EnableSessionState = "ReadOnly"... %> This is particularly useful when you use the HTML framework. The serialization is performed on the page by default (due to ReaderWriterLock. Set it to read-only to prevent blocking and allow more parallel operations. ◆ Do you check that the project in the previous session status is null? Is empty, and then access the project check, as shown in the following code, you can improve performance.

What are the common optimization methods in ASPNET? Solution

Compared with the previous Web development model, ASP. NET provides several important advantages: enhanced performance. ASP. NET is the compiled public Language Runtime library code on the server. Unlike the predecessors, ASP. NET can use early binding, real-time compilation, local optimization, and out-of-box cache services. This is equivalent to significantly improving the performance before writing code lines. World-class tool support. The ASP. NET Framework complements a large number of toolboxes and designers in the integrated development environment of Visual Studio. WYSIWYG editing, drag-and-drop server controls, and automatic deployment are only a few of the functions provided by this powerful tool. Power and flexibility. Because ASP. NET is based on a Common Language Runtime Library, Web application developers can use the power and flexibility of the entire platform .. . NET Framework class library, message processing, and data access solutions can be seamlessly accessed from the Web. ASP. NET is also independent of language, so you can select the language that best suits your application, or split your application across multiple languages. In addition, the interaction of Public Language Runtime libraries ensures that existing investment in COM-based development is retained when the database is migrated to ASP. NET. Simplicity. ASP. NET makes it easy to execute common tasks, from simple form submission and client authentication to deployment and site configuration. For example, the ASP. NET page framework allows you to generate a user interface that separates application logic from the representation code, and process events in a simple form processing model similar to Visual Basic. In addition, the Common Language Runtime simplifies development by using managed code services (such as automatic reference counting and garbage collection. Manageability. ASP. NET uses a text-based hierarchical Configuration System, which simplifies the application of settings to server environments and Web applications. Because configuration information is stored in plain text, you can apply new settings without the help of local management tools. This "Zero local management" philosophy also extends to the deployment of ASP. NET Framework applications. You only need to copy the necessary files to the server to deploy the ASP. NET Framework application to the server. You do not need to restart the server, even when you deploy or replace the Running code. Scalability and availability. ASP. NET has been designed with Scalability considerations and added a feature specifically designed to improve performance in a clustered and multi-processor environment. In addition, the process is affected by ASP. NET Runtime Library is closely monitored and managed, so that when the process behavior is abnormal (leakage, deadlock), you can create a new process to help keep the application always available for processing requests. Customization and scalability.

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.