Home Database Mysql Tutorial Take a look at MySQL concurrency parameter tuning

Take a look at MySQL concurrency parameter tuning

Feb 03, 2021 am 09:22 AM
mysql concurrent

Take a look at MySQL concurrency parameter tuning

Free learning recommendation: mysql video tutorial

Mysql concurrency parameter adjustment

In terms of implementation, MySQL Server is a multi-threaded structure, including background threads and customer service threads. Multi-threading can effectively utilize server resources and improve the concurrency performance of the database. In Mysql, the main parameters that control concurrent connections and threads include max_connections, back_log, thread_cache_size, table_open_cahce.

1. max_connections

Use max_connections to control the maximum number of connections allowed to the MySQL database. The default value is 151. If the status variable connection_errors_max_connections is not zero and keeps growing, it means that there are continuous connection requests failing because the number of database connections has reached the maximum allowed value. This is why you can consider increasing the value of max_connections.
Description: When the number of simultaneous connection requests exceeds 151, there are no available connections to handle the client's request. These subsequent connections will be in a waiting state. Waiting for the MySQL connection to be released. If there is no idle connection, the request will time out

Mysql The maximum number of supported connections depends on many factors, including the quality of the thread library of the given operating system platform, Memory size, load per connection, CPU processing speed, expected response time, etc. Under the Linux platform, it is not difficult for a server with good performance to support 500-1000 connections. It needs to be evaluated and set based on the server performance.

2. back_log

The back_log parameter controls the backlog request stack size set when MySQL listens to the TCP port. If the number of MySql connections reaches max_connections, new requests will be stored in the stack to wait for a certain connection to release resources. The number of the stack is back_log. If the number of waiting connections exceeds back_log, connection resources will not be granted. An error will be reported. The default value before version 5.6.6 is 50, and the default value for subsequent versions is 50 (max_connections / 5), but the maximum does not exceed 900.
Description: When the concurrent number of requests sent by the client at the same time is greater than 151, subsequent requests will be in a waiting state. Then the number of waiting connections can reach back_log. These new requests will be stored in the stack. to wait for a connection to be released. The number of stacks is set through back_log.

If you need the database to handle a large number of connection requests in a short period of time, you can consider appropriately increasing the value of back_log.

3. table_open_cache

This parameter is used to control the number of table caches that can be opened by all SQL statement execution threads. When executing a SQL statement, each The SQL execution thread must open at least 1 table cache. The value of this parameter should be set according to the maximum number of connections max_connections set and the maximum number of tables involved in executing related queries for each connection :

max_connections x N;
Note: This is not for a certain session, this is for all client execution threads. The number of table caches is the number of tables operated in each SQL statement. For example, a SQL statement generally operates at least one table. If you operate one table, there will be one table cache. If you operate multiple tables, there will be multiple table caches.

mysql> show variables like 'table_open_cache%';+----------------------------+-------+| Variable_name              | Value |+----------------------------+-------+| table_open_cache           | 431   || table_open_cache_instances | 16    |+----------------------------+-------+2 rows in set (0.06 sec)
Copy after login

4, thread_cache_size

In order to speed up the connection to the database, MySQL will cache a certain number of customer service threads for reuse, which can be controlled through the parameter thread_cache_size The number of MySQL cache client service threads.
Description: This is equivalent to opening a thread pool on the MySQL server. When the client makes a request, we take out a thread in the thread pool to perform task processing.

mysql> show variables like 'thread_cache_size%';+-------------------+-------+| Variable_name     | Value |+-------------------+-------+| thread_cache_size | 8     |+-------------------+-------+1 row in set (0.00 sec)
Copy after login

A total of 8 thread information is cached.

5. innodb_lock_wait_timeout

This parameter is used to set the time for InnoDB transactions to wait for row locks. The default value is 50ms and can be set dynamically as needed. For business systems that require quick feedback, the waiting time for row locks can be adjusted smaller to avoid long-term suspension of transactions; for batch processing programs running in the background, the waiting time for row locks can be adjusted larger to avoid A large rollback operation occurred.

Note: If in a business system that responds quickly, if the row lock is not obtained, just report an error directly, and there is no need to wait for the transaction to respond for a long time.
As you can see, the default timeout is 50ms

mysql> show variables like 'innodb_lock_wait_timeout%';+--------------------------+-------+| Variable_name            | Value |+--------------------------+-------+| innodb_lock_wait_timeout | 50    |+--------------------------+-------+1 row in set (0.01 sec)
Copy after login

| Value | -------------------------- - ------- | innodb_lock_wait_timeout | 50 | -------------------------- ------- 1 row in set (0.01 sec)

More related free learning recommendations:mysql tutorial(Video)

The above is the detailed content of Take a look at MySQL concurrency parameter tuning. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

See all articles