Database Thread Pool Control Using Coroutines for High Concurrency

Resolve Bottlenecks,
Find Innovative Solutions
Generate 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

VSEngineering 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

Engineering Contradiction:
Improvedatabase stabilityVSAvoidconcurrency handling capability
Core Design Contradiction:
ReliabilityVSProductivity

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.

Inventive Principle:
Principle #26Copying

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处理能力.

Inventive Principle:
Principle #35Parameter changes

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

Engineering Contradiction:
Improveconnection handling capacityVSAvoidtask scheduling complexity
Core Design Contradiction:
ProductivityVSDevice complexity

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.

Inventive Principle:
Principle #26Copying

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.

Inventive Principle:
Principle #1Segmentation

Data Source

PatentEP4654011A1Database thread pool control method and apparatus, electronic device, and computer medium
Publication Date: 2025.11.26 JD DIGITS HAIYI INFORMATION TECHNOLOGY CO LTD
  • EP4654011A1 patent drawingFigure 1~2
  • EP4654011A1 patent drawingFigure 3~4
  • EP4654011A1 patent drawingFigure 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.