A task scheduling method and system based on large-scale business processing
By adopting asynchronous task scheduling methods in financial business processing, long-time tasks are converted into asynchronous processing, which solves the problems of long response time and resource waste under the synchronous model, achieving efficient resource utilization and improving user experience.
Patent Information
- Application Number
- CN202410954779.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-17
AI Technical Summary
When processing complex financial business logic, the synchronous blocking IO model causes the system response time to be too long, and the occupied thread cannot serve more concurrent requests. In addition, the connection of the front-end page is disconnected due to request timeout, and the response result cannot be obtained, resulting in a waste of resources and user Experience negative effects.
Adopt an asynchronous task scheduling method based on large-scale business to convert long-time-consuming business into asynchronous processing. Monitor the system and thread occupancy in real time through the asynchronous processing framework, pre-check task request qualifications, and submit asynchronous requests when system resources are idle. Task, persistent storage of processing results to notify the user.
It improves system resource utilization, avoids resource waste, and improves user experience. Users do not need to wait for back-end processing results. They can query in time or learn the processing progress through message push, reducing timeout waiting.
Smart Images

Figure CN118502923B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of financial business processing, and in particular to an asynchronous task scheduling method and system based on large-scale business. Background Art
[0002] Since the application backend framework usually adopts the MVC framework of the synchronous blocking IO model, each request is assigned a thread for processing. When processing complex and time-consuming tasks, the execution thread will be occupied until the task is completed. When this model is used to process large data volume calculations and complex financial business logic, the system response time is too long, which can easily cause the available threads of the running container to be occupied for a long time, making it impossible to serve and process more concurrent requests. In addition, if the front-end page initiates an http request, the front-end page will also be blocked until the request times out.
[0003] The front-end framework usually sets a reasonable request timeout for http requests. Once the front-end page request times out, the http connection between the front-end and back-end will be disconnected. Due to the stateless nature of the http connection, once the connection is disconnected, the front-end cannot obtain the response result of the request. At the same time, the back-end execution thread will not stop calculating due to the front-end request timeout, but will continue to execute until the task is completed or an exception occurs. However, since the front-end request has timed out, the connection is disconnected, and the back-end cannot return the successfully processed response result to the front-end, resulting in the waste of this response result. In addition, the user may continue to try to click the button on the page to re-initiate the request because he cannot get the result, resulting in a secondary waste of resources. This processing method not only wastes system resources, but also has a negative impact on the user's operating experience. Summary of the invention
[0004] The present invention aims to provide a task scheduling method and system based on large-scale business processing, which converts time-consuming business types into asynchronous processing, and at the same time needs to balance the overall resources of the system so that the asynchronous processing does not affect the execution of normal business. Task requests are processed based on system occupancy and thread occupancy to cope with situations where large amounts of data calculations and complex financial business logic processing are required.
[0005] To achieve the above object, the present invention adopts the following scheme:
[0006] In the first aspect, the present application provides a task scheduling method based on large-scale business processing, which runs in a task running container, pre-divides the task running container into a synchronous processing area and an asynchronous processing area, configures the task running container parameters, and deploys an asynchronous processing framework in the task running container. The asynchronous processing framework monitors the system occupancy of the task running container and the thread occupancy of the asynchronous processing framework in real time. The processing process includes the following steps:
[0007] Respond to the current business processing request initiated by the user end, analyze the type of business processing request received, and send the business processing request of this type to the corresponding processing area according to the system occupancy;
[0008] When the task is sent to the asynchronous processing area, the business processing request execution qualification is pre-checked again based on the system occupancy and thread occupancy;
[0009] If the pre-check passes, the current business processing request is submitted to the asynchronous processing framework, and the asynchronous processing framework creates a corresponding processing thread to process the current business processing request.
[0010] In some optional implementations, configuring the task running container parameters includes configuring the container global parameters, the asynchronous thread pool parameters of the asynchronous processing framework, and the task parameters. The container global parameters include the thread activity threshold of the task running container and the maximum quasi-intersection value of the heap memory; the asynchronous thread pool parameters include the total number of core threads, the maximum number of asynchronous processing tasks, the threshold for the number of tasks in the bounded priority waiting queue, the maximum idle time of the thread, and the saturation policy; the task parameters include the execution interval, timeout time, number of resets, and priority of the task; the system occupancy includes the current number of active threads and the current heap memory usage; the thread occupancy includes the number of active core threads and the number of tasks in the bounded priority waiting queue.
[0011] In some optional implementations, the pre-check performs the following process:
[0012] Receive a business processing request and encapsulate the business processing request into an executable asynchronous request task;
[0013] Query the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool in the asynchronous processing framework;
[0014] Determine whether to submit an asynchronous request task to the asynchronous thread pool based on the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool;
[0015] When submitting an asynchronous request task to the asynchronous thread pool, the asynchronous request task object is serialized and persistently stored in the asynchronous task table, and the processing status of the asynchronous request task is updated in real time in the asynchronous task table.
[0016] In some optional implementations, the process of determining whether to submit an asynchronous request task is as follows:
[0017] If the current number of active threads exceeds the thread activity threshold, stop submitting asynchronous request tasks to the asynchronous thread pool and wait for the next round of condition checks by the background monitoring thread;
[0018] If the current number of active threads is less than the thread activity threshold but the heap memory usage exceeds the maximum quasi-interval value of the heap memory, stop submitting asynchronous request tasks to the asynchronous thread pool and wait for the next round of condition checks by the background monitoring thread;
[0019] If the current number of active threads is less than the thread activity threshold and the heap memory usage is less than the maximum quasi-intersection value of the heap memory, but the number of tasks in the bounded priority waiting queue is full, stop submitting asynchronous request tasks to the asynchronous thread pool and wait for the next round of condition checks by the background monitoring thread;
[0020] If the number of tasks in the bounded priority waiting queue is less than the task number threshold, the asynchronous request task is submitted to the asynchronous thread pool.
[0021] In some optional implementations, the process of submitting an asynchronous request task to an asynchronous thread pool is:
[0022] Determine whether the bounded priority waiting queue is empty. If it is empty, determine whether to process the asynchronous request task immediately based on the thread occupancy and system occupancy;
[0023] If the bounded priority waiting queue is not empty, the tasks will be inserted into the bounded priority waiting queue in order of task priority and wait for execution. According to the thread occupancy and system occupancy, the asynchronous request tasks in the bounded priority waiting queue will be assigned threads for processing in order of task priority, and the processing status of the asynchronous request tasks in the asynchronous task table will be synchronously updated to pending execution.
[0024] In some optional implementations, when the bounded priority waiting queue is empty, the judgment process is:
[0025] If the number of currently active core threads does not exceed the total number of core threads, a core thread is assigned to process the asynchronous request task and the processing status of the asynchronous request task in the asynchronous task table is synchronously updated to being executed;
[0026] If the number of currently active core threads reaches the total number of core threads but does not exceed the maximum number of asynchronous processing tasks, and the system continues to determine that the number of currently active threads has not reached the active threshold and the system memory usage is less than the maximum quasi-interval value of the heap memory, a new core thread is created to execute the asynchronous request task and the processing status of the asynchronous request task in the asynchronous task table is synchronously updated to being executed;
[0027] If the number of currently active core threads reaches the total number of core threads and the maximum number of asynchronous processing tasks, the asynchronous request task will be inserted into the bounded priority waiting queue in the order of task priority to wait for execution, and the processing status of the asynchronous request task in the asynchronous task table will be synchronously updated to pending execution.
[0028] In some optional implementations, a thread pool listener thread is created in the asynchronous processing framework, and the thread pool listener thread performs the following process:
[0029] Poll the asynchronous task table to find asynchronous request tasks with abnormal execution status;
[0030] The task status of the asynchronous request task with execution exception is updated to pending execution, and the priority is set to the highest priority, and then inserted into the bounded priority waiting queue for priority execution.
[0031] In some optional implementations, the thread pool listener thread also performs the following process:
[0032] Determine in real time whether the number of currently active core threads in the thread pool exceeds the total number of core threads and calculate the thread excess value;
[0033] If it exceeds, continue to determine whether the active time of each currently active core thread exceeds the thread survival time threshold;
[0034] A core thread whose active time exceeds the thread survival time threshold is marked as to be destroyed, and the time excess value of the core thread marked with the to-be-destroyed tag is calculated;
[0035] After the currently active core thread is completed, the core threads are destroyed in sequence according to the time excess value, and the core threads corresponding to the thread excess value are destroyed.
[0036] In some optional implementations, the specific process of sending the service processing request to the corresponding processing area is:
[0037] Analyze the user's business processing request type and find the execution time and resource consumption corresponding to this type of business processing request;
[0038] Determine whether the execution time exceeds the time threshold. If it exceeds the threshold or there is no execution time, send the business processing request to the asynchronous processing area.
[0039] If the execution time does not exceed the time threshold but the execution resource consumption exceeds the set value, determine the system occupancy of the current task running container;
[0040] If the current number of active threads is less than the conversion threshold and the heap memory usage is less than the memory execution threshold, the business processing request is sent to the synchronous processing area for synchronous execution in the running container.
[0041] In a second aspect, the present application provides a task scheduling system based on large-scale business processing, including a task running container, the task running container is divided into a synchronous processing area and an asynchronous processing area deployed with an asynchronous processing framework, and the task running container includes:
[0042] Parameter configuration module, used to configure task running container parameters;
[0043] Asynchronous processing framework, including:
[0044] The receiving response module is used to respond to the current business processing request initiated by the user end, analyze the type of business processing request received, and send the business processing request of this type to the corresponding processing area according to the system occupancy;
[0045] The asynchronous processing area includes: background listening threads, which are used to monitor the system occupancy of the task running container and the thread occupancy of the asynchronous processing framework in real time;
[0046] Asynchronous task manager, used to pre-check the execution qualification of business processing request based on system occupancy and thread occupancy;
[0047] If the pre-check passes, the current business processing request will be submitted to the asynchronous processing pool, and a corresponding processing thread will be created to process the current business processing request.
[0048] In some optional implementations, the asynchronous processing framework includes an asynchronous task manager, an asynchronous thread pool, and a background listening thread, wherein the asynchronous task manager includes:
[0049] The task encapsulation module is used to receive a business processing request and encapsulate the business processing request into an executable asynchronous request task;
[0050] The task pre-check module is used to query the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool in the asynchronous processing framework, and determine whether to submit an asynchronous request task to the asynchronous thread pool based on the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool;
[0051] The task submission module is used to submit the asynchronous request task to the asynchronous thread pool, serialize the asynchronous request task object, and store it persistently in the asynchronous task table, and update the processing status of the asynchronous request task in the asynchronous task table in real time;
[0052] The asynchronous thread pool is used to allocate threads for processing submitted asynchronous request tasks and synchronously update the processing status of asynchronous request tasks in the asynchronous task table;
[0053] The thread pool listener thread is used to poll the processing status of the asynchronous request tasks in the asynchronous task table, and submit the asynchronous request tasks with the processing status of execution exception to the asynchronous thread pool for execution.
[0054] Beneficial effects:
[0055] In this application, some time-consuming requests are converted into asynchronous requests, persistently stored in the database, and the user is promptly notified that the task has been received and the task processing results can be queried later. Users do not need to passively wait for the back-end processing results, and can query the asynchronous processing results afterwards or learn about the processing progress through message push. The asynchronous task scheduling framework will submit the asynchronous request to the internal thread pool for processing when system resources are idle. After the processing is completed, the framework will persist the response results (for example, store them in a database or write them to a file), and remind users that the asynchronous task has been completed through various methods such as to-do reminders, text messages, and message push. Users can query or download asynchronous processing results through the asynchronous result query interface to avoid timeouts or long waits, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 A flowchart of a task processing method for large-scale business processing provided by an embodiment of the present invention;
[0057] Figure 2 A flowchart of an asynchronous task scheduling method for large-scale business processing provided by an embodiment of the present invention;
[0058] Figure 3 A block diagram of an asynchronous task framework system provided by an embodiment of the present invention;
[0059] Figure 4 Asynchronous scheduling block diagram provided for an embodiment of the present invention;
[0060] Figure 5 A block diagram of the task execution container provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0061] In order to enable those skilled in the art to better understand the technical solution of the present invention / invention, the present invention / invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0062] Embodiment 1:
[0063] like Figures 1 to 5 As shown, the present application provides a task scheduling method based on large-scale business processing, which runs in a task running container, pre-divides the task running container into a synchronous processing area and an asynchronous processing area, and deploys an asynchronous processing framework in the task running container. Configuring the task running container parameters includes configuring the container global parameters, the asynchronous thread pool parameters of the asynchronous processing framework, and the task parameters;
[0064] The global parameters of the container include the thread activity threshold of the task running container and the maximum quasi-commit value of the heap memory; the asynchronous thread pool parameters include the total number of core threads, the maximum number of asynchronous processing tasks, the bounded priority waiting queue task number threshold, the maximum thread idle time and saturation strategy; since the memory of the container is limited, the asynchronous task framework is integrated into the application system with the aim of converting time-consuming tasks into asynchronous processing. During asynchronous processing, attention will be paid to protecting the resources of the application system without affecting the normal business logic of the application system. The memory usage safety warning value (the maximum quasi-commit value of the heap memory) is configured to determine whether to continue submitting asynchronous request tasks to the asynchronous thread pool to prevent memory overflow caused by executing asynchronous request tasks when the memory usage is too high.
[0065] Task parameters include the task execution interval, timeout, reset times and priority. System occupancy includes the current number of active threads and current heap memory usage. Thread occupancy includes the number of active core threads and the number of tasks in the bounded priority waiting queue.
[0066] When the current business processing request initiated by the client is received, the tasks that take a long time and require a lot of resources are encapsulated as asynchronous processing requests. For tasks that take a long time, asynchronous processing is adopted, and for resource-consuming requests, when the load of the running container is low, the asynchronous can be converted to a synchronous task; If the system occupancy of the current task running container is not busy, and the heap memory usage of the running container is not high, there are sufficient resources to execute the computing request that consumes a lot of resources. If the request is executed for the first time and there is no statistical value of the execution time, it is directly converted to asynchronous task processing; if this type of asynchronous task has been executed before, and the request parameter name and request parameter value that are long and affect the execution efficiency are also the same, it is also converted to asynchronous task processing; if this type of asynchronous task has been executed before, the execution efficiency is fast and the time consumption is short, but it occupies a lot of computing resources, and the request parameter name and parameter value that affect the execution efficiency are also the same, then it is converted to synchronous request processing and directly executed synchronously in the running container. In the query request, some fields may be specified to affect the query results. Each query transaction is different. For example, if you want to query the transactions of a certain department, the department can be used as the request parameter name and parameter value that affects performance. Through test observation, the value of the department (department number) points to a small department (departments can be divided according to the user scale and business data volume of the department. Departments with large user scale and large business data volume are large departments, and departments with relatively small user scale and relatively small business data volume are small departments). The query efficiency is very high and very fast. The request parameter name and parameter value are stored as the request parameter name and parameter value that affects performance.
[0067] In other words, when a business processing request is received, it is necessary to first determine whether the task running container is busy according to the asynchronous task framework. If it is not busy, it will be executed directly in the synchronous area. If it is busy, it will be transferred to the asynchronous task and then asynchronously scheduled for execution. The specific process is:
[0068] Parse the user's business processing request, obtain all request parameter names and request parameter values corresponding to the request, obtain the request parameter names and request parameter values that affect the execution efficiency and performance by traversing the pre-stored request parameter names and request parameter values, and find the execution time and execution resource consumption corresponding to this type of business processing request according to the request parameter names and parameter values that affect the execution efficiency and performance;
[0069] Determine whether the execution time exceeds the time threshold. If it exceeds the threshold or there is no execution time, send the business processing request to the asynchronous processing area.
[0070] If the execution time does not exceed the time threshold but the execution resource consumption exceeds the set value, determine the system occupancy of the current task running container;
[0071] If the current number of active threads is less than the conversion threshold and the heap memory usage is less than the memory execution threshold, the business processing request is sent to the synchronous processing area for synchronous execution in the running container.
[0072] Specifically, the processing process includes the following steps:
[0073] S1. Respond to the current business processing request initiated by the user end, parse the received business processing request type, and send the business processing request to the corresponding processing area;
[0074] For the financial industry, some business types may take a long time, so these business requests need to be converted into asynchronous processing and processed when the system is idle.
[0075] S2. When the task is sent to the asynchronous processing area, the asynchronous processing framework will monitor the system occupancy of the task running container and the thread occupancy of the asynchronous processing framework in real time, and pre-check the execution qualification of the business processing request based on the system occupancy and thread occupancy;
[0076] The precheck performs the following process:
[0077] The precheck performs the following process:
[0078] S21, receiving a business processing request, and encapsulating the business processing request into an executable asynchronous request task;
[0079] S22, querying the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool in the asynchronous processing framework;
[0080] S23, judging whether to submit an asynchronous request task to the asynchronous thread pool according to the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool;
[0081] The asynchronous task pre-execution check mainly evaluates the resource usage of the current system. First, the asynchronous task framework checks the ratio of the current number of active threads in the current Web container to the maximum number of available threads in the Web container. If the ratio exceeds the threshold of 80% (which can be dynamically configured as needed), it means that the system currently has a large number of concurrent access requests, and the asynchronous task will stop submitting execution requests to the thread pool to ensure that there are enough resources in the container to prioritize synchronous requests. Secondly, if the Web container execution thread is not busy, the framework will further check the heap memory usage of the current container. If the system's heap memory usage is high (by default, it exceeds 80%, which can be dynamically configured), continuing to submit asynchronous tasks may cause insufficient system memory, so asynchronous tasks will not be submitted for execution. Finally, if the Web container thread is not busy and the heap memory is sufficient, the asynchronous task framework will further check the operation of the thread pool in the framework to ensure that there are enough executable threads in the thread pool. If there are not enough executable threads in the thread pool and the bounded priority waiting queue is full, the asynchronous tasks waiting to be executed will not be submitted to the thread pool for queue execution. If the above conditions are not met, the submission action will be terminated and the user will be promptly notified that the system is busy. When the user submits again, the asynchronous request will be awakened and the above check actions will be repeated until the asynchronous task is executed.
[0082] Specifically, the process of determining whether to submit an asynchronous request task is as follows:
[0083] S231. If the current number of active threads exceeds the thread activity threshold, stop submitting asynchronous request tasks to the asynchronous thread pool and return a system busy notification to the client;
[0084] S232: If the current number of active threads is less than the thread activity threshold but the heap memory usage exceeds the maximum quasi-interval value of the heap memory, stop submitting asynchronous request tasks to the asynchronous thread pool and return a system busy notification to the client;
[0085] S233. If the current number of active threads is less than the thread activity threshold and the heap memory usage is less than the maximum quasi-intersection value of the heap memory, but the number of tasks in the bounded priority waiting queue is full, stop submitting asynchronous request tasks to the asynchronous thread pool and return a system busy notification to the client;
[0086] S234. If the number of tasks in the bounded priority waiting queue is less than the task number threshold, submit the asynchronous request task to the asynchronous thread pool.
[0087] The asynchronous task framework includes an improved dynamically scalable asynchronous thread pool that can create multiple core threads for processing asynchronous tasks, and each core thread only processes one task at the same time. In addition, the thread pool also has a bounded priority waiting queue and a thread pool saturation rejection policy. When the asynchronous task framework submits asynchronous tasks to be executed to the thread pool, if the core threads are idle, the asynchronous request tasks will be assigned to these core threads for direct execution. If the core threads are running at full capacity but have not reached the maximum number of asynchronous processing tasks, and there is sufficient memory in the system, the asynchronous thread pool will further create execution threads and assign tasks to them. When the number of threads executing tasks in the thread pool reaches the maximum number of asynchronous processing tasks, the tasks submitted by the asynchronous task framework will be inserted into the waiting queue in the order of task priority and wait for execution.
[0088] The process of submitting an asynchronous request task to the asynchronous thread pool is:
[0089] Step 1: Determine whether the bounded priority waiting queue is empty. If it is empty, determine whether to process the asynchronous request task immediately based on the thread occupancy and system occupancy. The specific process is as follows:
[0090] 1.1. If the number of currently active core threads does not exceed the total number of core threads, a core thread is assigned to process the asynchronous request task and the processing status of the asynchronous request task in the asynchronous task table is synchronously updated to being executed;
[0091] 1.2. If the number of currently active core threads reaches the total number of core threads but does not exceed the maximum number of asynchronous processing tasks, and the number of currently active threads in the system does not reach the active threshold and the system memory usage is less than the maximum quasi-interval value of the heap memory, a new core thread is created to execute the asynchronous request task and the processing status of the asynchronous request task in the asynchronous task table is synchronously updated to being executed;
[0092] 1.3. If the number of currently active core threads reaches the total number of core threads and the maximum number of asynchronous processing tasks, the asynchronous request task will be inserted into the bounded priority waiting queue in the order of task priority to wait for execution, and the processing status of the asynchronous request task in the asynchronous task table will be synchronously updated to pending execution.
[0093] Step 2: If the bounded priority waiting queue is not empty, the tasks will be inserted into the bounded priority waiting queue in order of task priority and wait for execution. According to the thread occupancy and system occupancy, the asynchronous request tasks in the bounded priority waiting queue will be assigned thread processing in order of task priority, and the processing status of the asynchronous request tasks in the asynchronous task table will be synchronously updated to pending execution.
[0094] S24. While submitting the asynchronous request task to the asynchronous thread pool, the asynchronous request task is serialized as an object and persistently stored in the asynchronous task table, and the processing status of the asynchronous request task is updated in real time in the asynchronous task table.
[0095] Encapsulate the business processing request submitted by the user into a task request that can be executed asynchronously. Before submitting it to the asynchronous task thread pool, the framework will first serialize the asynchronous request task object and store it persistently in the database. The purpose is to prevent the loss of asynchronous tasks caused by sudden system downtime and improve the stability and reliability of the framework. The role of the asynchronous task table, the asynchronous task framework will encapsulate the asynchronous request into an asynchronous task. In order to prevent the task from being lost due to a sudden system downtime, the asynchronous task framework enables a protection mechanism and first saves the encapsulated asynchronous task to the database (writes it from the memory to the database medium). The table where the asynchronous task is stored is the asynchronous task table. The state of the asynchronous task is to be executed for the first time. If it is being executed and processed by the core thread, the state will be updated to being executed or the processing is completed. It will be updated to processing success or execution exception according to the actual processing situation. If the system suddenly crashes during the execution process, resulting in the interruption of the asynchronous task execution in the memory, then when the system starts, the state of the executing asynchronous task will be marked as execution exception, and then according to the task strategy (discard, re-execute), the state of the asynchronous task will be refreshed to be executed.
[0096] S3. If the pre-check is passed, the current business processing request is submitted to the asynchronous processing framework, and the asynchronous processing framework creates a corresponding processing thread to process the current business processing request.
[0097] When the core thread executes an asynchronous request task, it first updates the status of the corresponding task in the asynchronous task table to "executing" according to the task number, and then executes the business logic of the asynchronous task. After the task is executed, the status of the asynchronous task is updated to "successful execution" or "abnormal end" according to the actual execution result. According to the parameter configuration of the asynchronous task, the execution result is serialized and stored persistently. This process can be achieved by storing the execution result in the execution result table of the database or generating a result file in a specific format.
[0098] Specifically, a thread pool listener thread is created in the asynchronous processing framework, and the thread pool listener thread performs the following process:
[0099] 1. Poll the asynchronous task table to find the asynchronous request task with abnormal execution status; update the task status of the asynchronous request task with abnormal execution to pending execution and set the priority to the highest priority, and then insert it into the bounded priority waiting queue for priority execution.
[0100] The background monitoring thread runs regularly. When the asynchronous task framework service is started for the first time, according to the parameter configuration of the asynchronous task, it checks whether there are tasks in the asynchronous task table that are in abnormal execution due to abnormal system downtime. If the execution time of the abnormal value task reaches the timeout, the status of these tasks will be updated to "pending execution" and the priority will be set to the highest priority. Then, the tasks will be inserted into the bounded priority waiting queue for priority execution.
[0101] 2. Determine in real time whether the number of currently active core threads in the thread pool exceeds the total number of core threads, and calculate the thread overvalue; if it exceeds, continue to determine whether the active time of each currently active core thread exceeds the thread survival time threshold; mark the core threads whose active time exceeds the thread survival time threshold as to-be-destroyed, and calculate the time overvalue of the core threads marked with to-be-destroyed tags; after the current active core thread is completed, destroy the core threads in sequence according to the time overvalue, and destroy the core threads corresponding to the thread overvalue.
[0102] The asynchronous thread pool will check whether there are any "pending" asynchronous tasks in the current bounded priority waiting queue. If there are "pending" asynchronous tasks in the queue, the thread pool will give priority to high-priority asynchronous tasks for execution. If there are no "pending" asynchronous tasks in the waiting queue, it will further determine whether the number of active threads in the thread pool currently exceeds the number of core threads. When the total number of active threads exceeds the number of core threads, and the active time of the thread exceeds the thread survival time condition, the thread pool will destroy some threads that exceed the core threads.
[0103] Example 2
[0104] This embodiment provides a task scheduling system based on large-scale business processing, including a task running container for executing the task of Embodiment 1, wherein the task running container is divided into a synchronous processing area and an asynchronous processing area where an asynchronous processing framework is deployed, and the task running container includes:
[0105] Parameter configuration module, used to configure task running container parameters;
[0106] Asynchronous processing framework, including:
[0107] The receiving response module is used to respond to the current business processing request initiated by the user end, analyze the type of business processing request received, and send the business processing request of this type to the corresponding processing area according to the system occupancy;
[0108] The asynchronous processing area includes: background listening threads, which are used to monitor the system occupancy of the task running container and the thread occupancy of the asynchronous processing framework in real time;
[0109] Asynchronous task manager, used to pre-check the execution qualification of business processing request based on system occupancy and thread occupancy;
[0110] If the pre-check passes, the current business processing request is submitted to the asynchronous processing pool, and a corresponding processing thread is created to process the current business processing request.
[0111] In some optional implementations, the asynchronous processing area further includes an asynchronous task manager, an asynchronous thread pool, and a background listening thread, wherein the asynchronous task manager includes:
[0112] The task encapsulation module is used to receive a business processing request and encapsulate the business processing request into an executable asynchronous request task;
[0113] The task pre-check module is used to query the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool in the asynchronous processing framework, and determine whether to submit an asynchronous request task to the asynchronous thread pool based on the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool;
[0114] The task submission module is used to submit the asynchronous request task to the asynchronous thread pool, serialize the asynchronous request task object, and store it persistently in the asynchronous task table, and update the processing status of the asynchronous request task in the asynchronous task table in real time;
[0115] The asynchronous thread pool is used to allocate threads for processing submitted asynchronous request tasks and synchronously update the processing status of asynchronous request tasks in the asynchronous task table;
[0116] The thread pool listener thread is used to poll the processing status of the asynchronous request tasks in the asynchronous task table, and submit the asynchronous request tasks with the processing status of execution exception to the asynchronous thread pool for execution.
[0117] The thread pool listening thread is also used to monitor the startup time and running time of the asynchronous processing server; monitor the running status of asynchronous request tasks in the asynchronous processing server, including the number of successful, failed, abnormal, and abandoned tasks of asynchronous request tasks that have been executed, the total execution time, the average execution time, the number of asynchronous request tasks to be executed, the average memory usage, the total waiting time and the average waiting time of asynchronous request tasks; monitor the running status of the asynchronous thread pool, including the number of currently executing threads, the execution time of the currently executing asynchronous request task, and the number of waiting tasks in the bounded priority waiting queue.
[0118] The technical concept of this application is:
[0119] Since the application backend framework usually adopts the MVC framework of the synchronous blocking IO model, each request will be processed by a corresponding thread. When processing complex and time-consuming tasks, the thread will be occupied until the task is completed. When this model is used to process large data volume calculations and complex financial business logic, the system response time will be too long, which may easily cause the thread running the container to be occupied for a long time, making it impossible to serve more concurrent requests. In addition, if the front-end page initiates an http request, the front-end page will also be blocked until the request times out.
[0120] Therefore, this application will identify the business request as an asynchronous business processing request when the business type is a task that is estimated to take longer than the synchronous processing time threshold, and assign it to the asynchronous processing framework for processing. After the asynchronous processing framework receives the request, it will register the request information in the asynchronous processing control information according to the standard, including the asynchronous initiation channel, institution information, transaction time, transaction business type, transaction request information (class name, method name, parameter json), and file information if there is file processing. In addition, when the asynchronous processing framework receives a request, it will also determine whether there is an unfinished asynchronous processing task for the user, transaction business type, and transaction request information corresponding to the request. If there is an unfinished asynchronous processing task for the same user, the same type of transaction business type, and transaction request information, repeated asynchronous requests are not allowed.
[0121] For asynchronous processing, in order to prevent low or slow asynchronous task processing efficiency from squeezing out normal business processing resources in the synchronous processing area, the system needs to set the "maximum number of asynchronous processing tasks" parameter according to the actual container resource situation to limit the number of asynchronous processing execution threads; set a bounded priority waiting queue to limit the number of asynchronous tasks in the waiting queue.
[0122] When a user initiates an asynchronous task, the request goes through a series of pre-checks. Only when the conditions are met will the task be approved and submitted to the asynchronous thread pool for execution. Before submission, the system will check the overall resource usage of the system (check the number of active threads of the running container, check the memory usage of the running container). If the overall resource usage of the system exceeds the preset threshold (80%) and the priority of the task to be submitted at this time is low, the task will not be submitted. If the priority is high, the system will further check the resource usage of the asynchronous thread pool (whether there are idle threads, whether the maximum number of asynchronous processing tasks has been reached, the number of tasks waiting in the waiting queue, etc.). When the task submission conditions are met, the asynchronous task is submitted for execution.
[0123] For asynchronous tasks that are persisted to the asynchronous task table, a timer is used to periodically wake up a listening thread to check the asynchronous task status. For asynchronous tasks with an execution exception, first check whether the overall system resource usage exceeds the preset threshold and whether the asynchronous thread pool has enough idle threads or the waiting queue has idle positions. Then, asynchronous tasks with higher priorities are inserted first. If there are asynchronous tasks with the same priority, the tasks are woken up according to the queuing time.
[0124] It is understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present invention, but the present invention is not limited thereto. For those skilled in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.
Claims
1. A task scheduling method based on large-scale business processing, characterized in that: Running in the task running container, the task running container is pre-divided into a synchronous processing area and an asynchronous processing area, the task running container parameters are configured, and an asynchronous processing framework is deployed in the task running container. The asynchronous processing framework monitors the system occupancy of the task running container and the thread occupancy of the asynchronous processing framework in real time. The processing process includes the following steps: Respond to the current business processing request initiated by the user end, analyze the type of business processing request received, and send the business processing request of this type to the corresponding processing area according to the system occupancy; The specific process of sending the business processing request to the corresponding processing area is as follows: Analyze the user's business processing request and find the execution time and resource consumption corresponding to the business processing request; Determine whether the execution time exceeds the time threshold. If it exceeds the threshold or there is no execution time, send the business processing request to the asynchronous processing area. If the execution time does not exceed the time threshold but the execution resource consumption exceeds the set value, determine the system occupancy of the current task running container; If the current number of active threads is less than the conversion threshold and the heap memory usage is less than the memory execution threshold, the business processing request is sent to the synchronous processing area for synchronous execution in the running container; When the task is sent to the asynchronous processing area, the business processing request execution qualification is pre-checked again based on the system occupancy and thread occupancy; The precheck performs the following process: Receive a business processing request and encapsulate the business processing request into an executable asynchronous request task; Query the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool in the asynchronous processing framework; Determine whether to submit an asynchronous request task to the asynchronous thread pool based on the system occupancy of the task running container and the thread occupancy of the asynchronous thread pool; When submitting an asynchronous request task to the asynchronous thread pool, the asynchronous request task is serialized and persistently stored in the asynchronous task table, and the processing status of the asynchronous request task is updated in real time in the asynchronous task table; A thread pool listener thread is created in the asynchronous processing framework, and the thread pool listener thread performs the following process: Poll the asynchronous task table to find asynchronous request tasks with abnormal execution status; Update the task status of the asynchronous request task with execution exception to pending execution and set the priority to the highest priority, then insert it into the bounded priority waiting queue for priority execution; If the pre-check passes, the current business processing request is submitted to the asynchronous processing framework, and the asynchronous processing framework creates a corresponding processing thread to process the current business processing request.
2. A task scheduling method based on large-scale business processing according to claim 1, characterized in that: Configuring task running container parameters includes configuring container global parameters, asynchronous thread pool parameters of the asynchronous processing framework, and task parameters. Container global parameters include the thread activity threshold of the task running container and the maximum quasi-commit value of the heap memory; asynchronous thread pool parameters include the total number of core threads, the maximum number of asynchronous processing tasks, the threshold for the number of tasks in the bounded priority waiting queue, the maximum idle time of threads, and the saturation policy. System occupancy includes the current number of active threads and the current heap memory usage. Thread occupancy includes the number of active core threads and the number of tasks in the bounded priority waiting queue.
3. The task scheduling method based on large-scale business processing according to claim 1 is characterized in that: The process of determining whether to submit an asynchronous request task is: If the current number of active threads exceeds the thread activity threshold, stop submitting asynchronous request tasks to the asynchronous thread pool and wait for the next round of condition checks by the background monitoring thread; If the current number of active threads is less than the thread activity threshold but the heap memory usage exceeds the maximum quasi-interval value of the heap memory, stop submitting asynchronous request tasks to the asynchronous thread pool and wait for the next round of condition checks by the background monitoring thread; If the current number of active threads is less than the thread activity threshold and the heap memory usage is less than the maximum quasi-intersection value of the heap memory, but the number of tasks in the bounded priority waiting queue is full, stop submitting asynchronous request tasks to the asynchronous thread pool and wait for the next round of condition checks by the background monitoring thread; If the number of tasks in the bounded priority waiting queue is less than the task number threshold, the asynchronous request task is submitted to the asynchronous thread pool.
4. The task scheduling method based on large-scale business processing according to claim 1 is characterized in that: The process of submitting an asynchronous request task to the asynchronous thread pool is: Determine whether the bounded priority waiting queue is empty. If it is empty, determine whether to process the asynchronous request task immediately based on the thread occupancy and system occupancy; If the bounded priority waiting queue is not empty, the tasks will be inserted into the bounded priority waiting queue in order of task priority and wait for execution. According to the thread occupancy and system occupancy, the asynchronous request tasks in the bounded priority waiting queue will be assigned threads for processing in order of task priority, and the processing status of the asynchronous request tasks in the asynchronous task table will be synchronously updated to pending execution.
5. A task scheduling method based on large-scale business processing according to claim 4, characterized in that: When the bounded priority waiting queue is empty, the judgment process is: If the number of currently active core threads does not exceed the total number of core threads, a core thread is assigned to process the asynchronous request task and the processing status of the asynchronous request task in the asynchronous task table is synchronously updated to being executed; If the number of currently active core threads reaches the total number of core threads but does not exceed the maximum number of asynchronous processing tasks, and the system continues to determine that the number of currently active threads has not reached the active threshold and the system memory usage is less than the maximum quasi-interval value of the heap memory, a new core thread is created to execute the asynchronous request task and the processing status of the asynchronous request task in the asynchronous task table is synchronously updated to being executed; If the number of currently active core threads reaches the total number of core threads and the maximum number of asynchronous processing tasks, the asynchronous request task will be inserted into the bounded priority waiting queue in the order of task priority to wait for execution, and the processing status of the asynchronous request task in the asynchronous task table will be synchronously updated to pending execution.
6. The task scheduling method based on large-scale business processing according to claim 1 is characterized in that: The thread pool listener thread also performs the following process: Determine in real time whether the number of currently active core threads in the thread pool exceeds the total number of core threads and calculate the thread excess value; If it exceeds, continue to determine whether the active time of each currently active core thread exceeds the thread survival time threshold; A core thread whose active time exceeds the thread survival time threshold is marked as to be destroyed, and the time excess value of the core thread marked with the to-be-destroyed tag is calculated; After the currently active core thread is completed, the core threads are destroyed in sequence according to the time excess value, and the core threads corresponding to the thread excess value are destroyed.
7. A task scheduling system based on large-scale business processing, using a task scheduling method based on large-scale business processing as described in any one of claims 1 to 6, characterized in that: It includes a task running container with an asynchronous processing framework deployed. The task running container is divided into a synchronous processing area and an asynchronous processing area. The task running container includes: Parameter configuration module, used to configure task running container parameters; Asynchronous processing framework, including: The receiving response module is used to respond to the current business processing request initiated by the user end, analyze the type of business processing request received, and send the business processing request of this type to the corresponding processing area according to the system occupancy; The asynchronous processing area includes: background listening threads, which are used to monitor the system occupancy of the task running container and the thread occupancy of the asynchronous processing framework in real time; Asynchronous task manager, used to pre-check the execution qualification of business processing request based on system occupancy and thread occupancy; If the pre-check passes, the current business processing request will be submitted to the asynchronous processing pool, and a corresponding processing thread will be created to process the current business processing request.
