Thoughts on the bottleneck caused by a select statement

Source: Internet
Author: User

Situation reproduction:

The company launched a new project. On the first day of its launch, it found a network IO bottleneck between the database server and the IIS server in the background. The 1 GB network bandwidth occupied 2nd-70%, that is, data is transmitted 700 MB-1 GB per second, and the database uses up to 21 GB of memory.

The CPU usage of the IIS server is frequently increased to 80%-90%, leading to frequent connection timeout on the website.

Cause: In the evening, I had to temporarily shut down the website, perform server maintenance, and perform comprehensive inspection and tracking. It was found that a Select statement resulted in:
Select * From Table1
The syntax of this statement is correct, but there is a problem in the application. Table1 stores more than 0.1 million rows of data, and the table data increases by tens of thousands every day.
To count the total number of rows, this statement is frequently called and refresh should not be less than 1000 times per second.
This also leads to network bottlenecks.

Solution: Change the Select statement

Copy codeThe Code is as follows:
Select Count (*) from Table1


The problem can be solved. The network I/O data is immediately reduced to less than 10 MB, and the memory usage of the database is also kept in the estimated range of 12 GB.

It seems very simple, but it is not. It takes six hours to solve the problem, one hour to check the problem, and five hours to modify the code.

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: info-contact@alibabacloud.com 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.