search
HomeDatabaseMysql TutorialTake a look at MySQL concurrency parameter tuning

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)

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)

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)

| 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
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment