This article uses a special case: the end user uses a browser to request a page containing 100 latest news records from the server.
This article focuses on ASP. net web server (specifically used to receive user requests, process business logic and respond to HTML servers; distributed, client, IIS, database and application server configuration and optimization part, will be introduced later)
ApplicationProgramLevel
1. Use the release version in the production environment instead of the debug version.
2. Remove unnecessary HTTP modules
- Access httpcontext. Current. applicationinstance. modules at runtime to determine the module used
- Remove unnecessary HTTP modules through web. config
- For example, if you do not want to use session, remove the sessionmodule.
- In this case, because news data has nothing to do with users, we may be able to remove many modules.
3. Remove unnecessary files
- Especially useless DLL and PDB files
4. Enable Server Configuration
- For example, GC runs in server mode.
5. Check global code and functions
Page Level
1. Consider using a lightweight processing mode than aspx, such as ashx (httphandler)
- For example, you need a page to provide or receive data as an interface (instead of returning a bunch of HTML)
- The lifecycle of the ASPX page is too heavy and slow
- Server controls are often used inside aspx, which is also a heavyweight master
- Viewstate generated by the server control in aspx ....
- I personally prefer using MVC for webpage and WCF services.
2. Avoid using heavyweight Solutions
- Asp.net updatepanel)
- EXT, componentart, and other heavyweight third-party solutions
3. Avoid page or class inheritance that is too deep (for example, apage: bpage ....)
- Do not design super parent classes with a large set of functions
- The inheritance level is too deep, which consumes more performance.
4. Optimization Logic
5. Be careful when using heavyweight resources, including but not limited
- Thread
- Sesssion
- Application
- Kernel lock
- Memory
- A large number of small objects (GC pressure, such as a large number of small strings) can be investigated using windbg + SOS
6.Design often has a crucial impact on performance.
- For example, for long-time operations, Asynchronization is much better than synchronization.
- For example, for a large batch of similar operations, batch operations are much better than one operation.
- The CPU is not full, and you want to shorten the response time and consider multithreading.
- When the CPU is full, consider changing the space for time.
- When the CPU is not full, consider changing the time to space (note that the IO pressure will also lead to CPU. At this time, consider changing the space to time)
- For example, data and style separation are considered during the design. Each time you pull the data again, for example, when you pull the data, the server only returns the updated data.
- For example, if the data is updated according to the Update time, it is a problem to sort the data according to the Update time during each read. It is better to save the latest 100 data records in the memory, if there is an update, the oldest and newest items in the set will be removed directly (several additional items can be left for backup)
- This example is generally a good example of using the cache because the number of read/write operations and the percentage of read/write operations may reach.
Cache
1. Page cache and page fragment Cache
<% @ Outputcache duration = " 60 " Varybyparam = " None " %>
< Html >
< Script Language = "C #" Runat = "Server" >
Void Page_load (Object sender, eventargs E)
{
Timemsg. Text = Datetime. Now. tostring ( " G " );
}
</ Script >
< Body >
< H3 > Using the output Cache </ H3 >
< P > Last generated on: < ASP: Label ID = "Timemsg" Runat = "Server" />
</ Body >
</ Html >
2. Use 304 cache or browser cache as appropriate
3. Use httpruntimecache to cache data, or use static objects to cache data
- If you do not need to control the expiration time or never expire, we recommend that you use static objects to cache data. The cache is actually very heavy.
4. For this solution
- You can put the 100 pieces of data in the memory. If the memory is directly updated when there is an update, you can directly read the data from the memory when you need to read the data.
- Cache synchronization and updates are always a big problem. Choosing different caches depends on your desired performance and affordability (for example, if you can accept 1 minute of data latency, cache)
- Good thread synchronization knowledge can reduce many bugs
Code Level
1. Design possible classes as closed (not inherited)
2. Use more efficient methods
- For example, use request. querystring [Key] instead of request [Key].
- For example, Int. tryparse, instead of Int. parse.
- Exercise caution when using exceptions
Slowly add, not to be continued ......
Tool measurement is an important aspect, such as dottrace, Visual Studio 2010 Performance Testing Tool, LoadRunner, and other stress testing tools.
However, such tools cannot compensate for the lack of basic concepts. For example, the performance of closed classes is better than that of non-closed classes (tools like fxcop can help you a little in this regard ),
However, tools can help you accurately measure the modified performance. The final performance is the key to determining the value of optimization.
In addition, high performance generally conflicts with maintainability, so you need to find a balance point.
My skills are limited. I hope you can discuss them together.