Database Thread Pool Control Using Coroutines for High Concurrency
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
The default concurrent connection model of MySQL databases leads to frequent thread creation and destruction, causing freezing or crashing in high-concurrency scenarios, and excessive thread numbers increase task scheduling burdens, resulting in 'starvation' and response time jitter.
Innovation Solution
A database thread pool control method that replaces connection processing threads with coroutines using a dynamic runtime library, allowing for efficient scheduling through coroutine scheduling threads, divided into IO-intensive and computation-intensive types to manage different load types.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If one thread one connection model is used in MySQL database, then each connection can be processed independently, but frequent thread creation and destruction will cause database freezing or crashing in high-concurrency scenarios
Solution Approach 1:
The patent creates a dynamic runtime library that copies and replaces the original thread creation functions with coroutine-based implementations. This allows the system to maintain the appearance of thread-based processing while actually using coroutines, resolving the contradiction between reliability and concurrency handling.
Solution Approach 2:
The patent changes the fundamental parameter of thread management by introducing a thread pool with configurable size limits. Instead of creating threads dynamically for each connection, the system reuses a fixed pool of threads, preventing resource exhaustion and database freezing while maintaining high concurrency处理能力.
2Productivity
If long connection mode with large number of threads is used, then connection handling capacity increases, but task scheduling burden greatly increases causing starvation and response time jitter
Solution Approach 1:
The patent replaces heavy-weight thread scheduling with lightweight coroutine scheduling by copying and replacing the runtime library functions. Coroutines can be scheduled more efficiently with lower overhead, reducing the scheduling burden while maintaining high connection handling capacity.
Solution Approach 2:
The patent segments the scheduling system into dedicated IO scheduling threads and computation scheduling threads. This segmentation allows each thread type to optimize its scheduling strategy, reducing overall scheduling complexity while improving connection handling efficiency through specialized processing paths.
Data Source
Figure 1~2
Figure 3~4
Figure 5
AI summary
The present disclosure provides a database thread pool control method and apparatus. A specific implementation of the method comprises: loading a dynamic runtime library capable of replacing a thread with a coroutine in an operating system of a database to generate at least one coroutine scheduling thread; receiving a request for connection sent by a client to the database; detecting whether a request for creating a new thread in the database is a request for processing the request for connection; and in response to detecting that the request for creating a new thread in the database is a request for processing the request for connection, creating a coroutine corresponding to the request for connection, and scheduling the coroutine with the at least one coroutine scheduling thread to complete an access task corresponding to the request for connection.