Database optimization and fault tracking and troubleshooting for large websites (Part II)

Source: Internet
Author: User
2 After database optimization, we foundIISThe CPU usage of the process is very high, and even instantly rises80% ~ 90


AIn this case, it is estimated thatCodeThere is an endless loop in. My God, there are hundreds or even thousands of files on the website. How can I find them.

First, analyze the situation of endless loops and Use Vbscript to writeASPWhen loop statements are used, an endless loop may occur. For example, the problem is best described as follows:


Strsql = "select name from user where name ='Zhang San'"

SetRs = server. Createobject ("ADODB. recordset ")

Rs. cursorlocation = 3

Rs. Open strsql, objconn, 0, 1' ObjconnIs the created object


I = 0

 Do while I <= 5 and not Rs. EOF

I = I + 1

'Some operations

Rs. movenext



IfRs. movenextForgot to write,It must be dead. However, this situation rarely happens. It is unforgivable to make such a mistake.

IfSQLThe statement is incorrect. For some reason, the condition changesName ="Zhang San", OrName =Zhang San; I found that the above statement was an endless loop during debugging. Wondering,I <= 5It should end the loop, but it does not. If you are interested, try it. At least the test is an endless loop.







A.Transformation cycle statement,Make it more robust. The test result shows that the loop can be ended.

I = 0

 Do while not Rs. EOF

I = I + 1

'Some operations

Rs. movenext

If I> 5 then

Exit do

End if



B.For recordset objects,If no record is opened Recordset Object,BOF And EOF Property will be setTrue, AndRecordset Object RecordcountThe property is set to zero. Open a record that contains at least one record Recordset Object, the first record is the current record, andBOF And EOF The property isFalse. However, I found that the above statement is not accurate when there is a record.I found someProgramWhen determining whether a user existsNot Rs. EOF,This may cause an endless loop based on the wrong logic. It is recommended that you useRecordcount.


Second, if the above method is too much code, it will not work. Here is a very targeted solution.

Idea: UseSQL MSTool "event probe" and "Task Manager ". Create a new trail. When the cup reaches100%Immediately pause the selected trace or stop the selected trace, and then roll out all the executed SQL commands, paste it to "query analyzer" to check for syntax errors.


Operation diagram:

Incorrect syntaxSQLStatement. This is important.


Through the above database optimization and fileSQLStatement troubleshooting. If the problem persists. Continue.


3, Open "performance" in "Administrative Tools" on the server"


Operation diagram:

Trace and view the parameters of each performance object: see the figure below

Please pay attention to the parameters in the red box. If the CPU load is too high due to excessive traffic, upgrade the server's hardware!

[Post-writing feeling]

This article is only based on the original framework design. It is an easy-to-use, robust, secure, and well-performing website that is far from enough. Please share your good framework design, storage structure, and valuable experience.


This article is just my own experience. If not, please give us some advice. We hope you will join in the discussion on optimization of large websites.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.