This is a problem just discovered in the past two days. Remember it and hope it will be helpful to colleagues who are troubled by web performance!
Let's talk about the website's environment and status:
Environment: win2003 + asp.net + sqlserver2000, an online reading project with a daily PV of over 5 million and an independent IP address of over 30 thousand
Status:
1) The memory usage is MB;
2) cpu accounts for about 5%, but it will suddenly rush to 30% or even 50% every 20 seconds. (This is important)
3) each time the release program is updated, the cpu will occupy 5% for a period of time (about 30 minutes), and then it will be like the above 2nd (this is also very important)
After my analysis, I thought there should be something like a timer triggered once every 20 seconds to clean up the cache of the program, because the cache was not large at the beginning, therefore, there was no cpu instability problem 30 minutes before the program was updated. After 30 minutes, the larger the cache, the more cache to be cleaned, which caused the cpu instability.
So I checked all the programs, and I didn't even find any timer or other related words. I was wondering. I thought about things that can trigger the timer. Only global. asax is available. After reading this file, there are only several lines of code for the Session_End event, as shown below:
Code
Void Session_End (object sender, EventArgs e)
{
// The code that runs when the session ends.
// Note: Only the sessionstate mode in the Web. config file is set
// The Session_End event is triggered only when InProc is used. If the session mode is set to StateServer
// Or SQLServer, the event is not triggered.
If (Session. SessionID! = "")
{
Application. Remove ("id" + Session. SessionID );
Application. Contents. Remove ("id" + Session. SessionID );
}
}
Is it really a problem here, trying to remove this code, update and release, the cpu has remained stable.
It seems that the problem has finally been found. To further understand how many operations are there, I changed the code to this
Code
Void Session_End (object sender, EventArgs e)
{
// The code that runs when the session ends.
// Note: Only the sessionstate mode in the Web. config file is set
// The Session_End event is triggered only when InProc is used. If the session mode is set to StateServer
// Or SQLServer, the event is not triggered.
If (Session. SessionID! = "")
{
String sessoinId = Session. SessionID;
String applicationContent = Application. Contents ["id" + Session. SessionID]. ToString ();
SessionLog. Insert (sessionId, applicationContent, DateTime. Now); // record the data to the database.
Application. Remove ("id" + Session. SessionID );
Application. Contents. Remove ("id" + Session. SessionID );
}
}
Updated and released. About half an hour later, the database finally had data and found that the time was between 00-01 seconds, between 20-21 seconds, and between 40-41 seconds, there are about 70-data records each time.
I am not. net expert, I don't know how this Session_End is triggered, but through the test results, I personally think Session_End should be triggered every 20 seconds, if an expired Session is found, the code in Session_End is executed. For example, my website has performed more than 100 applications. remove (), so the cpu will jump once every 20 seconds.
Can anyone explain this to me in detail? If so, thank you very much.
I also hope this will be helpful to everyone who is troubled by performance.