A select statement causes a bottleneck

Source: Internet
Author: User

Situation: Last week, the company launched a new project. On the first day of its launch, we found a bottleneck in the network I/O between the database server and the IIS server in the background, with 1 GB of network bandwidth, it occupies 70%-100%, that is, 700 mb-1 GB of data is transmitted per second, and the memory usage of the database is as high as 21 GB.

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

 

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.

 

Summary:

Be careful in your work and avoid making low-level mistakes. Sometimes success depends on the details.

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.