Abstract This article explores how to improve the performance of the ASP.NET application from page, data access, string operations, and provide several test tools to detect ASP.NET website performance. Keywords ASP.NET application Performance Optimization website performance is very important for ASP.NET program developers. A excellent website has a beautiful page design, a perfect service function, but there is a long latency when opening a web page, and the user will eventually unable to endure. Especially for large-scale e-commerce websites, tens of thousands of users accessed at the same time per second, and there is no good website performance, which cannot meet huge demand. Asp.net As a new generation of dynamic web generation systems, it has an essential increase in the original ASP in terms of platform performance. However, on this basis, it is necessary to develop professional standards, in line with production standards, and users welcome web applications, developers also need to optimize processing from all aspects of programming in all aspects of page, data access, and string processing. Improve the overall performance of the website. This article will mainly explore several ways to perform performance optimization in ASP.NET and pay attention to problems. Page Performance Optimization 1, the appropriate selection of session status is a stateless communication protocol, unable to record and identify requests from different clients, but in actual application, the system must maintain a session between different requests from the client. information. ASP.NET solves this problem by storing session status information in a process, status server, or SQL Server database. Save session status information has the best performance in the memory of the web server, which is very fast, but the ability to short session status information across multiple servers. To maintain session information between multiple web servers, you can use the status server to store, this method can improve the system's scalability and reliability due to deployment applications to multiple servers, but to reduce performance cost. For extremely important session information, you need to use SQL Server storage, avoid losing important session information, but the resulting workload is much larger than the top. If you do not consider the retention of status information and multiple server shares, you should try to choose the best performance in the process of saving to the server. Session status information storage mode Select the web.config file:
Void Page_Load (Object O, Eventargs E) {if (! page.ispostback) {= new sqlconnection ("Server = localhost; uid = sa; pwd =; database = data"); string sql = "select * from student" Cmd.fill (DS, "STU"); myDataGrid.database ();}} The above code will ensure that the database is read and bind only when accessing this page for the first time. 2.4 rationally use the DataGrid control DataGrid control with the most powerful data display, but also has a lot of functions such as modification, deletion, addition, and pagination of data. If you simply display data, DataGrid is not the best choice. The paging function of the DataGrid control (stored in viewstate), etc. The DataList control is much less than the DataGrid function. But the customity has a lot. The unique multi-line data is still convenient. DataGrid can be implemented, it is basically possible. The Repeater control has the least function, but the customization is very strong. Due to a lot of functions, the performance of the server is minimized. Therefore, when simply displaying a list of data, select the REPEATER or DATALIST control can also achieve the purpose, and reduce performance overhead. Database Access Performance Optimization 1, the database connection and closing access database resources need to create a connection, open the connection, and turn off a few operations. These processes need to exchange information multiple times with databases to compare server resources through authentication. ASP.NET provides a connection pool to improve the impact of the database to the performance. The system places the user's database connection in the connection pool, take it out, and the connection is retracted, waiting for the next connection request. The size of the connection pool is limited. If the connection is required to create a connection after the connecting pool is maximized, it will inevitably affect performance. Therefore, after the establishment of the database connection, only the connection is turned on when you truly need to operate. It is immediately turned off again, thereby minimizing the time of the database connection to open, avoiding the situation that exceeds the connection limit. 2. Use the stored procedure stored procedure to be a set of pre-compiled SQL statements stored on the server, similar to batch files in the DOS system. The stored procedure has functions that are immediately accessed immediately, and the information processing is extremely rapid. Using the stored procedure can avoid multiple compilation of the command, after executing the execution plan resides in the cache, just call the binary code in the cache when needed. In addition, the stored procedure runs on the server side, independent of the ASP.NET program, which is easy to modify, the most important thing is that it can reduce the transmission of the database operation statement in the network. 3. Optimize the resource consumption of the ADO connection in Query statement ASP.NET is quite large, the longer the SQL statement runs, the longer the time of occupying system resources. Therefore, try to use an optimized SQL statement to reduce execution time. For example, not in the query statement contains a child query statement, take advantage of indexing, etc. String Operation Performance Optimization 1. When the TOSTRING method for use value is connected to the string, you often use the " " to add the numbers to the string. Although this method is simple, the correct result can be obtained, but due to the different data types, the number needs to be converted into the reference type by packing operation to be added to the string.
However, the packing operation has a large effect on performance, because when such processing is performed, a new object will be allocated in the hosted heap, and the original value is copied into the newly created object. Use the TOSTRING method of the value type to avoid packing operations, thereby improving application performance. 2, using the StringBuilder class String class object is unable, re-assay for String objects in nature, is in nature, imparts the object to the object, and its method to improve performance is not significant. When processing a string, it is best to use the StringBuilder class, and its .NET namespace is System.Text. This class does not create a new object, but through the Append, Remove, Insert, etc., the string is directly operated, and the results result is returned by the TSTRING method. Its definitions and operation statements are as follows: int Num; system.text.StringBuilder str = new system.text.stringbuilder (); // Create string str.Append (Num.tostring ()); // Add Numerical NumResponse. Write (str.tostring); // Display Operations ASP.NET application performance test Before you perform performance testing of the ASP.NET application, make sure the application has no error and the function is correct. The specific performance test can be performed using the following tools: Web Application Strees Tool (WAS) is a free test tool released by Microsoft, which can be downloaded from http://webtool.rte.microsoft.com/. It can simulate a hundred thousand users to access the web application, form a traffic load on the server, to achieve the purpose of the test, can generate average TTFB, average TTLB and other performance summary reports. Application Center Test (ACT) is a test tool that is included in the Enterprise Edition of Visual Studio.NET, which is a Web application test tool that Microsoft officially supported. It can intuitively generate chart results, the function is more than WAS, but does not have multiple clients to test at the same time. The Server Operating System "Performance" counter can monitor the server for application performance. Conclusion For website developers, pay attention to performance issues when writing ASP.NET applications, develop good habits, improve application performance, at least delegates required hardware upgrades, reduce the cost of the website.
Void Page_Load (Object O, Eventargs E) {if (! page.ispostback) {= new sqlconnection ("Server = localhost; uid = sa; pwd =; database = data"); string sql = "select * from student" Cmd.fill (DS, "STU"); myDataGrid.database ();}} The above code will ensure that the database is read and bind only when accessing this page for the first time. 2.4 rationally use the DataGrid control DataGrid control with the most powerful data display, but also has a lot of functions such as modification, deletion, addition, and pagination of data. If you simply display data, DataGrid is not the best choice. The paging function of the DataGrid control (stored in viewstate), etc. The DataList control is much less than the DataGrid function. But the customity has a lot. The unique multi-line data is still convenient. DataGrid can be implemented, it is basically possible. The Repeater control has the least function, but the customization is very strong. Due to a lot of functions, the performance of the server is minimized. Therefore, when simply displaying a list of data, select the REPEATER or DATALIST control can also achieve the purpose, and reduce performance overhead. Database Access Performance Optimization 1, the database connection and closing access database resources need to create a connection, open the connection, and turn off a few operations. These processes need to exchange information multiple times with databases to compare server resources through authentication. ASP.NET provides a connection pool to improve the impact of the database to the performance. The system places the user's database connection in the connection pool, take it out, and the connection is retracted, waiting for the next connection request. The size of the connection pool is limited. If the connection is required to create a connection after the connecting pool is maximized, it will inevitably affect performance. Therefore, after the establishment of the database connection, only the connection is turned on when you truly need to operate. It is immediately turned off again, thereby minimizing the time of the database connection to open, avoiding the situation that exceeds the connection limit. 2. Use the stored procedure stored procedure to be a set of pre-compiled SQL statements stored on the server, similar to batch files in the DOS system. The stored procedure has functions that are immediately accessed immediately, and the information processing is extremely rapid. Using the stored procedure can avoid multiple compilation of the command, after executing the execution plan resides in the cache, just call the binary code in the cache when needed. In addition, the stored procedure runs on the server side, independent of the ASP.NET program, which is easy to modify, the most important thing is that it can reduce the transmission of the database operation statement in the network. 3. Optimize the resource consumption of the ADO connection in Query statement ASP.NET is quite large, the longer the SQL statement runs, the longer the time of occupying system resources. Therefore, try to use an optimized SQL statement to reduce execution time. For example, not in the query statement contains a child query statement, take advantage of indexing, etc. String Operation Performance Optimization 1. When the TOSTRING method for use value is connected to the string, you often use the " " to add the numbers to the string. Although this method is simple, the correct result can be obtained, but due to the different data types, the number needs to be converted into the reference type by packing operation to be added to the string.
However, the packing operation has a large effect on performance, because when such processing is performed, a new object will be allocated in the hosted heap, and the original value is copied into the newly created object. Use the TOSTRING method of the value type to avoid packing operations, thereby improving application performance. 2, using the StringBuilder class String class object is unable, re-assay for String objects in nature, is in nature, imparts the object to the object, and its method to improve performance is not significant. When processing a string, it is best to use the StringBuilder class, and its .NET namespace is System.Text. This class does not create a new object, but through the Append, Remove, Insert, etc., the string is directly operated, and the results result is returned by the TSTRING method. Its definitions and operation statements are as follows: int Num; system.text.StringBuilder str = new system.text.stringbuilder (); // Create string str.Append (Num.tostring ()); // Add Numerical NumResponse. Write (str.tostring); // Display Operations ASP.NET application performance test Before you perform performance testing of the ASP.NET application, make sure the application has no error and the function is correct. The specific performance test can be performed using the following tools: Web Application Strees Tool (WAS) is a free test tool released by Microsoft, which can be downloaded from http://webtool.rte.microsoft.com/. It can simulate a hundred thousand users to access the web application, form a traffic load on the server, to achieve the purpose of the test, can generate average TTFB, average TTLB and other performance summary reports. Application Center Test (ACT) is a test tool that is included in the Enterprise Edition of Visual Studio.NET, which is a Web application test tool that Microsoft officially supported. It can intuitively generate chart results, the function is more than WAS, but does not have multiple clients to test at the same time. The Server Operating System "Performance" counter can monitor the server for application performance. Conclusion For website developers, pay attention to performance issues when writing ASP.NET applications, develop good habits, improve application performance, at least delegates required hardware upgrades, reduce the cost of the website.
Void Page_Load (Object O, Eventargs E) {if (! page.ispostback) {= new sqlconnection ("Server = localhost; uid = sa; pwd =; database = data"); string sql = "select * from student" Cmd.fill (DS, "STU"); myDataGrid.database ();}} The above code will ensure that the database is read and bind only when accessing this page for the first time. 2.4 rationally use the DataGrid control DataGrid control with the most powerful data display, but also has a lot of functions such as modification, deletion, addition, and pagination of data. If you simply display data, DataGrid is not the best choice. The paging function of the DataGrid control (stored in viewstate), etc. The DataList control is much less than the DataGrid function. But the customity has a lot. The unique multi-line data is still convenient. DataGrid can be implemented, it is basically possible. The Repeater control has the least function, but the customization is very strong. Due to a lot of functions, the performance of the server is minimized. Therefore, when simply displaying a list of data, select the REPEATER or DATALIST control can also achieve the purpose, and reduce performance overhead. Database Access Performance Optimization 1, the database connection and closing access database resources need to create a connection, open the connection, and turn off a few operations. These processes need to exchange information multiple times with databases to compare server resources through authentication. ASP.NET provides a connection pool to improve the impact of the database to the performance. The system places the user's database connection in the connection pool, take it out, and the connection is retracted, waiting for the next connection request. The size of the connection pool is limited. If the connection is required to create a connection after the connecting pool is maximized, it will inevitably affect performance. Therefore, after the establishment of the database connection, only the connection is turned on when you truly need to operate. It is immediately turned off again, thereby minimizing the time of the database connection to open, avoiding the situation that exceeds the connection limit. 2. Use the stored procedure stored procedure to be a set of pre-compiled SQL statements stored on the server, similar to batch files in the DOS system. The stored procedure has functions that are immediately accessed immediately, and the information processing is extremely rapid. Using the stored procedure can avoid multiple compilation of the command, after executing the execution plan resides in the cache, just call the binary code in the cache when needed. In addition, the stored procedure runs on the server side, independent of the ASP.NET program, which is easy to modify, the most important thing is that it can reduce the transmission of the database operation statement in the network. 3. Optimize the resource consumption of the ADO connection in Query statement ASP.NET is quite large, the longer the SQL statement runs, the longer the time of occupying system resources. Therefore, try to use an optimized SQL statement to reduce execution time. For example, not in the query statement contains a child query statement, take advantage of indexing, etc. String Operation Performance Optimization 1. When the TOSTRING method for use value is connected to the string, you often use the " " to add the numbers to the string. Although this method is simple, the correct result can be obtained, but due to the different data types, the number needs to be converted into the reference type by packing operation to be added to the string.
However, the packing operation has a large effect on performance, because when such processing is performed, a new object will be allocated in the hosted heap, and the original value is copied into the newly created object. Use the TOSTRING method of the value type to avoid packing operations, thereby improving application performance. 2, using the StringBuilder class String class object is unable, re-assay for String objects in nature, is in nature, imparts the object to the object, and its method to improve performance is not significant. When processing a string, it is best to use the StringBuilder class, and its .NET namespace is System.Text. This class does not create a new object, but through the Append, Remove, Insert, etc., the string is directly operated, and the results result is returned by the TSTRING method. Its definitions and operation statements are as follows: int Num; system.text.StringBuilder str = new system.text.stringbuilder (); // Create string str.Append (Num.tostring ()); // Add Numerical NumResponse. Write (str.tostring); // Display Operations ASP.NET application performance test Before you perform performance testing of the ASP.NET application, make sure the application has no error and the function is correct. The specific performance test can be performed using the following tools: Web Application Strees Tool (WAS) is a free test tool released by Microsoft, which can be downloaded from http://webtool.rte.microsoft.com/. It can simulate a hundred thousand users to access the web application, form a traffic load on the server, to achieve the purpose of the test, can generate average TTFB, average TTLB and other performance summary reports. Application Center Test (ACT) is a test tool that is included in the Enterprise Edition of Visual Studio.NET, which is a Web application test tool that Microsoft officially supported. It can intuitively generate chart results, the function is more than WAS, but does not have multiple clients to test at the same time. The Server Operating System "Performance" counter can monitor the server for application performance. Conclusion For website developers, pay attention to performance issues when writing ASP.NET applications, develop good habits, improve application performance, at least delegates required hardware upgrades, reduce the cost of the website.