In one of my Asp.net sites, the and B functions are provided, both of which consume Web Server resources (mainly CPU, it takes about half a minute to complete the function. If one user is using one of the and B functions, the CPU usage of w3wp is about 50%. If two or more users use one of the and B functions at the same time, the web server will become overwhelmed, and the CPU usage is nearly 100%. The website can hardly respond to other requests. Basically, a timeout error will be reported on all pages.
I once thought about changing these two functions from the immediate execution mode to creating a task queue. In the early morning, I used a special service to execute tasks in the task queue in sequence. But it is really unwilling to think about it, because it greatly reduces the ease of use of these two features. In addition, such resource-consuming operations on a site should be quite common and should be solved through other more advanced tasks or thread management. Possible solutions I can think of currently include:
(1) configure the thread pool of the website to limit the maximum CPU usage of each thread. (How to set it? Can I only set a fixed percentage or can I set a dynamic value based on the CPU usage of the current server ?)
(2) serialize the functions A and B, that is, create a queue. If a user wants to execute one of the functions a and B, check whether the queue is empty, if it is not null, it is added to the end of the queue. This method is significantly reduced ProgramBut it is easier to operate, and it is much more real-time than the method for executing services in the early morning.
There should be better solutions. Please help me a lot.