Explanation of factors affecting database performance in MySQL

Explanation of factors affecting database performance in MySQL

A story about database performance

During the interview, the topic of database will be discussed to some extent, such as "How familiar are you with database?" When is the performance of the database most tested? In general, it is when reading and writing large amounts of data. Large promotional activities of e-commerce are the time to test the performance of each database.

For web servers, when the amount of data is large, we can simply reduce the burden on a single server by horizontal expansion. However, it is not that simple for database servers. They cannot be easily expanded horizontally, which also violates the principles of database integrity and consistency. So how should our database architecture be built?

For big promotion activities, no matter how good the product is or how successful the planning is, if there is no stable database and server environment, all this will be in vain.

Database architecture example

As shown in the figure, there is no master-slave replication component between the master and slave servers. That is, when the master server fails, it is difficult to switch the master server. This requires the DBA to select the slave server with the latest data from the slave servers, promote it to the master server, and synchronize other slave servers. The time cost of this process is also very heavy.

Moreover, too many slave servers will also pose a certain challenge to the network card of the main server when the business volume is large.

We can use cluster monitoring information to understand what affects database performance.

The answer is yes. Generally speaking, the main reasons are QPS and TPS, concurrency (the number of requests processed at the same time, to avoid confusion with the number of simultaneous connections), disk IO, and read operations are too high.

Here is a suggestion: it is best not to back up data on the main database, at least cancel such plans before large-scale activities.

Factors affecting the database

  • SQL query speed
  • Server Hardware
  • Network card traffic
  • Disk IO

Ultra-high QPS and TPS

Risk: Inefficient SQL (QPS: queries processed per second)

High CPU usage and high concurrency

Risk: A large number of concurrent connections (the number of database connections is full (max_connections defaults to 100))

Risk: Extremely high CPU usage (downtime due to CPU exhaustion)

Disk IO

Risk: Disk IO performance suddenly drops (use faster disk devices)

Risk: Other scheduled tasks that consume a lot of disk performance (adjust scheduled tasks)

Network card traffic

Risk: Network card IO is full (1000Mb/8=100MB)

How to avoid being unable to connect to the database:

1. Reduce the number of slave servers
2. Perform hierarchical caching
3. Avoid using "select *" for queries
4. Separate business network and server network

You may also be interested in:
  • Usage and performance optimization techniques of aggregate function count in MySQL
  • Detailed explanation of the reasons and optimizations for the large offset affecting performance during MySQL query
  • Example of how to optimize MySQL insert performance
  • MySQL performance comprehensive optimization method reference, from CPU, file system selection to mysql.cnf parameter optimization
  • A brief discussion on the difference between MySQL and MariaDB (performance comparison between mariadb and mysql)
  • Optimizing the performance of paging query for MySQL with tens of millions of data
  • MySQL paging performance exploration
  • Detailed explanation of MySQL batch SQL insert performance optimization
  • Summary of several important performance index calculation and optimization methods for MySQL

<<:  Vue implements DingTalk's attendance calendar

>>:  Keepalived+Nginx+Tomcat sample code to implement high-availability Web cluster

Recommend

CocosCreator Skeleton Animation Dragon Bones

CocosCreator version 2.3.4 Dragon bone animation ...

Summary of MySQL character sets

Table of contents Character Set Comparison Rules ...

Web design skills: iframe adaptive height problem

Maybe some people have not come across this issue ...

Use auto.js to realize the automatic daily check-in function

Use auto.js to automate daily check-in Due to the...

Introduction to MySQL method of deleting table data with foreign key constraints

When deleting a table or a piece of data in MySQL...

SQL implements LeetCode (180. Continuous numbers)

[LeetCode] 180. Consecutive Numbers Write a SQL q...

A brief discussion on whether CSS will block page rendering

Maybe everyone knows that js execution will block...

Remote Desktop Connection between Windows and Linux

When it comes to remote desktop connection to Lin...

Differences between Windows Server 2008R2, 2012, 2016, and 2019

Table of contents Common version introduction Com...

jQuery implements shopping cart function

This article example shares the specific code of ...

Basic knowledge of MySQL learning notes

View Database show databases; Create a database c...

Vue+ElementUI implements paging function-mysql data

Table of contents 1. Problem 2. Solution 2.1 Pagi...

Detailed explanation of nginx reverse proxy webSocket configuration

Recently, I used the webSocket protocol when work...