MySQL Server IO 100% Analysis and Optimization Solution

MySQL Server IO 100% Analysis and Optimization Solution

Preface

During the stress test, if the most direct performance problem caused by resource usage bottlenecks is that the business transaction response time is too long and the TPS gradually decreases, etc. In problem location analysis, the top priority is usually to monitor server resource utilization, such as using TOP or nmon to check CPU and memory usage, and then troubleshoot IO problems, such as network IO and disk IO problems. If it is a disk IO problem, the general problem is SQL syntax problem, MYSQL parameter configuration problem, or the server's own hardware bottleneck leading to IOPS throughput rate problem.

This article mainly introduces the analysis and optimization plan of MySQL server IO 100%. Let's take a look at the detailed introduction.

【question】

There is a MySQL 5.6.21 database instance that is mainly write-based, and the IO %util is close to 100%

High write IOPS

【Analysis process】

1. Through the iotop tool, you can see the mysql thread with the highest current IO consumption

2. Check the stack of thread 49342, and you can see that the redo log is being refreshed, corresponding to file 9.

3. File No. 9 corresponds to the first file of the redo log

Why does the MySQL process frequently refresh the redo log file? We need to analyze it in combination with the redo log flushing strategy. The key is the innodb_flush_log_at_trx_commit parameter.

The default value is 1, which is the safest. However, it may also have a significant performance impact when write pressure is high. Each time a transaction is committed, MySQL writes the data in the log buffer to the log file and flushes it to disk.

Considering the write scenario of this cluster, most of the writes are small transactions, and each transaction commit triggers a disk flush. In this scenario, the optimization effect of increasing innodb_log_buffer_size and innodb_log_file_size is not obvious.

【Optimization plan】

1. At the application level, for systems with heavy write pressure, a single insert statement can be optimized into a small batch of insert statements. This will reduce the number of transaction commits and redo log flushes, and theoretically improve performance.

2. At the MySQL level, for log-type systems, if a small amount of data loss is allowed in the event of downtime, the innodb_flush_log_at_trx_commit parameter can be adjusted to 2.

When set to 2, only write operations are performed when the transaction is committed, and only the system page cache is guaranteed to be written. Therefore, transactions will not be lost if the instance crashes, but transactions may be lost if the system crashes.

In the test on this server, when the parameter is adjusted to 2, the IO request drops from 200M/S to about 10M/S, and the pressure is reduced by more than 10 times.

3. At the system level, replace the disk with a better performance

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • Analyze the sql statement efficiency optimization issues of Mysql table reading, writing, indexing and other operations
  • Xiaomi officially open-sources SQL intelligent optimization and rewriting tool SOAR
  • Detailed explanation of Mysql's method of optimizing order by statement
  • Detailed explanation of MYSQL configuration parameter optimization
  • Usage and performance optimization techniques of aggregate function count in MySQL
  • Mysql query the most recent record of the sql statement (optimization)
  • Detailed explanation of 30 SQL query optimization techniques for MySQL tens of millions of large data
  • PHP+MySQL to achieve daily data statistics optimization operation example within a period of time
  • SQL statement optimization: JOIN, LEFT JOIN and RIGHT JOIN statement optimization
  • Database SQL statement optimization

<<:  Vue implements tab label (label exceeds automatic scrolling)

>>:  Detailed tutorial on deploying apollo with docker

Recommend

Javascript scope and closure details

Table of contents 1. Scope 2. Scope Chain 3. Lexi...

How to control the proportion of Flex child elements on the main axis

background Flex layout achieves alignment and spa...

Nodejs-cluster module knowledge points summary and example usage

The interviewer will sometimes ask you, tell me h...

Can CSS be used like this? The art of whimsical gradients

In the previous article - The charm of one line o...

vue+element-ui implements the head navigation bar component

This article shares the specific code of vue+elem...

How to use Celery and Docker to handle periodic tasks in Django

As you build and scale your Django applications, ...

How to manually scroll logs in Linux system

Log rotation is a very common function on Linux s...

MySQL 8.0.13 download and installation tutorial with pictures and text

MySQL is the most commonly used database. You mus...

HTML sub tag and sup tag

Today I will introduce two HTML tags that I don’t...

MySQL Optimization Solution Reference

Problems that may arise from optimization Optimiz...

Summary of learning HTML tags and basic elements

1. Elements and tags in HTML <br />An eleme...

Solution to forgetting mysql database password

You may have set a MySQL password just now, but f...