1. Reduce round trips)
The following method can be used to reduce the round-trip between the Web server and browser:
1. Enable cache for Browser
If the displayed content is static or has a long change period, browser cache should be enabled to avoid redundant HTTP requests.
2. Buffer page output
If possible, try to buffer the page output and send it to the client again after processing. This avoids multiple network interactions caused by frequent transmission of small pieces of content. Because the client cannot see the page content before page processing ends, if the size of a page is large, you can use the response. Flush method. This method forces the output of content in the buffer so far. You should use a reasonable algorithm to control the number of times the response. Flush method is called.
3. Use server. Transfer to redirect requests
The redirect request using the server. transfer method is better than the response. Redirect method. The reason is that response. Redirect will send a response header to broswer, pointing to the redirected URL in the Response Header, then Brower uses the new URL to re-send the request. The server. transfer method is a simple server call without these overhead!
Note that server. Transfer has limitations: First, it skips the security check; second, it is only applicable to page jumps within the same web application.
Ii. Avoid blocking and long-time jobs
If you need to run a blocking or long-running operation, you can consider using an asynchronous call mechanism so that the Web server can continue to process other requests.
1. Use Asynchronous Method to call Web Services and remote objects
As long as it is possible to avoid synchronous calls to Web Services and remote objects during request processing, because it occupies ASP. net thread pool, which will directly affect the web server's ability to respond to other requests.
2. consider adding the oneway attribute to the web method or remote object method that does not require a returned value.
This mode allows the Web server to return immediately after being called. You can decide whether to use this method based on the actual situation.
3. Use a work queue
Submit the job to the work queue on the server. The client sends a request to poll the job execution result.
Iii. Use Cache
Caching can largely determine the final performance of ASP. NET applications. Asp.net supports page output caching and partial page caching, and provides cache APIs to supply applications to cache their own data. If cache is used, consider the following points:
1. Identify data with high creation and access costs
2. Evaluate the variability of data to be cached
3. evaluation data usage frequency
4. Easy-to-change data and unchanged data separation to be cached. Only unchanged data will be cached.
5. select an appropriate cache mechanism (besides Asp.net cache, application state and session state can also be used as cache)
4. Multithreading
1. Avoid creating threads during request processing
Creating a thread during request execution is a costly operation that seriously affects the performance of the Web server. If subsequent operations must be completed by a thread, we recommend that you use the thread pool to create/manage threads.
2. Do not rely on thread data slots or static thread Variables
Because the request execution thread is a working thread in the ASP. NET thread pool, the two requests of the same client may not be processed by the same thread.
3. Avoid blocking the request processing thread
4. Avoid asynchronous calls
This is similar to 1. Asynchronous calls may lead to the creation of new threads and increase the burden on the server. Therefore, if no concurrent job is to be executed, do not execute asynchronous calls.
V. System Resources
1. Consider implementing resource pools to improve performance
2. Call dispose or close to release system resources.
3. Do not cache or occupy Resources in the resource pool for a long time
4. Apply as late as possible and release as early as possible
6. Page Processing
1. Minimize page size
Including shortening the control name, CSS class name, removing unnecessary blank lines and spaces, and disabling unwanted viewstate
2. Enable the buffer for page output)
If the buffer mechanism is disabled, use the following method.
Use a program to open the page output cache:
Response. bufferoutput = true;
Use the @ page switch to enable the page output buffer mechanism:
Nodes that use the web. config or machine. config configuration file:
3. Optimize page output using page. ispostback
4. Improve cache efficiency and reduce rendering time by separating different content on the page
5. optimized the complex and costly cycle
6. reasonably use the computing resources of the client and transfer some operations to the client.
VII. viewstate
Viewstate is a mechanism designed by Asp.net to track status information between page backhaul by server controls.
1. Disable viewstate
If you do not need to track the page status, for example, the page does not return (PostBack), you do not need to handle server control events, or the control content is recalculated every time the page is refreshed, you do not need to use viewstate to record the page status. You can set the enableviewstate attribute for a specific webcontrol, or at the page level:
2. initialize control properties at appropriate time points
ASP. the properties set by the net control during the execution of constructor and initialization are not tracked and changes to the properties are tracked after the initialization phase, and finally recorded in the _ viewstate of the IE page. Therefore, selecting a proper execution point of the initialization control attribute can effectively reduce the page size.
3. Carefully select the content to be placed in viewstate.
Content placed in viewstate will be serialized/deserialized, and Asp.net is optimized for serialization of string, integer, Boolean, and other basic types, if array, arraylist, and hashtable are used to store basic types, type converter must be provided for other types. Otherwise, expensive binary serialization programs will be used.
Summary: it is not enough to use these technical methods based on your website. You must adjust these methods in a timely manner to solve important problems in a centralized manner, in this way, the website performance can be greatly optimized.