ASP.NET massive access processing experience sharing

IIS has opened up the platform to us. We no longer need to use complex sockets to parse the client's http requests, and IIS itself provides a complete set of solutions for handling massive links.

 

 

However, as far as I know, few people use the advanced functions of IIS or use third-party services to optimize massive links. Most programmers use a single-process model for Web development, without any cache development, and most of the system's processing power Are very limited.

 

In fact, it is not an easy task to handle massive amounts of links. Here I share a little experience of mine. In IIS, for both sites and virtual directories, you can specify the corresponding application pool. For different sites, different virtual directories, and for different applications, especially those with huge traffic, it is best to set up different application pools.

 

Many people can set up the application pool, but it is not easy to use it well. Here I will focus on the web garden in the second option of the application pool. In the options of the Web Park, the application pool can be set to multi-process, which can greatly improve the processing power of IIS.

 

It is true that many people will set up a Web park, but after setting up a Web park, the problem of the program architecture is the focus of my discussion. Because the static and session variables in the Web program are stored in the process, the process is the last boundary of the application. After setting up a multi-process web, the values ​​of static and session variables may be lost. For example, the process of processing page a sets a static or session variable. When page b is opened, it may or may not be read, because when processing page b, IIS may have started another process to process this page .

 

In this case, asp.net provides a perfect solution for session variables. Just in the configuration file

Set the <sessionState mode="StateServer"></sessionState>, and then start the asp.net status server service in the system service.

 

However, the handling of static type variables is not so simple. Static is very useful. As long as there is a complete memory release mechanism in time, the intermediate results of processing can be stored in static variables. For example, a data query service executes the query when it is accessed for the first time and saves the results in static variables. If there is a lot of data, the client can load it in asynchronous paging, and directly read the static variable during the second visit, and there is no need to perform data query and analysis operations that occupy a high CPU.

 

However, the static type is no longer available due to the setup of multiple processes, so what is the solution? In fact, we can build another windows service or web service program. If it is to build a windows service, IIS can save the data to the windows service through remoting. The windows service is responsible for saving this data, and then returns an ID to IIS, and then IIS returns the ID To the client, if the client wants to fetch the data in the future, it does not need to go to the database to fetch it, directly use this ID to post to IIS, and IIS will use remoting to the windows service to fetch the intermediate result; if it is to build a web service, then It cannot be the same application pool as the original web application, and the application pool of the web service that saves state data can only be set to a single process. Then external web applications deal with this web service. The processing method is the same as that of windows service. In fact, the principle is the same as that of asp.net status service.

 

In this way, the state data can be saved in the multi-process web program, and the web performance is greatly improved. I have made a system that handles hundreds of requests per second. If there is only a single-process IIS, the number of threads in w3wp.exe is increasing. It can’t be processed, and the result will eventually crash. Later I used this In this way, there are multiple w3wp.exe processes, and the number of threads in each process will not increase, and it handles massive link requests very well.

Guess you like

Origin blog.csdn.net/handsome0916/article/details/4576835