8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / A MySQL 8.4 Frequently Asked Questions / A.15 MySQL 8.4 FAQ: MySQL Enterprise Thread Pool
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 83%

A.15 MySQL 8.4 常见问题解答:MySQL 企业线程池A.15 MySQL 8.4 FAQ: MySQL Enterprise Thread Pool

A.15.1. 什么是线程池,它解决了什么问题? A.15.1. What is the Thread Pool and what problem does it solve?
A.15.2. 线程池如何限制和管理并发会话和事务,以实现最佳性能和吞吐量? A.15.2. How does the Thread Pool limit and manage concurrent sessions and transactions for optimal performance and throughput?
A.15.3. 线程池与客户端连接池有何不同? A.15.3. How is the Thread Pool different from the client side Connection Pool?
A.15.4. 我什么时候应该使用线程池? A.15.4. When should I use the Thread Pool?
A.15.5. 是否有推荐的线程池配置? A.15.5. Are there recommended Thread Pool configurations?

A.15.1.

什么是线程池,它解决了什么问题?What is the Thread Pool and what problem does it solve?

MySQL 线程池是一个 MySQL 服务器插件,扩展了 MySQL 服务器的默认连接处理功能,以限制同时执行的语句/查询和事务的数量,确保每个语句/事务都有足够的 CPU 和内存资源来完成其任务。对于 MySQL 8.4,线程池插件包含在 MySQL 企业版中,这是一个商业产品。The MySQL Thread Pool is a MySQL server plugin that extends the default connection-handling capabilities of the MySQL server to limit the number of concurrently executing statements/queries and transactions to ensure that each has sufficient CPU and memory resources to fulfill its task. For MySQL 8.4, the Thread Pool plugin is included in MySQL Enterprise Edition, a commercial product.

MySQL 服务器中的默认线程处理模型为每个客户端连接使用一个线程来执行语句。随着更多客户端连接到服务器并执行语句,整体性能会下降。线程池插件提供了一种替代的线程处理模型,旨在减少开销并提高性能。线程池插件通过为大量客户端连接有效管理语句执行线程,提高服务器性能,尤其是在现代多 CPU/核心系统上。The default thread-handling model in MySQL Server executes statements using one thread per client connection. As more clients connect to the server and execute statements, overall performance degrades. The Thread Pool plugin provides an alternative thread-handling model designed to reduce overhead and improve performance. The Thread Pool plugin increases server performance by efficiently managing statement execution threads for large numbers of client connections, especially on modern multi-CPU/Core systems.

更多信息,请参见 第 7.6.3 节,“MySQL Enterprise 线程池”。For more information, see Section 7.6.3, “MySQL Enterprise Thread Pool”.

A.15.2.

线程池如何限制和管理并发会话和事务,以实现最佳性能和吞吐量?How does the Thread Pool limit and manage concurrent sessions and transactions for optimal performance and throughput?

线程池使用“分而治之”方法来限制和平衡并发。与 MySQL 服务器的默认连接处理方式不同,线程池将连接与线程分离,因此连接与执行来自这些连接的语句的线程之间没有固定关系。随后,线程池在可配置的线程组中管理客户端连接,根据提交任务的性质对其进行优先级排序和排队处理。The Thread Pool uses a “divide and conquer” approach to limiting and balancing concurrency. Unlike the default connection handling of the MySQL Server, the Thread Pool separates connections and threads, so there is no fixed relationship between connections and the threads that execute statements received from those connections. The Thread Pool then manages client connections within configurable thread groups, where they are prioritized and queued based on the nature of the work they were submitted to accomplish.

有关更多信息,请参见 第 7.6.3.3 节,“线程池操作”。For more information, see Section 7.6.3.3, “Thread Pool Operation”.

A.15.3.

线程池与客户端连接池有何不同?How is the Thread Pool different from the client side Connection Pool?

MySQL 连接池在客户端运行,以确保 MySQL 客户端不会持续不断地连接和断开 MySQL 服务器。它旨在在 MySQL 客户端中缓存空闲连接,以便其他用户在需要时使用。这可以在向 MySQL 服务器提交查询时,最大限度地减少建立和拆除连接的开销和成本。MySQL 连接池无法看到后端 MySQL 服务器的查询处理能力或负载。相比之下,线程池在 MySQL 服务器端运行,旨在管理从客户端连接访问后端 MySQL 数据库时接收到的并发连接和查询的执行。由于职责的分离,MySQL 连接池和线程池是正交的,可以相互独立使用。The MySQL Connection Pool operates on the client side to ensure that a MySQL client does not constantly connect to and disconnect from the MySQL server. It is designed to cache idle connections in the MySQL client for use by other users as they are needed. This minimizes the overhead and expense of establishing and tearing down connections as queries are submitted to the MySQL server. The MySQL Connection Pool has no visibility as to the query handling capabilities or load of the back-end MySQL server. By contrast, the Thread Pool operates on the MySQL server side and is designed to manage the execution of inbound concurrent connections and queries as they are received from the client connections accessing the back-end MySQL database. Because of the separation of duties, the MySQL Connection Pool and Thread Pool are orthogonal and can be used independent of each other.

通过 MySQL 连接器进行 MySQL 连接池的使用在 第 31 章,连接器和 API 中有介绍。MySQL Connection Pooling via the MySQL Connectors is covered in Chapter 31, Connectors and APIs.

A.15.4.

我什么时候应该使用线程池?When should I use the Thread Pool?

在选择最佳线程池使用场景时,可以考虑以下几个经验法则:There are a few rules of thumb to consider for optimal Thread Pool use cases:

MySQL Threads_running 变量用于跟踪当前在 MySQL 服务器中并发执行的语句数。如果该变量持续超过服务器无法最佳运行的范围(对于 InnoDB 工作负载通常超过 40),线程池将会有帮助,特别是在极端并行过载的情况下。The MySQL Threads_running variable keeps track of the number of concurrent statements currently executing in the MySQL Server. If this variable consistently exceeds a region where the server won't operate optimally (usually going beyond 40 for InnoDB workloads), the Thread Pool should be beneficial, especially in extreme parallel overload situations.

如果您正在使用 innodb_thread_concurrency 来限制并发执行的语句数量,您会发现线程池可以解决相同的问题,而且做得更好,它通过将连接分配到线程组,然后根据事务内容、用户定义的指定等来排队执行。If you are using the innodb_thread_concurrency to limit the number of concurrently executing statements, you should find that the Thread Pool solves the same problem, only better, by assigning connections to thread groups, then queuing executions based on transactional content, user defined designations, and so forth.

最后,如果您的工作负载主要由短查询组成,线程池应该会带来好处。Lastly, if your workload comprises mainly short queries, the Thread Pool should be beneficial.

要了解更多信息,请参见 第 7.6.3.4 节,“线程池调优”。To learn more, see Section 7.6.3.4, “Thread Pool Tuning”.

A.15.5.

是否有推荐的线程池配置?Are there recommended Thread Pool configurations?

线程池有许多由用户使用场景驱动的配置参数,这些参数会影响其性能。要了解这些参数以及优化的建议,请参见 第 7.6.3.4 节,“线程池调优”。The Thread Pool has a number of user case driven configuration parameters that affect its performance. To learn about these and tips on tuning, see Section 7.6.3.4, “Thread Pool Tuning”.