A MYSQL database query method and device based on thread pool
The MYSQL database query method and device using a thread pool with priority queues and worker threads address the performance degradation in high-concurrency scenarios by optimizing thread management, reducing resource competition and context switching, and enhancing user experience.
Patent Information
- Application Number
- CN202111575938.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2041-12-21
AI Technical Summary
The default connection processing method of MySQL database, which creates an independent thread per connection, leads to high memory consumption, frequent context switching, and resource competition in high-concurrency scenarios, resulting in reduced service performance and user experience.
A MYSQL database query method and device utilizing a thread pool with multiple thread groups, each containing a priority queue and worker threads, where at most one worker thread per group has a listening status, managing query requests efficiently to reduce context switching and resource competition.
The thread pool optimizes resource utilization and reduces server jitter by allowing one thread to handle multiple connections, minimizing context switching overhead and maintaining performance in high-concurrency scenarios.
Smart Images

Figure CN114461668B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to a MYSQL database query method and device based on a thread pool. Background Art
[0002] For application services, high concurrent requests have always been an unavoidable problem. When there are a large number of concurrent requests, resources are often constantly acquired and released, which leads to low resource utilization and reduced service quality.
[0003] As one of the most widely used open source databases, MySQL database uses the default connection processing method of per-connection per-thread, that is, for each database connection, the MySQL server will create an independent thread service, and destroy the thread after the request ends. In high-concurrency scenarios, this will lead to frequent creation and release of threads. The connection processing method of per-connection per-thread requires the creation of the same number of service threads as the number of connections increases, which means higher memory consumption, more context switching operations, and more resource competition, resulting in a sharp decline in service performance, which in turn affects the user experience. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a MYSQL database query method and device based on a thread pool to overcome the problem that the connection processing method of each connection and each thread used by the MySQL database by default in the prior art sharply decreases service performance in high concurrency scenarios, affecting the user experience.
[0005] The embodiment of the present invention provides a MYSQL database query method based on a thread pool, wherein the thread pool comprises: a plurality of thread groups, each thread group comprises a priority queue for storing query requests and a plurality of worker threads, and among all the worker threads of each thread group, at most one worker thread has a listening status bit in a valid state, and the method comprises:
[0006] When the current working thread whose monitoring status bit is in a valid state in the current thread group monitors that the current thread group has a new query request, it is determined whether there is an unprocessed historical query request in the priority queue corresponding to the current thread group;
[0007] When there is no unprocessed historical query request in the priority queue corresponding to the current thread group, configuring the listening state bit of the current working thread to an invalid state;
[0008] The new query request is assigned to the current working thread for processing.
[0009] Optionally, the method further comprises:
[0010] When there is an unprocessed historical query request in the current priority queue corresponding to the current thread group, storing the new query request in the current priority queue according to a preset priority;
[0011] Create a new working thread in the current thread group or wake up a working thread in a dormant state;
[0012] The query request with the highest priority in the current priority queue is assigned to a new working thread or an awakened working thread for processing.
[0013] Optionally, the method further comprises:
[0014] When the first working thread completes processing the first query request, determining whether there is a working thread whose listening state bit is in a valid state in the first thread group corresponding to the first working thread;
[0015] When there is no working thread whose listening state bit is in a valid state in the first thread group corresponding to the first working thread, setting the listening state of the first working thread to a valid state;
[0016] When there is a working thread whose listening status bit is in a valid state in the first thread group corresponding to the first working thread, determining whether there is an unprocessed historical query request in the first priority queue of the first thread group corresponding to the first working thread;
[0017] When there are unprocessed historical query requests in the first priority queue of the first thread group corresponding to the first working thread, the query request with the highest priority is extracted from the first priority queue and allocated to the first working thread.
[0018] Optionally, when there is no unprocessed historical query request in the first priority queue of the first thread group corresponding to the first working thread, extract a new processing request from epoll;
[0019] When a new processing request is extracted from epoll, the new processing request is assigned to the first working thread for processing.
[0020] Optionally, when no new processing request is extracted from epoll, controlling the first working thread to enter a dormant state;
[0021] Monitoring the time when the first working thread enters a dormant state;
[0022] When the time that the first working thread enters the dormant state reaches a preset time, the first working thread is removed from the first thread group.
[0023] Optionally, the method further comprises:
[0024] Receiving a first query request sent by a client;
[0025] Determine whether the connection mode of the first query request is a socket connection or a super user's TCP connection;
[0026] When the connection mode of the first query request is neither a socket connection nor a super user's TCP connection;
[0027] The first query request is assigned to a thread group.
[0028] Optionally, allocating the first query request to a thread group includes:
[0029] Determining thread numbers corresponding to the first query requests according to the order in which the first query requests are received;
[0030] Based on a modulo of the thread number and the number of thread groups in the thread pool, the first query request is assigned to a thread group corresponding to a modulo result.
[0031] The embodiment of the present invention further provides a MYSQL database query device based on a thread pool, wherein the thread pool comprises: a plurality of thread groups, each thread group comprises a priority queue for storing query requests and a plurality of worker threads, and among all the worker threads of each thread group, at most only one worker thread has a listening status bit in a valid state, and the device comprises:
[0032] A first processing module is used to determine whether there is an unprocessed historical query request in the priority queue corresponding to the current thread group when the current working thread whose monitoring status bit is in a valid state in the current thread group monitors that the current thread group has a new query request;
[0033] A second processing module is used to configure the listening state bit of the current working thread to an invalid state when there is no unprocessed historical query request in the priority queue corresponding to the current thread group;
[0034] The third processing module is used to assign the new query request to the current working thread for processing.
[0035] An embodiment of the present invention further provides an electronic device, comprising: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method provided by the embodiment of the present invention by executing the computer instructions.
[0036] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method provided by the embodiment of the present invention.
[0037] The technical solution of the present invention has the following advantages:
[0038] The embodiment of the present invention provides a MYSQL database query method and device based on a thread pool. The thread pool includes: multiple thread groups, each thread group includes a priority queue for storing query requests and a plurality of working threads, and at most only one working thread among all the working threads of each thread group has a listening status bit in a valid state. The method determines whether there are unprocessed historical query requests in the priority queue corresponding to the current thread group when the current working thread whose listening status bit is in a valid state in the current thread group monitors that the current thread group has a new query request; when there are no unprocessed historical query requests in the priority queue corresponding to the current thread group, the listening status bit of the current working thread is configured to be in an invalid state; and the new query request is assigned to the current working thread for processing. Therefore, by setting the current working thread with the listening status bit in a valid state in each thread group in the thread pool, it is determined whether the priority queue is empty. If it is empty, the thread is treated as a normal working thread. Compared with each connection and each thread, the minimum processing unit in the thread pool implementation is a statement. One thread can handle requests from multiple connections. The thread pool can control the service threads of the server within a certain range, reduce resource competition and thread context switching overhead, and avoid server jitter caused by an instantaneous increase in the number of connections while making full use of hardware resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 It is a flowchart of a MYSQL database query method based on a thread pool in an embodiment of the present invention;
[0041] Figure 2 It is a schematic diagram of the specific working process of the listening thread and the ordinary working thread in the embodiment of the present invention;
[0042] Figure 3 It is a structural diagram of a MYSQL database query device based on a thread pool in an embodiment of the present invention;
[0043] Figure 4 Schematic diagram of the structure of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0045] The technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0046] For application services, high concurrent requests have always been an unavoidable problem. When there are a large number of concurrent requests, resources are often constantly acquired and released, which leads to low resource utilization and reduced service quality.
[0047] As one of the most widely used open source databases, MySQL database uses the default connection processing method of per-connection per-thread, that is, for each database connection, the MySQL server will create an independent thread service, and destroy the thread after the request ends. In high-concurrency scenarios, this will lead to frequent creation and release of threads. The connection processing method of per-connection per-thread requires the creation of the same number of service threads as the number of connections increases, which means higher memory consumption, more context switching operations, and more resource competition, resulting in a sharp decline in service performance, which in turn affects the user experience.
[0048] Based on the above problems, an embodiment of the present invention provides a MYSQL database query method based on a thread pool. The thread pool in the embodiment of the present invention includes: multiple thread groups, each thread group includes a priority queue for storing query requests and a number of worker threads, and at most one worker thread among all the worker threads of each thread group has a listening status bit in a valid state, such as Figure 1 As shown, the method specifically comprises the following steps:
[0049] Step S101: when the current working thread whose monitoring state bit is in the valid state in the current thread group monitors that the current thread group has a new query request, it is determined whether there is an unprocessed historical query request in the priority queue corresponding to the current thread group.
[0050] Among them, the query request is sent by the client when the client queries the MYSQL database. The query request can be connected to the MYSQL database in the form of TCP connection or socket connection. The query requests in the priority queue are sorted according to the priority order set in advance by the MYSQL database. The query requests are sorted according to the priority. The query requests with high priority will be processed before the query requests with low priority. The query requests with the same priority will be prioritized according to the time sequence. This is only an example, and the present invention is not limited to this. In addition, for the convenience of description, in the following embodiments of the present invention, the working thread whose listening status bit is in a valid state is called a listening thread, and the working threads whose other listening status bits are in an invalid state are called ordinary working threads.
[0051] Step S102: When there is no unprocessed historical query request in the priority queue corresponding to the current thread group, the listening state bit of the current working thread is configured to be in an invalid state.
[0052] Specifically, if the priority queue in the same thread group as the listening thread is empty, the listening thread is converted into a normal working thread.
[0053] Step S103: assigning the new query request to the current working thread for processing.
[0054] Specifically, the query request is immediately processed by the converted ordinary working thread to reduce context switching.
[0055] By executing the above steps, the MYSQL database query method based on the thread pool provided by the embodiment of the present invention determines whether the priority queue is empty by setting the current working thread with the listening status bit in a valid state in each thread group in the thread pool. If it is empty, the thread is processed as a normal working thread. Compared with each connection and each thread, the minimum processing unit in the thread pool implementation is a statement. One thread can process requests from multiple connections. The thread pool can control the service threads of the server within a certain range, reduce resource competition and thread context switching overhead, and avoid server jitter caused by an instantaneous increase in the number of connections while making full use of hardware resources.
[0056] Specifically, in one embodiment, the above method further includes the following steps:
[0057] Step S104: when there are unprocessed historical query requests in the current priority queue corresponding to the current thread group, a new query request is stored in the current priority queue according to a preset priority.
[0058] Specifically, if there is a query request in the priority queue, the priority order of the new query request is compared with the existing query requests one by one, and the new query request is inserted into the priority queue accordingly.
[0059] Step S105: Create a new working thread in the current thread group or wake up a working thread in a dormant state.
[0060] Specifically, when there are unprocessed query requests in the priority queue, it means that the number of threads in the current thread group cannot meet the needs of the query requests. Therefore, the query request processing capability of the current thread group is improved by creating a new working thread or waking up a dormant working thread to improve the user experience.
[0061] Step S106: Allocate the query request with the highest priority in the current priority queue to a new working thread or an awakened working thread for processing.
[0062] Specifically, in one embodiment, the above method further includes the following steps:
[0063] Step S201: when the first working thread completes processing the first query request, it is determined whether there is a working thread whose listening state bit is in a valid state in the first thread group corresponding to the first working thread.
[0064] The first working thread is a common working thread. After it processes the query request, that is, returns the corresponding query data to the user, it will automatically traverse whether there is a listening thread in the same thread group.
[0065] Step S202: When there is no working thread whose listening state bit is set to a valid state in the first thread group corresponding to the first working thread, the listening state of the first working thread is set to a valid state.
[0066] Specifically, if there is no listening thread, the common working thread that has processed the query task is converted into a listening thread, and the above step S101 is returned to continue execution, thereby ensuring that the thread group retains as many listening threads as possible, so as to further reduce the overhead of thread context switching.
[0067] Step S203: when there is a working thread whose monitoring status bit is in a valid state in the first thread group corresponding to the first working thread, it is determined whether there is an unprocessed historical query request in the first priority queue of the first thread group corresponding to the first working thread;
[0068] Specifically, if a listening thread already exists, the working thread continues to be used as a normal working thread, and it is determined whether there is an unprocessed query request in the priority queue. If so, step S204 is executed, otherwise, step S205 is executed.
[0069] Step S204: when there are unprocessed historical query requests in the first priority queue of the first thread group corresponding to the first working thread, extract the query request with the highest priority from the first priority queue and assign it to the first working thread.
[0070] Step S205: When there are no unprocessed historical query requests in the first priority queue of the first thread group corresponding to the first working thread, extract a new processing request from epoll. When a new processing request is extracted from epoll, the new processing request is assigned to the first working thread for processing. When no new processing request is extracted from epoll, control the first working thread to enter a dormant state; monitor the time when the first working thread enters a dormant state; when the time when the first working thread enters a dormant state reaches a preset time, remove the first working thread from the first thread group.
[0071] Thus, the hardware resource overhead can be further reduced by putting redundant threads in the control thread group into a dormant state and by promptly removing dormant worker threads that have not processed query requests for a long time.
[0072] Specifically, before executing the above step S101, the above method further includes the following steps:
[0073] Step S301: receiving a first query request sent by a client;
[0074] Step S302: determine whether the connection mode of the first query request is a socket connection or a super user's TCP connection; when the connection mode of the first query request is neither a socket connection nor a super user's TCP connection; assign the first query request to a thread group.
[0075] Specifically, the thread number corresponding to the first query request is determined according to the order in which the first query request is received; based on the modulus of the thread number and the number of thread groups in the thread pool, the first query request is allocated to the thread group corresponding to the modulus result.
[0076] MySQL database connection methods include TCP connection and socket connection, which are query request connection methods. Usually, users for monitoring and management use socket connection or TCP connection of super users, and other services use TCP connection of general users. Based on this business scenario, a method for distinguishing database business traffic and management traffic and managing them independently is provided. After the connection request enters the database server, the connection is divided into two categories, using socket connection or TCP connection of super users, and TCP connection of general users. The two types of connections enter different processing logics. Generally, for monitoring or management traffic, there are fewer user connections and most of them are short connections, which are released after the query is completed. Therefore, this type of connection adopts the traditional MySQL database query processing mode of connection per thread per connection, which will not be described here. For TCP connections of general users, that is, business-related traffic, the number of concurrent connections is usually high, so the thread pool mode is adopted to avoid the problem of sudden drop in database performance in high concurrency and high connection scenarios.
[0077] The specific implementation process of the MYSQL database query method based on the thread pool provided by the embodiment of the present invention will be described in detail below in conjunction with a specific application example.
[0078] The thread pool consists of a timer thread and multiple thread groups. Each group contains two priority queues, a listening thread, and several worker threads. The number of worker threads is determined by the workload. The timer thread periodically checks whether the group is blocked. If the group has not processed requests in the recent period and there are requests in the queue, it means that the group is blocked. The timer thread solves the blocking problem by waking up the thread or creating a new thread. The specific working process of the thread pool is as follows:
[0079] 1) When a connection to MySQL is requested, a connection object is created, a corresponding thread id number is assigned, and the id number is used to determine the current thread assignment group modulo the number of groups. Assuming that the current group has 5 threads, the corresponding numbers are from 1 to 5, and the id number corresponding to the current request is 3, the request is assigned to thread 3.
[0080] 2) If Figure 2 As shown in the figure, after the listening thread monitors a new request in its group through epoll, it checks whether the priority queue is empty, that is, whether there are unprocessed requests. If so, the corresponding request is put into the queue and other threads are created or awakened to process the request. If not, the listening thread will immediately process the request as a normal working thread to reduce context switching.
[0081] 3) If Figure 2As shown, the ordinary worker thread is responsible for taking out the request from the priority queue for processing. If it is not taken, it tries to take it from epoll. If not, it goes into sleep. If it is not awakened at the specified time, it will automatically exit and end the current thread.
[0082] 4) The timer thread periodically checks whether the group is blocked. If so, it wakes up or creates a new worker thread.
[0083] The technical solution proposed by the present invention solves the problem of sudden performance degradation of MySQL database in high-concurrency scenarios, and solves the problems of frequent context switching and severe resource competition through thread pool technology. In addition, connection management is used to distinguish management traffic from business traffic. Even if the number of connections is fully occupied by business traffic, the monitoring user can log in to the database through the corresponding management port to query the database status information and return to the console, so that the console can promptly notify the operation and maintenance personnel through the alarm interface to solve the problem, so as not to affect the use and cause losses to users.
[0084] By executing the above steps, the MYSQL database query method based on the thread pool provided by the embodiment of the present invention determines whether the priority queue is empty by setting the current working thread with the listening status bit in a valid state in each thread group in the thread pool. If it is empty, the thread is processed as a normal working thread. Compared with each connection and each thread, the minimum processing unit in the thread pool implementation is a statement. One thread can process requests from multiple connections. The thread pool can control the service threads of the server within a certain range, reduce resource competition and thread context switching overhead, and avoid server jitter caused by an instantaneous increase in the number of connections while making full use of hardware resources.
[0085] The embodiment of the present invention also provides a MYSQL database query device based on a thread pool, wherein the thread pool includes: a plurality of thread groups, each thread group includes a priority queue for storing query requests and a plurality of worker threads, and among all the worker threads of each thread group, at most only one worker thread has a listening status bit in a valid state, such as Figure 3 As shown, the MYSQL database query device based on thread pool includes:
[0086] The first processing module is used to determine whether there is an unprocessed historical query request in the priority queue corresponding to the current thread group when the current working thread whose monitoring status bit is in a valid state in the current thread group monitors a new query request from the current thread group. For details, please refer to the relevant description of step S101 in the above method embodiment, which will not be repeated here.
[0087] The second processing module 102 is used to configure the listening state bit of the current working thread to an invalid state when there is no unprocessed historical query request in the priority queue corresponding to the current thread group. For details, please refer to the relevant description of step S102 in the above method embodiment, which will not be repeated here.
[0088] The third processing module 103 is used to assign the new query request to the current working thread for processing. For details, please refer to the relevant description of step S103 in the above method embodiment, which will not be repeated here.
[0089] Through the coordinated cooperation of the above-mentioned components, the MYSQL database query device based on the thread pool provided by the embodiment of the present invention determines whether the priority queue is empty by setting the current working thread with the listening status bit in a valid state in each thread group in the thread pool. If it is empty, the thread is processed as a normal working thread. Compared with each connection and each thread, the minimum processing unit in the thread pool implementation is a statement. One thread can process requests from multiple connections. The thread pool can control the service threads of the server within a certain range, reduce resource competition and the overhead of thread context switching, and avoid server jitter caused by an instantaneous increase in the number of connections while making full use of hardware resources.
[0090] The further functional description of each of the above modules is the same as that of the above corresponding method embodiments and will not be repeated here.
[0091] According to an embodiment of the present invention, there is also provided an electronic device, such as Figure 4 As shown, the electronic device may include a processor 901 and a memory 902, wherein the processor 901 and the memory 902 may be connected via a bus or other means. Figure 4 The example of connecting through bus is taken in the following.
[0092] The processor 901 may be a central processing unit (CPU). The processor 901 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0093] The memory 902 is a non-transitory computer-readable storage medium that can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the methods in the method embodiments of the present invention. The processor 901 executes various functional applications and data processing of the processor by running the non-transitory software programs, instructions and modules stored in the memory 902, that is, implementing the methods in the above method embodiments.
[0094] The memory 902 may include a program storage area and a data storage area, wherein the program storage area may store an application required for operating the device and at least one function; the data storage area may store data created by the processor 901, etc. In addition, the memory 902 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 902 may optionally include a memory remotely arranged relative to the processor 901, and these remote memories may be connected to the processor 901 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0095] One or more modules are stored in the memory 902 , and when executed by the processor 901 , the method in the above method embodiment is executed.
[0096] The specific details of the above electronic device can be understood by referring to the corresponding descriptions and effects in the above method embodiments, and will not be repeated here.
[0097] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the implemented program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.
[0098] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A MYSQL database query method based on thread pool, characterized in that: The thread pool includes: a plurality of thread groups, each thread group includes a priority queue for storing query requests and a plurality of worker threads, and at most one worker thread among all worker threads of each thread group has a listening state bit in a valid state, and the method includes: When the current working thread whose monitoring status bit is in a valid state in the current thread group monitors that the current thread group has a new query request, it is determined whether there is an unprocessed historical query request in the priority queue corresponding to the current thread group; When there is no unprocessed historical query request in the priority queue corresponding to the current thread group, configuring the listening state bit of the current working thread to an invalid state; Assigning a new query request to the current working thread for processing; When the first working thread completes processing the first query request, determining whether there is a working thread whose listening state bit is in a valid state in the first thread group corresponding to the first working thread; When there is no working thread whose listening state bit is in a valid state in the first thread group corresponding to the first working thread, the listening state of the first working thread is set to a valid state.
2. The method according to claim 1, characterized in that Also includes: When there is an unprocessed historical query request in the current priority queue corresponding to the current thread group, storing the new query request in the current priority queue according to the preset priority; Create a new working thread in the current thread group or wake up a working thread in a dormant state; The query request with the highest priority in the current priority queue is assigned to a new working thread or an awakened working thread for processing.
3. The method according to claim 1, characterized in that: Also includes: When there is a working thread whose listening status bit is in a valid state in the first thread group corresponding to the first working thread, determining whether there is an unprocessed historical query request in the first priority queue of the first thread group corresponding to the first working thread; When there are unprocessed historical query requests in the first priority queue of the first thread group corresponding to the first working thread, the query request with the highest priority is extracted from the first priority queue and allocated to the first working thread.
4. The method according to claim 3, characterized in that When there is no unprocessed historical query request in the first priority queue of the first thread group corresponding to the first working thread, extract a new processing request from epoll; When a new processing request is extracted from epoll, the new processing request is assigned to the first working thread for processing.
5. The method according to claim 4, characterized in that When no new processing request is extracted from epoll, controlling the first working thread to enter a dormant state; Monitoring the time when the first working thread enters a dormant state; When the time that the first working thread enters the dormant state reaches a preset time, the first working thread is removed from the first thread group.
6. The method according to claim 1, characterized in that Also includes: Receiving a first query request sent by a client; Determine whether the connection mode of the first query request is a socket connection or a super user's TCP connection; When the connection mode of the first query request is neither a socket connection nor a super user's TCP connection; The first query request is assigned to a thread group.
7. The method according to claim 6, characterized in that The allocating the first query request to the thread group includes: Determining thread numbers corresponding to the first query requests according to the order in which the first query requests are received; Based on a modulo of the thread number and the number of thread groups in the thread pool, the first query request is assigned to a thread group corresponding to a modulo result.
8. A MYSQL database query device based on thread pool, characterized in that: The thread pool includes: a plurality of thread groups, each thread group includes a priority queue for storing query requests and a plurality of working threads, and at most one working thread among all working threads of each thread group has a listening state bit in a valid state, and the device includes: A first processing module is used to determine whether there is an unprocessed historical query request in the priority queue corresponding to the current thread group when the current working thread whose monitoring status bit is in a valid state in the current thread group monitors that the current thread group has a new query request; A second processing module is used to configure the listening state bit of the current working thread to an invalid state when there is no unprocessed historical query request in the priority queue corresponding to the current thread group; The third processing module is used to assign the new query request to the current working thread for processing; when the first working thread completes processing the first query request, determine whether there is a working thread whose listening status bit is in a valid state in the first thread group corresponding to the first working thread; when there is no working thread whose listening status bit is in a valid state in the first thread group corresponding to the first working thread, set the listening status of the first working thread to a valid state.
9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method according to any one of claims 1 to 7.
