Solution to the problem of MySQL data delay jump

Solution to the problem of MySQL data delay jump

Today we analyzed another typical problem about database delay jump. In this process, we also provided some methods and techniques for analyzing the problem for reference.

First, in the high availability test, there is a set of environment detection intermittent. After investigation, it is found that the database has a delay. When logging in to the slave library to check the show slave status, it is found that the value of Seconds_behind_master is constantly jumping, that is, it keeps jumping from 0~39~0~39 at a frequency, which makes people very angry.

After checking the relevant logs of the database, I found that there were no log records for reference. How to analyze this problem? Let's reproduce it first, so I captured the logs of the problem three times according to the rhythm, that is, continuous monitoring through show slave status, capturing the output results of show slave status and saving them. In this way, we can get the offset change during the occurrence of a problem, and this change is the problem caused by SQLThread during the playback process.

For example, in the following output, I intercepted the relay log of the slave side for analysis. The corresponding field is Relay_Log_Pos

Slave_IO_State: Waiting for master to send event
         Master_Host: xxxx
         Master_User: dba_repl
         Master_Port: 4306
        Connect_Retry: 60
       Master_Log_File:mysqlbin.000044
     Read_Master_Log_Pos: 386125369
        Relay_Log_File: slave-relay-bin.000066
        Relay_Log_Pos: 386125580
    Relay_Master_Log_File: mysqlbin.000044

So we quickly get the change in offset: 385983806, 386062813, 386125580

Then I used mysqlbinlog to start analyzing the details of these log processes. According to the following command, I can quickly get three related tables in the dumped logs.

# grep INSERT relaylog_xxxx.dump |awk '{print $3 " " $4}'|sed 's/INTO//g'|sort|uniq
 act_action_exec_info
 act_join_desc
 dic_subsidy_marketing_querylog_202008

I gradually analyzed the data operations of each table, but the information I obtained was still limited. I continued to do further analysis, for example, let's analyze the transaction volume in the entire log:

# mysqlbinlog slave-relay-bin.000066 | grep "GTID$(printf '\t')last_committed" -B 1 \
> | grep -E '^# at' | awk '{print $3}' \
> | awk 'NR==1 {tmp=$1} NR>1 {print ($1-tmp);tmp=$1}' \
> | sort -n -r | head -n 100
mysqlbinlog: [Warning] unknown variable 'loose-default-character-set=utf8'
5278
5268
5268
5268
5253
5253
5253
5253
5253

It can be seen that it is about 5K, which is relatively large. Where does this additional information come from? I have enabled general_log in the main database, so that I can get more fine-grained operation logs.

Further analysis revealed that the entire business used the explicit transaction method: SET autocommit=0. The entire transaction contained several large SQL statements, which stored a lot of operation log details. In addition, during the transaction operation, multiple select count(1) from xxx operations were called based on the Mybatis framework.

After communicating with the business, the above issues have been basically clarified.

The above is the detailed solution to the problem of MySQL data delay and jump. For more information about MySQL data delay and jump, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to solve the mysql insert garbled problem
  • How to solve the problem that mysql cannot be closed
  • Solve the problem that the MySQL database crashes unexpectedly, causing the table data file to be damaged and unable to start
  • This article solves the compatibility problem between Django 2.2 and MySQL
  • A brief discussion on the datetime format when exporting table data from MySQL to Excel
  • Quickly solve the problems of incorrect format, slow import and data loss when importing data from MySQL
  • Quickly solve the problem of garbled characters and jump lines in mysql exported scv files
  • Modification of time zone problem of MySQL container in Docker
  • pyMySQL SQL statement parameter passing problem, single parameter or multiple parameter description
  • MySQL 5.7.30 Installation and Upgrade Issues Detailed Tutorial

<<:  Nginx dynamic and static separation implementation case code analysis

>>:  Solution to Ubuntu 20.04 Firefox cannot play videos (missing flash plug-in)

Recommend

On good design

<br />For every ten thousand people who answ...

Installation process of zabbix-agent on Kylin V10

1. Download the installation package Download add...

Examples of new selectors in CSS3

Structural (position) pseudo-class selector (CSS3...

Discussion on more reasonable creation rules for MySQL string indexes

Preface Regarding the use of MySQL indexes, we ha...

How to implement function currying and decurrying in Javascript

Function currying (black question mark face)? ? ?...

React High-Order Component HOC Usage Summary

One sentence to introduce HOC What is a higher-or...

JavaScript to implement voice queuing system

Table of contents introduce Key Features Effect d...

Use simple jQuery + CSS to create a custom a tag title tooltip

Introduction Use simple jQuery+CSS to create a cus...

Summary of pitfalls encountered in installing mysql and mysqlclient on centos7

1. Add MySQL Yum repository MySQL official websit...

Native JS to implement drag position preview

This article shares with you a small Demo that ad...

How to build sonarqube using docker

Table of contents 1. Install Docker 2. Install so...

Detailed examples of Linux disk device and LVM management commands

Preface In the Linux operating system, device fil...

React and Redux array processing explanation

This article will introduce some commonly used ar...

JavaScript canvas to achieve colorful clock effect

Use canvas to write a colorful clock! 1. Title (1...