CN115080247B - High-availability thread pool switching method and device - Google Patents

High-availability thread pool switching method and device Download PDF

Info

Publication number
CN115080247B
CN115080247B CN202210972026.7A CN202210972026A CN115080247B CN 115080247 B CN115080247 B CN 115080247B CN 202210972026 A CN202210972026 A CN 202210972026A CN 115080247 B CN115080247 B CN 115080247B
Authority
CN
China
Prior art keywords
thread pool
main thread
task
state
dirty
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210972026.7A
Other languages
Chinese (zh)
Other versions
CN115080247A (en
Inventor
童跃
张学亮
唐华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Kelai Network Technology Co ltd
Original Assignee
Kelai Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Kelai Network Technology Co ltd filed Critical Kelai Network Technology Co ltd
Priority to CN202210972026.7A priority Critical patent/CN115080247B/en
Publication of CN115080247A publication Critical patent/CN115080247A/en
Application granted granted Critical
Publication of CN115080247B publication Critical patent/CN115080247B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5011Pool
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Hardware Redundancy (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses a method and a device for switching a high-availability thread pool, wherein the method comprises the following steps: acquiring a main thread pool from a dynamic thread pool factory, and detecting the state of the main thread pool; according to the state of the main thread pool, switching to a different thread pool to execute a newly received task, wherein the task comprises the following steps: when the state of the main thread pool is in a determined blocking state, switching from the main thread pool to a standby thread pool to provide service for a newly received task, simultaneously starting a dirty task identification mechanism of the main thread pool to identify the dirty task, and placing the identified dirty task in a dirty task resource limited thread pool to execute; starting a timing task after the dirty task identification is completed; and detecting the latest state of the main thread pool according to the timing task, and if the latest state of the main thread pool is the recovery completion state, switching the standby thread pool to the original main thread pool to provide service for the newly received task. The method and the device can solve the problem that when a plurality of tasks share one thread pool, a certain task is time-consuming and delayed, so that the whole task is stuck.

Description

High-availability thread pool switching method and device
Technical Field
The invention relates to the technical field of data transmission and thread pool switching, in particular to a method and a device for switching a high-availability thread pool.
Background
The existing thread pool switching method mainly comprises two types: the first method generally focuses on identifying the change of the environment, dynamically sets the parameters of the thread pool, increases the parameters to adapt to a large task amount, and decreases the parameters to save resources, and the related patents of the existing thread pool are as follows: "CN202110343860.5 thread pool adjusting method, device, storage medium and electronic device", "CN201810990940.8 thread pool optimizing method and system", and "CN202110838179.8 method, system and device for dynamically setting thread pool parameters".
The second method presets a priority mode, sets priority for tasks, and responds to the tasks with high priority preferentially, and the prior related patents are as follows: CN201510162291.9 a thread pool sharing method and system based on semaphore and CN201810935659.4 a java thread pool hierarchical processing method and device.
However, the above two methods do not solve the problems encountered in the current system in the following scenarios: when a certain multitask running thread pool receives and processes tasks at fixed time, because a certain task consumes a long time, the thread pool resources are all occupied by the task in the long term, and other tasks cannot respond in time. But since all these tasks cannot be prioritized in advance and are not themselves prioritized. Therefore, when the above scenario is met, a time-consuming delay of a certain task occurs, thereby causing a problem of overall stuck.
Disclosure of Invention
The invention aims to provide a method and a device for switching a high-availability thread pool, which can solve the problem that when a plurality of tasks share one thread pool, a certain task is delayed in time consumption, so that the whole thread pool is blocked. The invention enables the average response time of all tasks to reach the lowest, and can automatically identify the tasks with problems, thereby reducing manual intervention; meanwhile, the manual modification of the thread pool parameters is avoided; therefore, the stable operation of the service system is ensured, the failure rate is reduced, and the high availability is realized.
The invention is realized by the following technical scheme:
in a first aspect, the present invention provides a method for switching a highly available thread pool, where the method includes:
acquiring a main thread pool from a dynamic thread pool factory, and detecting the state of the main thread pool;
according to the state of the main thread pool, switching to a different thread pool to execute a newly received task, wherein the process comprises the following steps:
when the state of the main thread pool is a determined blocking state, switching from the main thread pool to a standby thread pool to provide service for a newly received task (at this time, the main thread pool does not provide service for the newly received task any more, and is only responsible for providing service for the originally received task, but the standby thread pool provides service for the newly received task), and simultaneously, starting a main thread pool dirty task identification mechanism to identify dirty tasks, and placing the identified dirty tasks in a dirty task resource limited thread pool for execution;
when the dirty task identification is completed, starting a timing task; and detecting the latest state of the main thread pool according to the timing task, and if the latest state of the main thread pool is a recovery completion state, switching the standby thread pool to the original main thread pool to provide service for the newly received task.
The working principle is as follows: in order to avoid excessive resource occupation, the similar tasks are placed in a thread pool, and the scheme mainly solves the problem that when a plurality of tasks share one thread pool, a certain task consumes time and delays, so that the whole block is caused. According to the invention, a High Availability HA (High Availability) thought in a distributed system is referred, each thread pool is also configured with a standby thread pool, and according to the state of a main thread pool, the thread pool is switched to different thread pools to execute newly received tasks; when the fact that the main thread pool starts to queue and the queue ratio reaches a preset value is detected, namely the state of the main thread pool is in a determined blocking state, the main thread pool is switched to a standby thread pool to provide service for a newly received task, meanwhile, a main thread pool dirty task identification mechanism is started to carry out dirty task identification, and the identified dirty task is placed in a dirty task resource limited thread pool to be executed; starting a timing task after the dirty task identification is completed; and detecting the latest state of the main thread pool according to the timing task, and if the latest state of the main thread pool returns to normal (no longer queues), switching the standby thread pool to the original main thread pool to provide service for the newly received task.
The method is suitable for ensuring the stable transmission of the data, and is particularly suitable for scenes involving the transmission of a large amount of data between two systems. For example, the method is applied to stable data transmission between a performance management system and a network traffic analysis auditing system.
Further, the method further comprises initializing a dynamic thread pool factory, specifically:
setting a dynamic thread pool factory, wherein the thread pool acquisition must pass through a uniform scheduling inlet; the dynamic thread pool factory is a multi-task shared thread pool;
initializing a standby thread pool and initializing a dirty task resource limited thread pool;
the state of the built-in main thread pool is a normal state.
Further, the states of the main thread pool include a normal state, a suspected blocking state, a determined blocking state, a recovering state and a recovering completion state.
Further, the judgment basis of the state of the main thread pool is as follows:
if the size of a blocking block in the main thread pool is 0 or the proportion of the used blocking blocks in the total capacity of a blocking queue does not exceed a first preset value (such as 40%), the main thread pool is in a normal state;
if the size of a blocking block in the main thread pool is not 0 and the proportion of the used blocking blocks in the total capacity of a blocking queue exceeds a first preset value (such as 40%), the main thread pool is busy, and the state of the main thread pool is set to be a suspected blocking state;
recording the suspected blocking state of the main thread pool and recording the accumulated busy times when the main thread pool is obtained every time; when the accumulated busy times reach a second preset value, setting the state of the main thread pool as a determined blocking state;
after the blocking state is determined, a dirty task identification mechanism of a main thread pool is started to identify dirty tasks, and the names of the tasks causing the blocking are found and recorded; after the dirty task identification is completed, starting a timing task, and setting the state of the main thread pool as a recovery state if the main thread pool is in recovery; and setting the state of the main thread pool as a recovery completion state until recovery is completed.
Further, the dirty task refers to the most dominant and time-consuming task in the main thread pool.
Further, the step of identifying the dirty task identification mechanism of the main thread pool comprises the following steps:
recording the execution duration of each task in the main thread pool according to the obtained main thread pool;
acquiring a stack in the main thread pool according to the execution duration of each task, and analyzing a plurality of first tasks (such as the first five tasks Top 5) which occupy the most and a plurality of first tasks (such as the first five tasks Top 5) which consume the longest time in the stack;
and taking an intersection of the first tasks occupying the most proportion in the stack and the first tasks consuming the longest time in the stack, and selecting the first task occupying the most proportion and consuming the most time from the intersection as a dirty task.
Furthermore, each main thread pool is provided with a standby thread pool, and the standby thread pools are newly built when used and are recycled when used up.
Furthermore, the main thread pool allocates the most resources to perform task execution, and the dirty task resource limited thread pool allocates the least resources to perform task execution.
According to the technical scheme, after a dirty task in a main thread pool is identified through a main thread pool dirty task identification mechanism, the identified dirty task is placed in a dirty task resource limited thread pool to be executed, and relatively few resources are allocated in the dirty task resource limited thread pool to execute the dirty task; meanwhile, the main thread pool which is switched from the main thread pool to the standby thread pool is only responsible for providing service for the originally received task because the main thread pool does not receive new tasks any more, and at the moment, relatively more resources are allocated in the main thread pool to execute the originally received task.
Further, the switching to a different thread pool to execute the newly received task according to the state of the main thread pool further includes:
when the state of the main thread pool is a normal state, returning to the original main thread pool to provide service for the newly received task;
when the state of the main thread pool is a suspected blocking state, returning to the original main thread pool to provide service for the newly received task;
and when the state of the main thread pool is the recovery state, returning to the standby thread pool to provide service for the newly received task.
In a second aspect, the present invention further provides a device for switching a high-availability thread pool, which supports the method for switching a high-availability thread pool; the device includes:
the main thread pool obtaining unit is used for obtaining a main thread pool from a dynamic thread pool factory;
a detection state unit for detecting the state of the main thread pool obtained from the dynamic thread pool factory;
and the thread pool switching unit is used for switching to different thread pools to execute the newly received tasks according to the state of the main thread pool.
Compared with the prior art, the invention has the following advantages and beneficial effects:
the invention relates to a method and a device for switching high-availability thread pools, which refer to the idea of high-availability HA in a distributed system, configure a standby thread pool for each thread pool, and switch to different thread pools to execute newly received tasks according to the state of a main thread pool; when the fact that the main thread pool starts to queue and the queue ratio reaches a preset value is detected, namely the state of the main thread pool is in a determined blocking state, the main thread pool is switched to a standby thread pool to provide service for a newly received task, meanwhile, a main thread pool dirty task identification mechanism is started to carry out dirty task identification, and the identified dirty task is placed in a dirty task resource limited thread pool to be executed; starting a timing task after the dirty task identification is completed; and detecting the latest state of the main thread pool according to the timing task, and if the latest state of the main thread pool returns to normal (namely no queuing is performed), switching the standby thread pool to the original main thread pool to provide service for the newly received task. The method and the device can solve the problem that when a plurality of tasks share one thread pool, a certain task is time-consuming and delayed, so that the whole task is stuck. The invention enables the average response time of all tasks to reach the lowest, and can automatically identify the tasks with problems, thereby reducing manual intervention; meanwhile, the manual modification of the thread pool parameters is avoided; therefore, the stable operation of the service system is ensured, the high availability is realized, and the failure rate is reduced.
Drawings
The accompanying drawings, which are included to provide a further understanding of the embodiments of the invention and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the invention and together with the description serve to explain the principles of the invention. In the drawings:
FIG. 1 is a flow chart of a method for switching a highly available thread pool according to the present invention.
FIG. 2 is a schematic diagram of a high availability thread pool switching apparatus according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to examples and accompanying drawings, and the exemplary embodiments and descriptions thereof are only used for explaining the present invention and are not meant to limit the present invention.
Example 1
In order to avoid excessive resource occupation, the similar tasks are placed in a thread pool, and the scheme mainly solves the problem that when a plurality of tasks share one thread pool, a certain task consumes time and delays, so that the whole block is caused. According to the invention, a High Availability HA (High Availability) thought in a distributed system is referred, each thread pool is also configured with a standby thread pool, and according to the state of a main thread pool, the thread pool is switched to different thread pools to execute newly received tasks; when it is detected that the main thread pool starts to queue and the queuing ratio reaches a preset value, namely the state of the main thread pool is a determined blocking state, switching from the main thread pool to a standby thread pool to provide service for a newly received task, simultaneously starting a dirty task identification mechanism of the main thread pool to identify a dirty task, and placing the identified dirty task in a dirty task resource limited thread pool to execute; starting a timing task after the dirty task identification is completed; and detecting the latest state of the main thread pool according to the timing task, and if the latest state of the main thread pool returns to normal (namely no queuing is carried out), switching the standby thread pool to the original main thread pool to provide service for the newly received task.
As shown in fig. 1, a method for switching a high-availability thread pool according to the present invention includes:
initializing a dynamic thread pool factory;
acquiring a main thread pool from a dynamic thread pool factory, and detecting the state of the main thread pool;
according to the state of the main thread pool, switching to a different thread pool to execute a newly received task, wherein the process comprises the following steps:
when the state of the main thread pool is a determined blocking state, switching from the main thread pool to a standby thread pool to provide service for a newly received task (at this time, the main thread pool does not provide service for the newly received task any more, and is only responsible for providing service for the originally received task, but the standby thread pool provides service for the newly received task), and simultaneously, starting a main thread pool dirty task identification mechanism to identify dirty tasks, and placing the identified dirty tasks in a dirty task resource limited thread pool for execution;
when the dirty task identification is completed, starting a timing task; detecting the latest state of the main thread pool according to the timing task, and if the latest state of the main thread pool is a recovery completion state, switching the standby thread pool to the original main thread pool to provide service for a newly received task;
when the state of the main thread pool is a normal state, returning to the original main thread pool to provide service for the newly received task;
when the state of the main thread pool is a suspected blocking state, returning to the original main thread pool to provide service for the newly received task;
and when the state of the main thread pool is the recovery state, returning to the standby thread pool to provide service for the newly received task.
And each main thread pool is provided with a standby thread pool, the standby thread pools are newly built when used, and the standby thread pools are recovered when used up.
As a further implementation, the initialization of the dynamic thread pool factory includes:
s11: setting a dynamic thread pool factory, wherein the thread pool acquisition must pass through a uniform scheduling inlet; the dynamic thread pool factory is a multi-task shared thread pool;
s12: when a thread pool is obtained, a current task name lambda is simultaneously transmitted;
s13: initializing a standby thread pool;
s14: initializing a dirty task resource limited thread pool;
s15: the state of the built-in main thread pool is a normal state.
The S31 "dynamic thread pool factory" is a concept in a design mode, that is, an original program can be directly taken to the thread pool a, but is now packaged by the "factory" to provide a in a unified manner.
In further implementations, the states of the main thread pool include a normal state, a suspected blocking state, a confirmed blocking state, a recovering state, and a recovering completion state. Specifically, the judgment basis of the state of the main thread pool is as follows:
if the size of a blocking block in the main thread pool is 0 or the proportion of the used blocking blocks in the total capacity of a blocking queue does not exceed a first preset value (such as 40%), the main thread pool is in a normal state;
if the size of a blocking block in the main thread pool is not 0 and the proportion of the used blocking blocks in the total capacity of a blocking queue exceeds a first preset value (such as 40%), the main thread pool is busy, and the state of the main thread pool is set to be a suspected blocking state;
recording the suspected blocking state of the main thread pool and recording the accumulated busy times when the main thread pool is obtained every time; when the accumulated busy times reach a second preset value, setting the state of the main thread pool as a determined blocking state;
after the blocking state is determined, starting a dirty task identification mechanism of the main thread pool to identify dirty tasks, finding out the names of the tasks causing the blocking, and recording the names into C; after the dirty task identification is completed, starting a timing task, and setting the state of the main thread pool as a recovery state if the main thread pool is in recovery; and setting the state of the main thread pool as a recovery completion state until recovery is completed.
As a further implementation, the dirty task refers to the most prevalent and time-consuming task in the main thread pool. Specifically, the identification step of the dirty task identification mechanism of the main thread pool is as follows:
recording the execution duration of each task in the main thread pool according to the obtained main thread pool;
acquiring a stack in the main thread pool according to the execution duration of each task, and analyzing a plurality of first tasks (such as the first five tasks Top 5) which occupy the most and a plurality of first tasks (such as the first five tasks Top 5) which consume the longest time in the stack;
and taking an intersection of the first tasks occupying the most proportion in the stack and the first tasks consuming the longest time in the stack, and selecting the first task occupying the most proportion and consuming the most time from the intersection as a dirty task.
The dirty task identification mechanism of the main thread pool can adopt other modes except the mode of high task occupation ratio, high task time consumption and the like.
In a further implementation, the main thread pool allocates the most resources for task execution, and the dirty task resource restricted thread pool allocates the least resources for task execution.
According to the technical scheme, after a dirty task in a main thread pool is identified through a main thread pool dirty task identification mechanism, the identified dirty task is placed in a dirty task resource limited thread pool to be executed, and relatively few resources are allocated in the dirty task resource limited thread pool to execute the dirty task; meanwhile, the main thread pool which is switched from the main thread pool to the standby thread pool is only responsible for providing service for the originally received task because the main thread pool does not receive a new task any more, and at the moment, relatively more resources are allocated in the main thread pool to execute the originally received task.
For example, after a dirty task in the main thread pool is identified by the main thread pool dirty task identification mechanism, the identified dirty task is placed in the dirty task resource restricted thread pool to be executed, and at this time, 2 resources are allocated in the dirty task resource restricted thread pool to execute the dirty task; at this time, 50 resources are allocated in the main thread pool to perform the task that was originally received (and 20 resources are allocated in the initial main thread pool to perform the task).
According to the steps, the invention can achieve the disaster tolerance of the tasks, and other tasks can normally acquire the resource execution even if one task is infinitely blocked, thereby ensuring the maximization of the overall benefit.
The application scenario of the invention is as follows: the method is suitable for a scene involving mass data transmission between two systems. For example, data is stably transmitted between the performance management system and the network traffic analysis auditing system. Depending on the service, many command formats are defined for transmission, and these commands are processed by a common thread pool. This can easily occur in a lossy situation, where a task code logic is faulty or otherwise blocked, causing other functions to be taken out of service. This is not simply solved by capacity expansion and must be able to dynamically identify dirty tasks and do post-event resource isolation.
Therefore, the invention designs a high-availability thread pool switching method based on the problems of the scenes. The method and the device can solve the problem that when a plurality of tasks share one thread pool, a certain task is time-consuming and delayed, so that the whole task is stuck. The invention enables the average response time of all tasks to reach the lowest, and can automatically identify the tasks with problems, thereby reducing manual intervention; meanwhile, the manual modification of the thread pool parameters is avoided; therefore, the stable operation of the service system is ensured, the high availability is realized, and the failure rate is reduced. The method is suitable for guaranteeing stable data transmission, and is particularly applied to stable data transmission between a performance management system and a network flow analysis and audit system.
Example 2
As shown in fig. 2, the difference between this embodiment and embodiment 1 is that this embodiment provides a high-available thread pool switching device, which supports the high-available thread pool switching method described in embodiment 1; the device includes:
the main thread pool obtaining unit is used for obtaining a main thread pool from a dynamic thread pool factory;
a detection state unit for detecting the state of the main thread pool obtained from the dynamic thread pool factory; the state of the main thread pool comprises a normal state, a suspected blocking state, a determined blocking state, a recovering state and a recovering completion state;
a thread pool switching unit, configured to switch to a different thread pool to execute a newly received task according to the state of the main thread pool, including:
when the state of the main thread pool is a determined blocking state, switching from the main thread pool to a standby thread pool to provide service for a newly received task (at this time, the main thread pool does not provide service for the newly received task any more, and is only responsible for providing service for the originally received task, but the standby thread pool provides service for the newly received task), and simultaneously, starting a main thread pool dirty task identification mechanism to identify dirty tasks, and placing the identified dirty tasks in a dirty task resource limited thread pool for execution;
when the dirty task identification is completed, starting a timing task; and detecting the latest state of the main thread pool according to the timing task, and if the latest state of the main thread pool is a recovery completion state, switching the standby thread pool to the original main thread pool to provide service for the newly received task.
The execution process of each unit may be executed according to the flow steps of the high-availability thread pool switching method described in embodiment 1, and details in this embodiment are not repeated.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (7)

1. A method for switching a high-availability thread pool is characterized by comprising the following steps:
acquiring a main thread pool from a dynamic thread pool factory, and detecting the state of the main thread pool;
according to the state of the main thread pool, switching to a different thread pool to execute a newly received task, wherein the process comprises the following steps:
when the state of the main thread pool is in a determined blocking state, switching from the main thread pool to a standby thread pool to provide service for a newly received task, simultaneously starting a dirty task identification mechanism of the main thread pool to identify the dirty task, and placing the identified dirty task in a dirty task resource limited thread pool to execute;
starting a timing task after the dirty task identification is completed; detecting the latest state of the main thread pool according to the timing task, and if the latest state of the main thread pool is a recovery completion state, switching the standby thread pool to the original main thread pool to provide service for a newly received task;
the state of the main thread pool comprises a normal state, a suspected blocking state, a determined blocking state, a recovering state and a recovering completion state;
the judgment basis of the state of the main thread pool is as follows:
if the size of a blocking block in the main thread pool is 0 or the proportion of the used blocking blocks in the total capacity of a blocking queue does not exceed a first preset value, the main thread pool is in a normal state;
if the size of a blocking block in the main thread pool is not 0 and the occupation ratio of the used blocking block in the total capacity of a blocking queue exceeds a first preset value, the main thread pool is busy, and the state of the main thread pool is set to be a suspected blocking state;
recording the suspected blocking state of the main thread pool and recording the accumulated busy times when the main thread pool is obtained every time; when the accumulated busy times reach a second preset value, setting the state of the main thread pool as a determined blocking state;
starting a main thread pool dirty task identification mechanism to identify dirty tasks after determining a blocking state, starting a timing task after the dirty task identification is finished, and setting the main thread pool state as a recovery state when the main thread pool is in recovery; setting the state of the main thread pool as a recovery completion state until recovery is completed;
the dirty tasks refer to the most frequent and time-consuming tasks in the main thread pool.
2. The method according to claim 1, further comprising initializing a dynamic thread pool factory, specifically:
setting a dynamic thread pool factory, wherein the thread pool acquisition must pass through a uniform scheduling inlet; the dynamic thread pool factory is a multi-task shared thread pool;
initializing a standby thread pool and initializing a dirty task resource limited thread pool;
the state of the built-in main thread pool is a normal state.
3. The method according to claim 1, wherein the step of identifying the dirty task identification mechanism of the main thread pool comprises:
recording the execution duration of each task in the main thread pool according to the obtained main thread pool;
acquiring a stack in the main thread pool according to the execution duration of each task, and analyzing a plurality of first tasks which occupy the most in the stack and a plurality of first tasks which consume the longest time in the stack;
and taking an intersection of the first tasks which occupy the most in the stack and the first tasks which consume the longest time in the stack, and selecting the first task which occupies the most in the intersection and consumes the most time as a dirty task.
4. The method according to claim 1, wherein each of the main thread pools is configured with a standby thread pool, and the standby thread pool is newly built when it is used and is recycled when it is used up.
5. The method according to claim 1, wherein the main thread pool allocates the most resources for task execution, and the dirty task resource restricted thread pool allocates the least resources for task execution.
6. The method according to claim 1, wherein switching to a different thread pool to execute a newly received task according to the status of the main thread pool further comprises:
when the state of the main thread pool is a normal state, returning to the original main thread pool to provide service for the newly received task;
when the state of the main thread pool is a suspected blocking state, returning to the original main thread pool to provide service for the newly received task;
and when the state of the main thread pool is the recovery state, returning to the standby thread pool to provide service for the newly received task.
7. A highly available thread pool switching apparatus, wherein the apparatus supports a highly available thread pool switching method according to any one of claims 1 to 6; the device includes:
the main thread pool obtaining unit is used for obtaining a main thread pool from a dynamic thread pool factory;
a detection state unit for detecting the state of the main thread pool obtained from the dynamic thread pool factory;
and the thread pool switching unit is used for switching to different thread pools to execute the newly received tasks according to the state of the main thread pool.
CN202210972026.7A 2022-08-15 2022-08-15 High-availability thread pool switching method and device Active CN115080247B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210972026.7A CN115080247B (en) 2022-08-15 2022-08-15 High-availability thread pool switching method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210972026.7A CN115080247B (en) 2022-08-15 2022-08-15 High-availability thread pool switching method and device

Publications (2)

Publication Number Publication Date
CN115080247A CN115080247A (en) 2022-09-20
CN115080247B true CN115080247B (en) 2022-11-04

Family

ID=83243966

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210972026.7A Active CN115080247B (en) 2022-08-15 2022-08-15 High-availability thread pool switching method and device

Country Status (1)

Country Link
CN (1) CN115080247B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106980546A (en) * 2016-01-18 2017-07-25 阿里巴巴集团控股有限公司 A kind of task asynchronous execution method, apparatus and system
CN114579323A (en) * 2022-03-09 2022-06-03 上海达梦数据库有限公司 Thread processing method, device, equipment and medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9201689B2 (en) * 2011-04-22 2015-12-01 Cray Inc. Software emulation of massive hardware threading for tolerating remote memory references
CN103218264A (en) * 2013-03-26 2013-07-24 广东威创视讯科技股份有限公司 Multi-thread finite state machine switching method and multi-thread finite state machine switching device based on thread pool
CN103997544B (en) * 2014-06-12 2017-08-25 网易(杭州)网络有限公司 A kind of method and apparatus of resource downloading
CN105893126B (en) * 2016-03-29 2019-06-11 华为技术有限公司 A kind of method for scheduling task and device
CN110188016B (en) * 2019-05-24 2022-11-01 山东多科科技有限公司 Method, terminal and storage medium for detecting application program no-response blocking
CN111444012B (en) * 2020-03-03 2023-05-30 中国科学院计算技术研究所 Dynamic resource regulation and control method and system for guaranteeing delay-sensitive application delay SLO
CN113553172B (en) * 2021-06-11 2024-02-13 济南浪潮数据技术有限公司 IPMI service execution method, device and storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106980546A (en) * 2016-01-18 2017-07-25 阿里巴巴集团控股有限公司 A kind of task asynchronous execution method, apparatus and system
CN114579323A (en) * 2022-03-09 2022-06-03 上海达梦数据库有限公司 Thread processing method, device, equipment and medium

Also Published As

Publication number Publication date
CN115080247A (en) 2022-09-20

Similar Documents

Publication Publication Date Title
EP3335120B1 (en) Method and system for resource scheduling
CN106557369B (en) Multithreading management method and system
EP2754046B1 (en) Automatic preemption in multiple computer systems
US20060123423A1 (en) Borrowing threads as a form of load balancing in a multiprocessor data processing system
EP2698711A1 (en) Method for dispatching central processing unit of hotspot domain virtual machine and virtual machine system
CN112068960B (en) CPU resource allocation method, device, storage medium and equipment
CN106557371B (en) A kind of Distributed System Deadlock detection method based on side tracking
CN106126335A (en) The Media Survey method of terminal unit and terminal unit
CN111722934A (en) Distributed timing task processing method and system
CN112035255A (en) Thread pool resource management task processing method, device, equipment and storage medium
CN111831408A (en) Asynchronous task processing method and device, electronic equipment and medium
CN112817933A (en) Management method and device for elastic database connection pool
CN114546587A (en) Capacity expansion and reduction method of online image recognition service and related device
US20230409391A1 (en) Thread priority adjusting method, terminal, and computer-readable storage medium
CN106775975B (en) Process scheduling method and device
CN115080247B (en) High-availability thread pool switching method and device
CN110795234A (en) Resource scheduling method and device
CN116450328A (en) Memory allocation method, memory allocation device, computer equipment and storage medium
CN110555009B (en) Processing method and device for Network File System (NFS) service
CN110287159B (en) File processing method and device
CN113138842B (en) Micro service cluster scheduling method, device and medium
CN115391051A (en) Video computing task scheduling method, device and computer readable medium
JPWO2018211865A1 (en) Vehicle control device
CN113032098A (en) Virtual machine scheduling method, device, equipment and readable storage medium
CN111124688A (en) Server resource control method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant