Front-end task scheduling and event processing method and device, equipment and storage medium
Events in high concurrent interactions are captured and processed through the event proxy mechanism, and tasks are sorted and resource allocation are used for scheduling queues and multi-task priority queues. Combined with asynchronous execution and user feedback mechanisms, the problems of task conflicts and resource competition in high concurrent interactions are solved, and the system response speed and resource utilization efficiency are improved.
Patent Information
- Application Number
- CN202510060286.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-05-27
AI Technical Summary
In high concurrent interaction scenarios, traditional event processing mode is difficult to cope with complex concurrent interaction scenarios, resulting in task conflicts and resource competition problems.
All events triggered by child elements are captured through the event proxy mechanism, the events are processed into standard task objects in a unified format, and sorted and resource allocation through scheduling queues and multi-task priority queues, combining asynchronous execution and user feedback mechanisms.
It effectively solves the problems of task conflicts and resource competition in high concurrent interactions, improves the system's response speed and resource utilization efficiency, and avoids system overload and user interaction delays.
Smart Images

Figure CN120045298A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed system and network technologies, and particularly to a front-end task scheduling and event processing method, apparatus, device, and storage medium. Background Art
[0002] A high-concurrency interaction scenario refers to a scenario where a large number of users or requests access or operate on a system simultaneously within a specific time. In these scenarios, the system needs to be able to handle a large number of concurrent requests to ensure data consistency and system stability. High-concurrency scenarios pose higher requirements for the system architecture design, performance optimization, and security.
[0003] With the development of front-end technologies and the increasing demand for high-performance experiences from users, high-concurrency interaction scenarios have become increasingly common in modern applications. Among them, high-concurrency interaction not only involves events frequently triggered by users, such as clicks, scrolls, drags, etc.; high-concurrency interaction also includes data synchronization between the front end and the back end, such as real-time inventory refreshing, dynamic update pushing, etc. Specifically, in application scenarios such as flash sale systems, online collaboration tools, and real-time interaction platforms, the front end needs to efficiently process a large number of event requests to ensure the page response speed and interaction experience. In the prior art, traditional event processing models are difficult to cope with complex concurrent interaction scenarios, and there is an urgent need for an intelligent scheduling and processing solution to solve the task conflicts and resource competition problems existing in high-concurrency interactions. Summary of the Invention
[0004] The present invention provides a front-end task scheduling and event processing method, apparatus, device, and storage medium, which solves the task conflicts and resource competition problems existing in high-concurrency interactions.
[0005] To achieve the above object, the present invention adopts the following technical solutions:
[0006] In a first aspect, the present invention provides a front-end task scheduling and event processing method, the method comprising: based on an event delegation mechanism, by binding a single event listener on a parent container, capturing all events triggered by child elements;
[0007] Processing each captured event into a standard task object in a unified format; each of the standard task objects includes the task type, priority, timestamp of the event, a task identifier assigned to the task type, and a callback function corresponding to the event;
[0008] Adding the standard task objects to a scheduling queue in the order of priority, and performing duplicate removal processing and task merging processing on all the standard task objects in the scheduling queue to obtain a cleaned scheduling queue;
[0009] Add the standard task objects in the cleaned scheduling queue to the multi-task priority queue in sequence, and re-sort all the standard task objects according to the priority in the multi-task priority queue;
[0010] Dynamically adjust the resource allocation of each standard task object in the multi-task priority queue according to the priority of the standard task objects in the multi-task priority queue and in combination with the current system load;
[0011] Execute the standard task objects allocated with resources by combining the asynchronous execution method with the user feedback mechanism.
[0012] In a possible implementation, process each captured event into a standard task object in a unified format, specifically:
[0013] For each captured event, identify the key information of the event through an event type classifier, and classify the event into the corresponding task type; the key information includes the timestamp, priority, data source of the event, and the callback function corresponding to the event, and the task type includes user interaction events and system-generated events;
[0014] Based on the key information and task type of the event, encapsulate the event into a standard task object in the preset encapsulation format in combination with the preset encapsulation format.
[0015] In a possible implementation, perform duplicate removal processing and task merging processing on all the standard task objects in the scheduling queue, specifically including:
[0016] For all the standard task objects in the scheduling queue, adopt a duplicate removal mechanism, and regard the standard task objects with the same task identifier as the current standard task object and with an interval time less than the first preset threshold as duplicate standard task objects, and remove the duplicate standard task objects;
[0017] For all the standard task objects after duplicate removal in the scheduling queue, adopt a task merging mechanism, and merge multiple standard task objects with the same selected task type and that can be merged and processed into a new standard task object.
[0018] In a possible implementation, dynamically adjust the resource allocation of each standard task object in the multi-task priority queue according to the priority of the standard task objects in the multi-task priority queue and in combination with the current system load, specifically including:
[0019] Determine the current system load according to the ratio of the currently active task quantity obtained to the maximum task bearing capacity of the system;
[0020] When the current load of the system is greater than the maximum task - bearing capacity of the system, standard task objects with lower priorities are paused in sequence until the current load of the system is less than or equal to the maximum task - bearing capacity of the system.
[0021] In a possible implementation, the standard task objects allocated with resources are executed by combining an asynchronous execution method with a user feedback mechanism. Specifically:
[0022] By means of an asynchronous execution method, Promise and async / await asynchronous programming are used to execute the standard task objects allocated with resources.
[0023] When it is determined that the task type of the currently executed standard task object belongs to a user interaction event, the triggering method of the sub - elements corresponding to the standard task object is disabled; the user interaction events include button click events and page drag - and - drop events.
[0024] In a possible implementation, before adding the standard task objects to the scheduling queue in the order of priority, the method further includes:
[0025] Updating the priorities of the standard task objects according to the urgency of each standard task object in the target business scenario.
[0026] In a possible implementation, updating the priorities of the standard task objects according to the urgency of each standard task object in the target business scenario specifically includes:
[0027] For each standard task object, multiple influence parameters of the standard task object in the target business scenario are respectively obtained, as well as the weight coefficients of each influence parameter; the influence parameters include the weight of the task type, the importance weight of the task source, and the reciprocal of the time interval between the task generation time and the current time.
[0028] Updating the priorities of the standard task objects according to the weighted sum result of the multiple influence parameters.
[0029] In a second aspect, the present invention provides a front - end task scheduling and event processing device. The device includes: a first processing module, configured to capture all events triggered by sub - elements by binding a single event listener on a parent container based on an event proxy mechanism;
[0030] A second processing module, configured to process each captured event into a standard task object in a unified format; each standard task object includes the task type, priority, timestamp of the event, a task identifier allocated for the task type, and a callback function corresponding to the event.
[0031] The third processing module is used to add the standard task objects to the scheduling queue in the order of priority, and perform deduplication processing and task merging processing on all the standard task objects in the scheduling queue to obtain a cleaned scheduling queue;
[0032] The fourth processing module is used to sequentially add the standard task objects in the cleaned scheduling queue to the multi-task priority queue, and re-sort all the standard task objects according to the priority in the multi-task priority queue;
[0033] The fifth processing module is used to dynamically adjust the resource allocation of each standard task object in the multi-task priority queue according to the priority of the standard task objects in the multi-task priority queue and in combination with the current system load;
[0034] The sixth processing module is used to execute the standard task objects allocated with resources in combination with the user feedback mechanism through an asynchronous execution method.
[0035] In a possible implementation manner, the second processing module is specifically configured to execute:
[0036] For each captured event, identify the key information of the event through an event type classifier, and classify the event into a corresponding task type; the key information includes the timestamp, priority, data source of the event, and the callback function corresponding to the event, and the task type includes user interaction events and system-generated events;
[0037] In combination with a preset encapsulation format, based on the key information and task type of the event, encapsulate the event into a standard task object in the preset encapsulation format.
[0038] In a possible implementation manner, when performing deduplication processing and task merging processing on all the standard task objects in the scheduling queue, the third processing module is specifically configured to execute:
[0039] For all the standard task objects in the scheduling queue, adopt a deduplication mechanism, and regard the standard task objects with the same task identifier as the current standard task object and with an interval time less than the first preset threshold as duplicate standard task objects, and remove the duplicate standard task objects;
[0040] For all the deduplicated standard task objects in the scheduling queue, adopt a task merging mechanism, and merge multiple standard task objects with the same task type and capable of being merged into one new standard task object.
[0041] In a possible implementation manner, the fifth processing module is specifically configured to execute:
[0042] Determine the current system load based on the ratio of the currently active task quantity obtained to the maximum task - bearing capacity of the system;
[0043] When the current system load is greater than the maximum task - bearing capacity of the system, pause the standard task objects with lower priorities in sequence until the current system load is less than or equal to the maximum task - bearing capacity of the system.
[0044] In a possible implementation manner, the sixth processing module is specifically configured to execute:
[0045] Execute the standard task objects allocated with resources through an asynchronous execution method, using Promise and async / await asynchronous programming;
[0046] When determining that the task type of the currently executing standard task object belongs to a user interaction event, disable the triggering method of the sub - elements corresponding to the standard task object; the user interaction events include button click events and page drag - and - drop events.
[0047] In a possible implementation manner, the front - end task scheduling and event - handling device further includes a seventh processing module. Before adding the standard task objects to the scheduling queue in the order of priorities, the seventh processing module is specifically configured to execute:
[0048] Update the priorities of the standard task objects according to the urgency of each standard task object in the target business scenario.
[0049] In a possible implementation manner, when updating the priorities of the standard task objects according to the urgency of each standard task object in the target business scenario, the seventh processing module is specifically configured to execute:
[0050] For each standard task object, respectively obtain multiple influence parameters of the standard task object in the target business scenario, and the weight coefficient of each influence parameter; the influence parameters include the weight of the task type, the importance weight of the task source, and the reciprocal of the time interval between the task generation time and the current time;
[0051] Update the priorities of the standard task objects according to the weighted sum result of the multiple influence parameters.
[0052] In a third aspect, the present invention provides an electronic device, which includes a processor and a memory. At least one instruction, at least one program, a code set or an instruction set is stored in the memory, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the front - end task scheduling and event - handling method described in any one of the above.
[0053] Fourthly, the present invention provides a computer-readable storage medium storing at least one instruction, at least one program, a code set or an instruction set, which is loaded and executed by a processor to implement the front-end task scheduling and event processing method described in any one of the above.
[0054] The front-end task scheduling and event processing method provided by the embodiments of the present invention collaboratively processes high-concurrency interactive tasks through task capture and classification, task priority evaluation, task distribution and scheduling, resource allocation and dynamic adjustment, and task execution and feedback mechanisms, and can effectively solve the problems of task conflicts and resource competition in high-concurrency interactions.
[0055] In practical applications, the front-end task scheduling and event processing method provided by the embodiments of the present invention, based on the event proxy mechanism, captures all events triggered by child elements by binding a single event listener to the parent container; processes each captured event into a standard task object in a unified format, and the standard task object includes the task type, priority, timestamp, task identifier, and callback function of the event; through the above solution, it can accurately identify multi-type tasks in a high-concurrency environment, ensure that critical tasks with higher priorities are processed first, thereby avoiding waste of system resources.
[0056] In practical applications, the front-end task scheduling and event processing method provided by the embodiments of the present invention, through deduplication processing and task merging processing, can not only reduce the execution of duplicate tasks, but also effectively reduce the research frequency of back-end interfaces, thereby significantly improving the utilization efficiency of system resources.
[0057] In practical applications, the front-end task scheduling and event processing method provided by the embodiments of the present invention can dynamically adjust the execution order and resource allocation of tasks according to the priorities of standard task objects in the multi-task priority queue and in combination with the current system load, thereby effectively improving system performance and avoiding system overload.
[0058] In practical applications, the front-end task scheduling and event processing method provided by the embodiments of the present invention can ensure the real-time responsiveness of user operations through an asynchronous execution method and a user feedback mechanism, significantly reduce the occurrence probability of interaction delay phenomena caused by high-concurrency tasks, and improve the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1 is a flowchart of the steps of a front-end task scheduling and event processing method provided by an embodiment of the present invention;
[0060] Figure 2 is a block diagram of the structure of a front-end task scheduling and event processing device provided by an embodiment of the present invention. Detailed implementation manners
[0061] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0062] Hereinafter, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of the embodiments of the present disclosure, unless otherwise stated, the meaning of "a plurality" is two or more. Additionally, the use of "based on" or "according to" is meant to be open and inclusive, as a process, step, calculation, or other action "based on" or "according to" one or more of the stated conditions or values may in practice be based on additional conditions or values beyond those stated.
[0063] Currently, in the processing of high-concurrency interaction scenarios, there are problems such as chaotic task priorities, resource waste, performance bottlenecks, lack of dynamic scheduling, and feedback delays.
[0064] Among them, chaotic task priorities refer to the system's inability to distinguish the importance and real-time nature of tasks, resulting in critical operations (e.g., button click operations) being blocked by low-priority tasks.
[0065] Resource waste refers to repeated operations within a short period (e.g., quickly clicking the same button) triggering multiple requests, causing waste of system resources and increased backend pressure.
[0066] Performance bottlenecks refer to the fact that frequently triggered high-frequency events (e.g., scrolling or dragging) may trigger a large number of rendering operations, resulting in page lags.
[0067] The lack of dynamic scheduling means that the existing methods of processing tasks in a fixed order or simply in parallel cannot dynamically adjust the execution order of tasks and resource allocation according to the system load.
[0068] Feedback delay means that the user feedback after a task is completed (e.g., button state update) may be delayed, reducing the user experience.
[0069] To solve the problems of task conflicts and resource competition in high-concurrency interactions, the embodiments of the present invention provide a front-end task scheduling and event processing method, device, equipment, and storage medium.
[0070] In a first aspect, as Figure 1As shown in the figure, an embodiment of the present invention provides a front-end task scheduling and event handling method, and the method includes:
[0071] Step 101, based on the event delegation mechanism, capture all events triggered by child elements by binding a single event listener to the parent container.
[0072] Among them, the event delegation mechanism is to delegate the function that responds to an event of one element to another element.
[0073] A single event listener refers to a listener that only focuses on a specific event; a single event listener focuses on one event, such as events like button clicks, mouse movements, or keyboard inputs. When this specific event occurs, the single event listener will execute the predefined processing logic.
[0074] The purposes of binding a single event listener to the parent container mainly include improving performance, reducing memory overhead, supporting dynamic elements, and improving code maintainability, where:
[0075] Improving performance: When child elements are dynamically generated, directly binding events to child elements will fail, while event delegation can capture these events; when binding events to multiple child elements, when the same event needs to be added to many child elements, binding them one by one will consume resources, and using event delegation can significantly improve performance.
[0076] Reducing memory overhead: Binding the event to the parent element reduces memory overhead and binding operations.
[0077] Supporting dynamic elements: It can handle subsequent dynamically added child elements.
[0078] Improving code maintainability: The implementation steps of event delegation determine the parent container, select the parent container that can contain the target child elements; add an event listener, bind the event to the parent container; determine the event target, use event.target to determine the actual trigger of the event; filter the child elements, filter out the required target elements through event.target or matches.
[0079] The event triggered by a child element means that in the DOM tree of a web page, when a user interacts with a specific child element (such as clicking, hovering, etc.), the event bound to the child element is activated and the corresponding operation is executed. In front-end development, the event triggered by a child element may affect its parent element or other ancestor elements. For example, when a user clicks a button (child element), it may trigger the click event of the button itself, and at the same time, it may also trigger the click event of its parent container (parent element).
[0080] In the present invention, adopting the method of step 101 can effectively avoid the problem of binding listeners to child elements one by one, significantly reduce memory overhead, and improve event management efficiency.
[0081] In an embodiment of the present invention, in JavaScript, the parent container listens for events triggered by child elements through the addEventListener method and dynamically dispatches event handling logic based on the event target (event.target).
[0082] Among them, JavaScript, abbreviated as JS, is an interpreted scripting language; addEventListener is a function that listens for events and processes the corresponding ones.
[0083] In the present invention, step 101 can effectively improve the event capture efficiency.
[0084] Step 102: Process each captured event into a standard task object in a unified format.
[0085] Among them, each standard task object includes the task type, priority, timestamp of the event, the task identifier assigned to the task type, and the callback function corresponding to the event.
[0086] Specifically, this step can be implemented through an event type classifier, which identifies, classifies, and encapsulates each captured event into a corresponding standard task object.
[0087] Step 103: Add the standard task objects to the scheduling queue in the order of priority, and perform deduplication processing and task merging processing on all the standard task objects in the scheduling queue to obtain a cleaned scheduling queue.
[0088] Specifically, the deduplication processing of all the standard task objects in the scheduling queue is implemented through a deduplication mechanism, and the merging processing of multiple standard task objects in the scheduling queue is implemented through a task merging mechanism, thereby effectively improving the task processing efficiency in a high-concurrency scenario and ensuring that the system processes tasks efficiently and stably.
[0089] Among them, the deduplication mechanism means that in different time dimensions, the data generated by repeating an action is only counted once. The task merging mechanism refers to the process of merging the results of multiple small tasks into an overall result.
[0090] Step 104: Add the standard task objects in the cleaned scheduling queue to the multi-task priority queue in sequence, and re-sort all the standard task objects according to the priority in the multi-task priority queue.
[0091] Among them, the multi-task priority queue can sort the standard task objects according to the priority, ensuring that the standard task objects with high priority can be processed first, while the tasks with low priority will be delayed.
[0092] In an embodiment of the present invention, step 104 is implemented using a PriorityQueue class. This PriorityQueue class manages standard task objects through a built-in task array. Whenever a standard task object is added to the multi-task priority queue, it is sorted within the multi-task priority queue according to the priority of the newly added standard task object, thereby ensuring that standard task objects with higher priorities can be scheduled first.
[0093] The specific implementation code is as follows:
[0094]
[0095]
[0096] In this implementation solution, a new standard task object is added to the multi-task priority queue through the enqueue method, the standard task objects are sorted according to the priority through the sort method, and the standard task object with the highest priority is taken out through the dequeue method for processing.
[0097] Step 105: Dynamically adjust the resource allocation of each standard task object in the multi-task priority queue according to the priority of the standard task objects in the multi-task priority queue and in combination with the current system load.
[0098] Specifically, step 105 cooperates with step 104 to achieve system resource allocation and dynamic adjustment. Through the multi-task priority queue and in combination with the actual situation of the system load, efficient task scheduling and resource allocation are carried out, thereby ensuring the stability and efficiency of the system in a high-concurrency scenario.
[0099] Step 106: Execute the standard task objects allocated with resources by combining the asynchronous execution method with the user feedback mechanism.
[0100] Among them, the asynchronous execution method ensures that the system can process multiple standard task objects simultaneously in a high-concurrency environment without affecting the response of the interface.
[0101] The user feedback mechanism provides instant interactive feedback during the task execution process to ensure that the user can perceive the state changes of the system when the task is being processed.
[0102] The combination of the asynchronous execution method and the user feedback mechanism can improve the responsiveness and performance of the application program, and at the same time provide timely feedback to the user. This method is very important in software development, especially when dealing with I / O-intensive tasks (such as file reading and writing, network communication, etc.). In this embodiment, the combination of the asynchronous execution method and the user feedback mechanism can efficiently manage the execution of standard task objects in a high-concurrency situation and provide a smooth interaction experience for the user.
[0103] Further, each captured event is processed into a standard task object in a unified format, specifically as follows:
[0104] For each captured event, the key information of the event is identified through an event type classifier, and the event is classified into the corresponding task type.
[0105] Among them, the key information includes the timestamp, priority, data source of the event, and the callback function corresponding to the event, and the task types include user interaction events and system-generated events.
[0106] Combined with the preset encapsulation format, based on the key information and task type of the event, the event is encapsulated into a standard task object in the preset encapsulation format.
[0107] Specifically, in order to achieve intelligent classification of events, through the event type classifier, the captured events are automatically identified and classified based on the basic information of the events. Among them, the basic information of the events includes information such as event type and source.
[0108] For example: classifying a click event as a user interaction event and classifying a dynamic frame update event as a system-generated event.
[0109] In the embodiment of the present invention, the implementation code of the event classification process is as follows:
[0110]
[0111] In this implementation solution, event classification is implemented based on event.type.
[0112] The encapsulation of the event into a standard task object in the preset encapsulation format is specifically implemented through the following code:
[0113]
[0114] In this implementation solution, the standard task object is represented by task, and the encapsulated standard task object includes: task identifier (id), task type (type), priority (priority), timestamp (timestamp), and callback function (callback). Among them, the task identifier (id) is automatically generated according to the different task types (type).
[0115] The encapsulated standard task object can be stored in a queue in a first-in-first-out storage form, laying a foundation for subsequent processing. This step can provide a unified standard and flexibility for subsequent task processing.
[0116] Further, all standard task objects in the scheduling queue are de-duplicated and task merged, specifically including:
[0117] For all standard task objects in the scheduling queue, a deduplication mechanism is adopted. Standard task objects with the same task identifier as the current standard task object and an interval time less than the first preset threshold are regarded as duplicate standard task objects, and the duplicate standard task objects are removed.
[0118] Among them, the deduplication mechanism uses task identifiers and hash storage to avoid the execution of duplicate tasks.
[0119] For example: Use the Map data structure to store standard task objects. By checking the unique id of the standard task object, it is judged whether there are the same standard task objects. If the standard task object already exists and the time interval is less than the first preset threshold (for example, 500 milliseconds), then the standard task object is not executed to avoid duplicate processing.
[0120] In the embodiments of the present invention, the deduplication process is specifically implemented through the following code:
[0121]
[0122] In this implementation solution, taskMap is used to store standard task objects. Among them, the key is the unique identifier task.id of the standard task object, and the value is the standard task object. By judging the time difference between the timestamp of the task and the current time, the standard task object is only stored in taskMap to achieve deduplication when the time difference is greater than the first preset threshold.
[0123] For all deduplicated standard task objects in the scheduling queue, a task merging mechanism is adopted. Multiple standard task objects with the same selected task type and capable of being merged and processed are merged into a new standard task object.
[0124] Among them, the task merging mechanism is that when the system processes multiple similar tasks, multiple similar tasks are merged into one task for unified processing, thereby reducing duplicate backend requests. For tasks of the same type, for example: inventory update or batch data synchronization, the system will screen out the tasks that can be merged according to the classification result of the task type, and merge these tasks into a new task for processing.
[0125] In the embodiments of the present invention, merging multiple standard task objects with the same selected task type and capable of being merged and processed into a new standard task object is specifically implemented through the following code:
[0126] const batchedUpdates=tasks.filter(task=>task.type==='update');
[0127] const mergedTask = mergeTasks(batchedUpdates); / / Merge into a single task
[0128] In this implementation, first, the filter method is used to screen all tasks of type update, and then these tasks are merged into one task through the mergeTasks function.
[0129] For example: The mergeTasks function is used to merge batch data synchronization into one batch task, reducing the number of requests, thereby reducing the burden on the server.
[0130] This step, through the combination of the deduplication mechanism and the merging mechanism, not only reduces the execution of duplicate tasks in the system but also effectively reduces the frequency of backend interface calls, improving the performance and response speed of the system. This design can significantly improve the resource utilization efficiency and the overall processing capacity of the system when dealing with a large number of concurrent tasks, especially when there are duplicates or similarities between tasks.
[0131] Furthermore, according to the priorities of the standard task objects in the multi-task priority queue and combined with the current system load, the resource allocation of each standard task object in the multi-task priority queue is dynamically adjusted, specifically including:
[0132] Determine the current system load based on the ratio of the currently active task quantity obtained to the maximum task capacity of the system;
[0133] When the current system load is greater than the maximum task capacity of the system, suspend the standard task objects with lower priorities in sequence until the current system load is less than or equal to the maximum task capacity of the system.
[0134] In the embodiments of the present invention, the current system load is determined through a load calculation formula, where the load calculation formula is:
[0135]
[0136] where L represents the current system load, N active represents the currently active task quantity, and C max represents the maximum task capacity of the system.
[0137] When the current system load is higher than the maximum task capacity of the system, the standard task objects with lower priorities will be suspended to avoid system overload until the current system load decreases.
[0138] This load scheduling strategy combined with the multi-task priority queue enables the system to achieve reasonable resource allocation and optimized scheduling when processing high-concurrency tasks, improving the overall processing efficiency.
[0139] Furthermore, the standard task object to which resources are allocated is executed by combining the asynchronous execution mode with the user feedback mechanism, specifically:
[0140] Through asynchronous execution, standard task objects with allocated resources are executed using Promise and async / await asynchronous programming.
[0141] Among them, the asynchronous execution method uses Promise and async / await asynchronous programming to execute tasks, avoiding main thread blockage and improving system responsiveness. When executing tasks, async function packaging is used to ensure that the execution of tasks will not block page rendering and other operations.
[0142] In the embodiment of the present invention, the asynchronous execution mode is specifically implemented by the following code:
[0143]
[0144]
[0145] In this implementation, the executeTask function accepts a standard task object and waits for the callback function of the task to be executed through the await function. If an error occurs during the task execution, the exception will be caught and recorded in the exception log.
[0146] When it is determined that the task type of the currently executed standard task object belongs to a user interaction event, the triggering mode of the sub-element corresponding to the standard task object is disabled.
[0147] Among them, user interaction events include button click events and page drag events.
[0148] For example, in an embodiment of the present invention, when a user clicks a button to initiate a task, the button will be disabled to prevent repeated submissions, and the button will be restored to its available state after the task is completed. This solution is specifically implemented by the following code:
[0149]
[0150] In this implementation, when a user clicks a button to trigger a task, the button is first disabled to prevent the user from repeatedly clicking and triggering the task multiple times. After the task is completed, the disabled state of the button is set to false, allowing the user to perform the next operation. This mechanism not only improves the stability of the system, but also optimizes the user experience and avoids abnormal behavior caused by high concurrency operations.
[0151] Furthermore, before adding the standard task objects to the scheduling queue in order of priority, the method further includes:
[0152] Update the priority of the standard task object according to the urgency of each standard task object in the target business scenario.
[0153] That is to say, before adding the standard task objects to the scheduling queue in the order of priority, the priority of each standard task object can also be adjusted according to the actual application scenario or user requirements, so that the priority of task execution is more suitable for the actual application scenario.
[0154] Furthermore, update the priority of the standard task object according to the urgency of each standard task object in the target business scenario, specifically including:
[0155] For each standard task object, obtain multiple influence parameters of the standard task object in the target business scenario and the weight coefficient of each influence parameter respectively.
[0156] Among them, the influence parameters include the weight of the task type, the importance weight of the task source, and the reciprocal of the time interval between the task generation time and the current time.
[0157] Update the priority of the standard task object according to the weighted sum result of multiple influence parameters.
[0158] Specifically, calculate the updated priority of the standard task object through the priority evaluation algorithm. Among them, the calculation formula of the priority evaluation algorithm is specifically:
[0159] P = ω 1 *T type + ω 2 *T source + ω 3 *(1 / Δt);
[0160] Among them, P represents the updated priority, T type represents the weight of the task type, T source represents the importance weight of the task source, Δt represents the time interval between the task generation time and the current time, where the task generation time is the time stamp of the standard task object, ω 1 、ω 2 、ω 3 respectively represent the weight coefficients of the three influence parameters.
[0161] In the embodiment of the present invention, the priority evaluation algorithm is specifically implemented through the following steps:
[0162] (1) Parse task attributes: Extract key information such as task type, task source, and time stamp from the standard task object.
[0163] (2) Mapping impact parameters: Score the task type and task source through a predefined impact parameter weight table. For example, user interaction tasks (such as click operations) have a higher priority, while system update tasks have a lower priority.
[0164] (3) Calculate the priority in real time. Determine the final priority of the standard task object after update according to the calculation formula of the priority evaluation algorithm, and update the priority of the standard task object.
[0165] The specific implementation code of this method is as follows:
[0166]
[0167] In this solution, the typeWeight function obtains the corresponding impact parameter value from the impact parameter weight table (weightMap) according to the task type (task.type). Among them, weightMap is a predefined object that contains the impact parameter values corresponding to different task types.
[0168] For example: weightMap["click"] may be 10, indicating that the click event has a higher priority. If the value of task.type cannot find the corresponding parameter value in weightMap, the default value 0 (indicating no special priority) is used.
[0169] The sourceWeight function obtains the corresponding impact parameter value from the impact parameter weight table (weightMap) according to the task source (task.source). Among them, sourceMap is a predefined object that stores the impact parameter values of different task sources.
[0170] For example: sourceMap["user"] may be 15, indicating that tasks generated by user interaction have a higher priority. If the value of task.source cannot find the corresponding impact parameter value in sourceMap, the default value 0 is also used.
[0171] The timeFactor function calculates a time-related factor based on the timestamp (task.timestamp) when the task is created, reflecting the urgency of the task. The closer the time, the higher the priority. The difference between the task creation time and the current time represents the "age" of the task. The smaller the time difference, the "newer" the task, so the higher the priority. Take the reciprocal of the interpolation to make the priority factor larger as the time is closer.
[0172] The return function performs a weighted sum of the three impact parameters to calculate the updated priority of the standard task object.
[0173] In this embodiment, the weight coefficients of the three influencing parameters are taken as 0.5, 0.3, and 0.2 respectively.
[0174] This solution enables the system to adapt to the task processing requirements in different scenarios in real time, ensures the response speed of high-priority tasks, and at the same time avoids low-priority tasks from blocking critical processes.
[0175] The front-end task scheduling and event handling method provided by the embodiments of the present invention collaboratively processes high-concurrency interactive tasks through task capture and classification, task priority evaluation, task distribution and scheduling, resource allocation and dynamic adjustment, and task execution and feedback mechanisms, and can effectively solve the problems of task conflicts and resource competition in high-concurrency interactions.
[0176] In practical applications, the front-end task scheduling and event handling method provided by the embodiments of the present invention, based on the event proxy mechanism, captures all events triggered by child elements by binding a single event listener to the parent container; processes each captured event into a standard task object in a unified format, and the standard task object includes the task type, priority, timestamp, task identifier, and callback function of the event; through the above solution, it can accurately identify multi-type tasks in a high-concurrency environment, ensure that key tasks with higher priorities are processed first, thereby avoiding waste of system resources.
[0177] In practical applications, the front-end task scheduling and event handling method provided by the embodiments of the present invention, through duplicate removal processing and task merging processing, can not only reduce the execution of duplicate tasks, but also effectively reduce the investigation frequency of the back-end interface, thereby significantly improving the utilization efficiency of system resources.
[0178] In practical applications, the front-end task scheduling and event handling method provided by the embodiments of the present invention can dynamically adjust the execution order of tasks and resource allocation according to the priorities of the standard task objects in the multi-task priority queue and in combination with the current load of the system, thereby effectively improving system performance and avoiding system overload.
[0179] In practical applications, the front-end task scheduling and event handling method provided by the embodiments of the present invention, through the asynchronous execution method and the user feedback mechanism, can ensure the real-time responsiveness of user operations, significantly reduce the occurrence probability of interaction delay phenomena caused by high-concurrency tasks, and improve the user experience.
[0180] In the second aspect, as Figure 2 shown, the embodiments of the present invention provide a front-end task scheduling and event handling device, and the device includes:
[0181] A first processing module 201, configured to capture all events triggered by child elements by binding a single event listener to the parent container based on the event proxy mechanism;
[0182] The second processing module 202 is configured to process each captured event into a standard task object in a unified format; each standard task object includes the task type, priority, timestamp of the event, a task identifier assigned to the task type, and a callback function corresponding to the event;
[0183] The third processing module 203 is configured to add the standard task objects to the scheduling queue in the order of priority, and perform duplicate removal processing and task merging processing on all the standard task objects in the scheduling queue to obtain a cleaned scheduling queue;
[0184] The fourth processing module 204 is configured to sequentially add the standard task objects in the cleaned scheduling queue to the multi-task priority queue, and re-sort all the standard task objects according to the priority in the multi-task priority queue;
[0185] The fifth processing module 205 is configured to dynamically adjust the resource allocation of each standard task object in the multi-task priority queue according to the priority of the standard task objects in the multi-task priority queue and in combination with the current system load;
[0186] The sixth processing module is configured to execute the standard task objects allocated with resources in combination with the user feedback mechanism through an asynchronous execution method.
[0187] Optionally, the second processing module 202 is specifically configured to execute:
[0188] For each captured event, identify the key information of the event through an event type classifier, and classify the event into a corresponding task type; the key information includes the timestamp, priority, data source of the event, and a callback function corresponding to the event, and the task types include user interaction events and system-generated events;
[0189] In combination with a preset encapsulation format, based on the key information and task type of the event, encapsulate the event into a standard task object in the preset encapsulation format.
[0190] Optionally, when performing duplicate removal processing and task merging processing on all the standard task objects in the scheduling queue, the third processing module 203 is specifically configured to execute:
[0191] For all the standard task objects in the scheduling queue, adopt a duplicate removal mechanism, and regard the standard task objects with the same task identifier as the current standard task object and with an interval time less than the first preset threshold as duplicate standard task objects, and remove the duplicate standard task objects;
[0192] For all the de-duplicated standard task objects in the scheduling queue, adopt a task merging mechanism, and merge multiple standard task objects with the same task type and capable of being merged into a new standard task object.
[0193] Optionally, the fifth processing module 205 is specifically configured to execute:
[0194] Determine the current system load according to the ratio of the currently active task quantity obtained to the maximum task carrying capacity of the system;
[0195] When the current system load is greater than the maximum task carrying capacity of the system, pause the standard task objects with lower priorities in sequence until the current system load is less than or equal to the maximum task carrying capacity of the system.
[0196] Optionally, the sixth processing module is specifically configured to execute:
[0197] Execute the standard task objects allocated with resources by means of asynchronous execution, using Promise and async / await asynchronous programming;
[0198] When it is determined that the task type of the currently executed standard task object belongs to a user interaction event, disable the triggering method of the sub-elements corresponding to the standard task object; the user interaction events include button click events and page drag events.
[0199] Optionally, the front-end task scheduling and event processing device further includes a seventh processing module. Before adding the standard task objects to the scheduling queue in the order of priorities, the seventh processing module is specifically configured to execute:
[0200] Update the priorities of the standard task objects according to the urgency of each standard task object in the target business scenario.
[0201] Optionally, when updating the priorities of the standard task objects according to the urgency of each standard task object in the target business scenario, the seventh processing module is specifically configured to execute:
[0202] For each standard task object, respectively obtain multiple influence parameters of the standard task object in the target business scenario, and the weight coefficient of each influence parameter; the influence parameters include the weight of the task type, the importance weight of the task source, and the reciprocal of the time interval between the task generation time and the current time;
[0203] Update the priorities of the standard task objects according to the weighted summation result of the multiple influence parameters.
[0204] The front-end task scheduling and event processing device provided by the embodiments of the present invention is used to execute the above front-end task scheduling and event processing method, and thus can achieve the same effects as the above front-end task scheduling and event processing method.
[0205] Those skilled in the art can clearly understand that for the convenience and conciseness of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.
[0206] In a third aspect, an embodiment of the present invention further provides an electronic device, which includes a processor and a memory. At least one instruction, at least one program, a code set, or an instruction set is stored in the memory, and the at least one instruction, at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the front-end task scheduling and event processing method in the embodiments of the present invention.
[0207] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, in which at least one instruction, at least one program, a code set, or an instruction set is stored, and the at least one instruction, at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the front-end task scheduling and event processing method in the embodiments of the present invention.
[0208] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present invention are generated in whole or in part. The computer can be a general-purpose computer, a dedicated computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired manner (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or a wireless manner (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or a data center that includes one or more integrated available media. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).
[0209] The above is only the specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed by the present invention should be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.
Claims
1. A front-end task scheduling and event processing method, characterized in that: include: Based on the event proxy mechanism, by binding a single event listener on the parent container, all events triggered by child elements are captured; Process each captured event into a standard task object in a unified format; each of the standard task objects includes the task type, priority, timestamp, task identifier assigned to the task type, and callback function corresponding to the event; Adding the standard task objects to the scheduling queue in order of priority, and performing deduplication processing and task merging processing on all standard task objects in the scheduling queue to obtain a cleaned scheduling queue; The standard task objects in the cleaned scheduling queue are sequentially added to the multi-task priority queue, and all the standard task objects are re-sorted in the multi-task priority queue according to the priority; Dynamically adjusting resource allocation of each standard task object in the multi-task priority queue according to the priority of the standard task object in the multi-task priority queue and in combination with the current load of the system; The standard task objects with allocated resources are executed through asynchronous execution combined with user feedback mechanism.
2. The front-end task scheduling and event processing method according to claim 1, characterized in that: Process each captured event into a standard task object in a unified format, specifically: For each captured event, the key information of the event is identified through an event type classifier, and the event is classified into a corresponding task type; the key information includes the timestamp, priority, data source and callback function corresponding to the event, and the task type includes user interaction events and system generated events; In combination with a preset encapsulation format, based on key information and task type of the event, the event is encapsulated into a standard task object in the preset encapsulation format.
3. The front-end task scheduling and event processing method according to claim 1, characterized in that: Deduplication and task merging are performed on all standard task objects in the scheduling queue, specifically including: For all standard task objects in the scheduling queue, a deduplication mechanism is adopted to treat standard task objects with the same task identifier as the current standard task object and with an interval time less than a first preset threshold as duplicate standard task objects, and remove the duplicate standard task objects; For all the standard task objects after duplication in the scheduling queue, a task merging mechanism is adopted to merge multiple standard task objects with the same task type and capable of being merged for processing into a new standard task object.
4. The front-end task scheduling and event processing method according to claim 1, characterized in that: According to the priority of the standard task object in the multi-task priority queue and in combination with the current load of the system, the resource allocation of each standard task object in the multi-task priority queue is dynamically adjusted, specifically including: Determine the current load of the system based on the ratio of the number of currently active tasks to the maximum task carrying capacity of the system; When the current load of the system is greater than the maximum task carrying capacity of the system, standard task objects with low priorities are suspended in sequence until the current load of the system is less than or equal to the maximum task carrying capacity of the system.
5. The front-end task scheduling and event processing method according to claim 1, characterized in that: The standard task objects with allocated resources are executed through asynchronous execution combined with the user feedback mechanism, specifically: Through asynchronous execution, use Promise and async / await asynchronous programming to execute standard task objects with allocated resources; When it is determined that the task type of the currently executed standard task object belongs to a user interaction event, the triggering mode of the sub-element corresponding to the standard task object is disabled; the user interaction event includes a button click event and a page drag event.
6. The front-end task scheduling and event processing method according to claim 1, characterized in that: Before adding the standard task objects to the scheduling queue in order of priority, the method further includes: According to the urgency of each standard task object in the target business scenario, the priority of the standard task object is updated.
7. The front-end task scheduling and event processing method according to claim 6, characterized in that: According to the urgency of each standard task object in the target business scenario, the priority of the standard task object is updated, specifically including: For each standard task object, a plurality of influencing parameters of the standard task object in the target business scenario and a weight coefficient of each influencing parameter are respectively obtained; the influencing parameters include the weight of the task type, the importance weight of the task source, and the reciprocal of the time interval between the task generation time and the current time; The priority of the standard task object is updated according to the weighted sum of the multiple influencing parameters.
8. A front-end task scheduling and event processing device, characterized in that: include: The first processing module is used to capture events triggered by all child elements by binding a single event listener to the parent container based on the event proxy mechanism; A second processing module is used to process each captured event into a standard task object in a unified format; each of the standard task objects includes a task type, priority, and timestamp of the event, a task identifier assigned to the task type, and a callback function corresponding to the event; The third processing module is used to add the standard task objects to the scheduling queue in order of priority, and perform deduplication processing and task merging processing on all standard task objects in the scheduling queue to obtain a cleaned scheduling queue; A fourth processing module, used for sequentially adding the standard task objects in the post-cleaning scheduling queue to the multi-task priority queue, and re-sorting all the standard task objects in the multi-task priority queue according to their priorities; A fifth processing module, configured to dynamically adjust resource allocation of each standard task object in the multi-task priority queue according to the priority of the standard task object in the multi-task priority queue and in combination with the current load of the system; The sixth processing module is used to execute the standard task object to which resources are allocated in an asynchronous execution mode in combination with a user feedback mechanism.
9. An electronic device, characterized in that: The electronic device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the front-end task scheduling and event processing method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement the front-end task scheduling and event processing method as described in any one of claims 1-7.
Citation Information
Cited By
Information synchronization method, system and equipment of embedded training simulator and medium
CN120263801A
Information synchronization method, system, device and medium for embedded training simulator
CN120263801B
Fusion terminal communication resource allocation method and system based on multi-application collaboration
CN120603072A
Method and system for allocating communication resources of a converged terminal based on multi-application collaboration
CN120603072B
Distributed event processing method and electronic equipment
CN121349737A