Using Stored Procedures
A stored procedure is a set of precompiled SQL statements stored on a server, similar to a batch file in a DOS system. The stored procedure has the function of immediate access to the database, and the information processing is very rapid. By using stored procedures, you can avoid multiple compilations of commands, which reside in the cache after a single execution, and need to call only the binary code in the cache at a later time. In addition, the stored procedure runs on the server side, independent of the ASP.net program, easy to modify, and most importantly, it can reduce the transmission of database operation statements in the network.
Optimizing query Statements
Asp. NET, the ADO connection consumes a large amount of resources, the longer the SQL statement runs, the longer it takes to occupy the system resources. Therefore, try to use optimized SQL statements to reduce execution time. For example, do not include subqueries in query statements, make full use of indexes, and so on.
2. String Operation Performance Optimization
ToString Method with value type
When connecting strings, you often add numbers directly to the string using the "+" number. Although this method is simple, it can get the correct result, but because it involves different data types, the number needs to be converted into a reference type by boxing operation to be added to the string. However, boxing operations have a greater impact on performance because, when such processing is done, a new object is allocated in the managed heap, and the original value is copied to the newly created object. Use the ToString method of value types to avoid boxing operations, thereby improving application performance.
using the StringBuilder class
The string class object is immutable, and the method ToString does not significantly improve performance for a string object that is essentially recreating a string object and assigning the new value to the object. When working with strings, it is best to use the StringBuilder class, whose. NET namespace is system.text. Instead of creating a new object, the class operates directly on the string through methods such as Append,remove,insert, and returns the result of the operation through the ToString method. Its definition and operation statements are as follows:
int num; System.Text.StringBuilder str = new System.Text.StringBuilder (); Creates a string str. Append (Num. ToString ()); Add numeric num Response.Write (str. ToString); Show operation result 3. Optimize the configuration files for your WEB server computer and specific applications to meet your specific needs
By default, the ASP.net configuration is set to enable the broadest range of features and to accommodate the most common scenarios. As a result, application developers can optimize and change some of these configurations to improve application performance, depending on the functionality that the application uses. The following list is some of the options you should consider.
Enable authentication only for the applications that you want.
By default, the authentication mode is Windows, or integrated NTLM. In most cases, for applications that require authentication, it is a good idea to disable authentication in the Machine.config file and enable authentication in the Web.config file. Configure the application according to the appropriate request and response encoding settings. The asp.net default encoding format is UTF-8. If your application is strictly ASCII, configure your application to use ASCII for a slight performance boost.
Consider disabling AutoEventWireup for your application.
Setting the AutoEventWireup property to False in the Machine.config file means that the page does not match the method name to the event and hooks the two (for example, Page_Load). If page developers want to use these events, you need to override them in the base class (for example, you need to rewrite page.onload for page load events instead of using the Page_Load method). If AutoEventWireup is disabled, the page gets a slight performance boost by leaving the event connection to the page author instead of automatically executing it.
Remove unused modules from the request processing pipeline.
By default, all features of a node in the Machine.config file of the server computer are kept active. Depending on the functionality used by your application, you can remove unused modules from the request pipeline for a slight performance boost. Review each module and its functionality and customize it to your needs. For example, if you do not use session state and output caching in your application, you can remove them from the list so that requests do not have to perform entry and exit code for each module without performing other meaningful processing.
13. Make all modules within the request pipeline as efficient as possible
All modules within the request pipeline have the opportunity to be run on each request. Therefore, it is critical to quickly trigger code when a request enters and leaves a module, especially in a code path that does not use module functionality. Performing throughput testing, respectively, when using and not using modules and configuration files, is useful for determining how quickly these methods are performed.
14. Redirect between pages of the same application using the HttpServerUtility.Transfer method
Using the Server.Transfer syntax, this method can be used in a page to avoid unnecessary client redirection.
15. Adjust the number of threads per worker process for the application if necessary
The ASP.NET request structure attempts to achieve a balance between the number of threads executing the request and the available resources. An application with sufficient CPU power is known to determine the number of requests that are allowed to execute at the same time, depending on the CPU power available for the request. This technique is called threading gating. However, under some conditions, the thread gate control algorithm is not very effective. You can monitor thread gating in PerfMon by using the Pipeline Instance Count performance counter that is associated with the ASP.net applications performance object. When a page invokes an external resource, such as database access or an XML Web services request, the page request usually stops and frees the CPU. If a request is waiting to be processed, and a thread in the thread pool is free, the waiting request will begin to be processed. Unfortunately, this can sometimes lead to a large number of simultaneous requests and many waiting threads on the WEB server that adversely affect server performance. Typically, if the gating factor is the response time of an external resource, it is not helpful for the throughput of the WEB server to have too many requests to wait for resources. To mitigate this situation, you can manually set the number of threads in the process by changing the maxWorkerThreads and Maxiothreads properties of the Machine.config configuration file node.
Note: Worker threads are used to process asp.net requests, while IO threads are used to service data from files, databases, or XML WEB services. The values assigned to these properties are the maximum number of each type of thread per CPU in the process. For dual-processor computers, the maximum number is twice times the set value. For four-processor computers, the maximum value is four times times the set value. In any case, for computers with four or eight CPUs, it is best to change the default values. For computers with one or two processors, the default value is OK, but for the performance of a computer with more processors, a process with 100 or 200 threads does more harm than good. Note that too many threads in a process tend to slow down the server because the extra context exchange causes the operating system to spend CPU cycles on maintaining threads rather than processing requests.