One time MySQL consumes CPU high processing process

Source: Internet
Author: User
Tags cpu usage high cpu usage

This morning in the formal service deployment of new code, over a period of time, server load alarm, CPU usage alarm, Login server query, found that MySQL led to high CPU usage, so show processlist query a bit, see a lot of threads in sending The state of data and lock is the operation of a table in a select database.

The SQL statements for sending data were then copied and executed once, and it was found that the time to execute them was too long and then explain analyzed.

There is no primary key and index in the condition of a select, and because that field in the query condition is unique, the field is indexed with the development plan, so the SQL of select is not in the state of sending data according to this field;

There is a condition in a select that is based on the primary key query, but also in the sending data state, but this table uses a composite primary key, but the composite primary key is only the first field of the index, the second field is non-indexed, so the query speed is much slower.

The results of the test query based on the primary key field and the second field are as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/71/9B/wKioL1XUtIezrmHRAACDgefRG2U000.jpg "style=" float: none; "title=" 2.png "alt=" Wkiol1xutiezrmhraacdgefrg2u000.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/71/9E/wKiom1XUsnqQboygAACDZ4qPLB8515.jpg "style=" float: none; "title=" 1.png "alt=" Wkiom1xusnqqboygaacdz4qplb8515.jpg "/>

So you need to add an additional index to the second field.

Refer to the following article about the index of the composite primary key

http://www.oschina.net/question/12_38140

The CPU usage decreased a lot after the index was increased, but there was still a problem. So we go back to the version, in the test suit and then do the concurrency test, the problem is fully resolved and then deployed to the formal service. Turn on the slow query log in the test suit and optimize all the inefficient SQL execution.

Slow query log open articles

Http://www.cnblogs.com/echo-something/archive/2012/07/25/2607771.html

The mysql5.1 version supports Method 2, which dynamically turns the log on or off.


One time MySQL consumes CPU high processing process

Related Article

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.