Solve MySQL congestion problem insert delayed

Source: Internet
Author: User

Because MySQL's concurrent data insertion capability is not well evaluatedProgramMySQL congestion is ignored.

As a result, the program is blocked by MySQL from time to time, causing sub-processes to wait for MySQL to release the plug and complete the INSERT command. Fault symptom:
    • All blocked sub-processes are in sbwait status.
    • Parent process, waiting for the child process to end, is in the Wait Status
    • If you do not manually kill the blocked sub-processes, these processes will always exist.
Cause troubleshooting: start to suspect that it is a socket problem. This is because the connection to the server is blocked while waiting for the other party to close the connection. It took a long time to check and debug the socket part. Code When I thought it had been solved several times, and there was another fault, it all ended in failure. This weekend, we will re-connect the entire socket and check the database connections one by one. It is found that the sbwait status is caused by MySQL blocking. In the case of multi-process concurrency, MySQL resources are also preemptible. MySQL locks the table by default. When a sub-process is locked for insertion, B sub-process can only wait. As well as concurrency congestion. Solution:
    • Optimize table structure and data structure
    • Change Insert into to insert delayed
    • Change the program structure so that each sub-process opens a MySQL connection
Description: insert delayed into: the client submits data to MySQL, and MySQL returns OK to the client. This is not to insert data into the table, but to store the data in the memory and wait for the queue. When MySQL is free, insert it again. The advantage is that the client does not need to wait too long to increase the insert speed. The disadvantage is that you cannot return an auto-incrementing ID, and if the system crashes, MySQL will lose the data before it can be inserted. Observation: After these adjustments, the system runs for one day without blocking. The running time is also shortened. Use phpMyAdmin to observe the MySQL process. After submission, some processes whose users are delayed and whose status is waiting for insert are displayed. After a while, the data will disappear after being completely inserted. Summary: For a system, we need to consider the existing and possible problems. We should not be too one-sided and self-righteous.
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: 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.