Task allocation management method and system
By introducing distributed locking mechanism and multi-computer room deployment in the task order grab system, the problem of low task allocation efficiency is solved, and the efficiency of task allocation and user experience is improved.
Patent Information
- Application Number
- PCT/CN2024/092648
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-25
- Filing Date
- 2024-05-11
- Publication Date
- 2024-11-28
AI Technical Summary
The task allocation efficiency in the existing task order grabbing system is low, resulting in poor user experience and uneven task allocation, affecting the overall efficiency.
By introducing a distributed lock mechanism in the task allocation management system, the number of users that can be preempted for each pending task is limited, and the consistency of task status is ensured in distributed concurrency scenarios. Multi-computer room deployment and message middleware are used to dynamically adjust Tasks send the number of users to improve the quality of allocation.
It effectively improves the efficiency and quality of task allocation, ensures the uniqueness and mutual exclusion of task allocation, reduces the uneven task allocation caused by concurrent allocation, and improves user experience.
Smart Images

Figure CN2024092648_28112024_PF_FP_ABST
Abstract
Description
A task allocation management method and system
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on May 25, 2023, with application number 202310606548.X. The entire contents of this application are incorporated by reference into this application. Technical Field
[0002] The embodiments of the present application relate to the field of computer technology, and in particular to a task allocation management method and system. Background Art
[0003] With the development of internet technology, various user-interactive platforms have emerged, such as food delivery platforms, ride-hailing platforms, and live streaming platforms. These platforms all involve task allocation operations, such as user submission, platform dispatch, and user claiming. To improve task allocation efficiency, task grabbing systems are often introduced.
[0004] The current task-grabbing system primarily operates in two modes: active assignment and manual claiming. Users can choose to have tasks automatically assigned by the system or manually claim them by refreshing the page. Task-grabbing systems typically assign a single task to all eligible users, causing all users to simultaneously claim the task, resulting in inefficient task allocation.
[0005] Summary of the Invention
[0006] The embodiments of the present application provide a task allocation management method and system to solve the technical problem of low task allocation efficiency in related technologies and effectively improve the efficiency of task allocation.
[0007] In a first aspect, an embodiment of the present application provides a task allocation management method, which is applied to a task allocation management system, wherein the task allocation management system includes a distributed front-end service, a task allocation service, and a cache service. The task allocation management method includes:
[0008] The task assignment service obtains the pending task and the online user list from the cache service, and respectively sets a first distributed lock and a second distributed lock in the cache service according to the task identifier of the pending task and the online user list. The online user list is updated by the task assignment service based on the online users who can receive tasks.
[0009] The task allocation service determines a plurality of first users from the online user list, unlocks the second distributed lock in the cache service, updates the pending task and the task status of the plurality of first users to dispatched in the cache service, and unlocks the first distributed lock in the cache service;
[0010] The task allocation service sends task dispatch information to the front-end service based on the to-be-processed task and the plurality of first users;
[0011] The front-end service sends the task dispatching information to the multiple first users, so that the multiple first users can receive the to-be-processed tasks based on the task dispatching information.
[0012] In a second aspect, an embodiment of the present application provides a task allocation management system, including a distributed front-end service, a task allocation service, and a cache service, wherein:
[0013] The task assignment service is configured to obtain a pending task and a list of online users from the cache service, and respectively set a first distributed lock and a second distributed lock in the cache service according to a task identifier of the pending task and the list of online users, wherein the online user list is updated by the task assignment service based on online users who can receive tasks; determine a plurality of first users from the online user list, unlock the second distributed lock in the cache service, update the task status of the pending task and the plurality of first users to dispatched in the cache service, and unlock the first distributed lock in the cache service; and send task dispatch information to the front-end service based on the pending task and the plurality of first users;
[0014] The front-end service is configured to send the task dispatching information to the multiple first users, so that the multiple first users can receive the pending tasks based on the task dispatching information.
[0015] In a third aspect, an embodiment of the present application provides a task allocation management device, including: a memory and one or more processors;
[0016] The memory is used to store one or more programs;
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the task allocation management method as described in the first aspect.
[0018] In a fourth aspect, an embodiment of the present application provides a non-volatile storage medium storing computer-executable instructions, which, when executed by a computer processor, are used to execute the task allocation management method as described in the first aspect.
[0019] In the fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor of the device reads and executes the computer program from the computer-readable storage medium, so that the device performs the task allocation management method described in the first aspect.
[0020] In an embodiment of the present application, a task allocation service is used to obtain pending tasks and a list of online users from a cache service, and a first distributed lock and a second distributed lock are set in the cache service according to the task identifier of the pending task and the online user list, respectively. After determining multiple first users from the online user list, the second distributed lock is unlocked, and the pending tasks and the task status of each first user are updated in the cache service. Then, task dispatch information is sent to the multiple first users through the front-end service, so that each first user can receive the pending tasks based on the task dispatch information. Multiple first users are selected from the online user list to dispatch the pending tasks. Each first user can choose to receive the task according to demand, and the number of users who can preempt each pending task is limited, thereby improving the efficiency of task allocation. In addition, the first distributed lock can ensure the consistency of the task status of tasks and related users in distributed concurrent scenarios, effectively ensuring the uniqueness and mutual exclusivity of task allocation. The second distributed lock can reduce the uneven instantaneous task allocation probability caused by concurrent task allocation, thereby improving the quality of task allocation. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] FIG1 is a schematic diagram of the system structure of a task allocation management system provided in an embodiment of the present application;
[0022] FIG2 is a flowchart of a task allocation management method provided in an embodiment of the present application;
[0023] FIG3 is a schematic diagram of a task state transition provided by an embodiment of the present application;
[0024] FIG4 is a schematic diagram of a task claiming process provided by an embodiment of the present application;
[0025] FIG5 is a schematic diagram of a task request process provided by an embodiment of the present application;
[0026] FIG6 is a schematic diagram of a task confirmation process provided in an embodiment of the present application;
[0027] FIG7 is a schematic diagram of the structure of a task allocation management device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solutions and advantages of the present application clearer, the specific embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. It is understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. It should also be noted that, for ease of description, only some, but not all, of the contents related to the present application are shown in the accompanying drawings. Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe each operation (or step) as a sequential process, many of the operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of the operations can be rearranged. The above process can be terminated when its operation is completed, but it can also have additional steps not included in the accompanying drawings. The above process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0029] The task allocation management method provided in this application can be applied to task allocation scenarios based on grabbing orders, such as order distribution on food delivery platforms, online car-hailing platforms, online service (such as consulting services) distribution, battles on live broadcast platforms, online task distribution, etc., aiming to limit the number of users who can grab each pending task, improve the efficiency of task allocation, and ensure the consistency of task status between tasks and related users in distributed concurrent scenarios through the first distributed lock, and reduce the uneven probability of instantaneous task allocation caused by concurrent task allocation through the second distributed lock, thereby improving the quality of task allocation. For existing task allocation methods, they are generally based on a task grabbing system. The task grabbing system will directly distribute the pending tasks to each user who can receive the task, resulting in all users grabbing a pending task at the same time, but a task will only be bound to one service party (the user who receives the task) and one serviced party (the user who requests the task). Therefore, a task will eventually be grabbed by only one service party, resulting in a lower overall success rate of the service party in grabbing orders, reduced task allocation efficiency, and affected the user experience. Based on this, a task allocation management method according to an embodiment of the present application is provided to solve the technical problem that the existing task allocation scheme has low task allocation efficiency and affects the user experience.
[0030] FIG1 shows a schematic diagram of the system structure of a task allocation management system provided by an embodiment of the present application. As shown in FIG1 , the task allocation management system provided by this solution includes a front-end service (proxy), a task allocation service (coreserver) and a cache service (DB&cache). The task allocation management system provided by this solution adopts a distributed deployment of multiple regions and multiple computer rooms (the figure exemplarily shows a task allocation management system deployed based on two computer rooms). Each computer room can be configured with several front-end services and task allocation services. For tasks or first users of the same type or category, the task allocation service can have a main point and a main computer room logic. For example, one of the multiple task allocation services arranged in a distributed manner is used as the main point of the task allocation service, and the computer room where the main point of the task allocation service is located is the main computer room.
[0031] The cache service can be a high-speed cache that stores user and task-related data and asynchronously synchronizes it with cache services in other computer rooms to ensure data consistency. In one embodiment, the task allocation and management system provided by this solution can also include message middleware (message queue) and business services related to processing tasks. Business services can be deployed synchronously in various computer rooms, and each computer room can be configured with its own cache service and message middleware. The cache services and message middleware data in different computer rooms can be asynchronously synchronized with each other.
[0032] User terminals access the task allocation management system at the nearest data center. All user operations (such as requesting or claiming tasks) are first validated by the front-end service and then forwarded to the task allocation service for processing. The task allocation service manages the status of users and tasks, handles business logic such as task requests, task dispatches, and task claims, maintains the complete task lifecycle, and interacts with related business services. The task allocation service has a primary location and a main data center, similar to service partitioning. The task allocation service can be isolated by task category rather than by region. Optionally, as user volume increases, more partitions can be added by dividing task categories, enabling parallel expansion of the task allocation service. The message middleware records task status changes for asynchronous business use and consumption, effectively reducing service coupling. Business services are the services that actually provide business needs after task allocation, such as call services, consumption services, rating services, and live broadcast and microphone game services.
[0033] The task assignment service provided in this solution is configured to obtain pending tasks and a list of online users from a cache service, and to acquire a first distributed lock and a second distributed lock in the cache service based on the task identifier of the pending task and the list of online users, respectively. The online user list is updated by the task assignment service based on the online users who can receive tasks.
[0034] The task assignment service is further configured to determine multiple first users from the online user list, unlock the second distributed lock in the cache service, update the status of the pending tasks and the multiple first users' tasks to dispatched in the cache service, and unlock the first distributed lock in the cache service. The task assignment service is further configured to send task dispatch information to the front-end service based on the pending tasks and the multiple first users.
[0035] The front-end service is configured to send task dispatch information to the plurality of first users, so that the plurality of first users can receive the tasks to be processed based on the task dispatch information.
[0036] In the above, the task allocation service obtains the pending tasks and the online user list from the cache service, and respectively sets the first distributed lock and the second distributed lock in the cache service according to the task identifier of the pending task and the online user list. After determining multiple first users from the online user list, the second distributed lock is unlocked, and the pending tasks and the task status of each first user are updated in the cache service. Then, the front-end service sends task dispatch information to the multiple first users so that each first user can receive the pending tasks based on the task dispatch information. Multiple first users are selected from the online user list to dispatch the pending tasks. Each first user can choose to receive the task according to demand, and the number of users who can preempt each pending task is limited, thereby improving the efficiency of task allocation. In addition, the first distributed lock can ensure the consistency of the task status of tasks and related users in distributed concurrent scenarios, effectively ensuring the uniqueness and mutual exclusivity of task allocation. The second distributed lock can reduce the uneven instantaneous task allocation probability caused by concurrent task allocation, thereby improving the quality of task allocation. The front-end service, task allocation service, cache service, message middleware and business service of the task allocation management system provided by this solution can provide functions related to the task allocation management method provided in the embodiment of this application and achieve corresponding technical effects. Please refer to the task allocation management method provided in the embodiment of this application for specific details, and this solution will not go into details.
[0037] FIG2 shows a flowchart of a task allocation management method provided by an embodiment of the present application. The task allocation management method provided by an embodiment of the present application can be applied to the task allocation management system provided by the above embodiment. The task allocation management system includes a distributed front-end service, a task allocation service, and a cache service. The task allocation management method provided by this solution can be integrated into a task allocation management device. Referring to FIG2, the task allocation management method includes:
[0038] S110: The task allocation service obtains the pending tasks and the online user list from the cache service, and respectively sets the first distributed lock and the second distributed lock in the cache service according to the task identifier of the pending task and the online user list. The online user list is updated by the task allocation service based on the online users who can receive tasks.
[0039] This solution provides an online user list that records online users who can receive tasks. This online user list is updated by the service allocation service based on the number of online users who can receive tasks. The service allocation service can maintain multiple online user lists, and different online user lists can be divided based on different task types or categories. That is, the online user list of a task type or category records the online users who can receive tasks of that type or category. Multiple task allocation services can also be partitioned using predefined hash rules. The task allocation service master node of each partition can periodically update the online user list corresponding to the partition, adding online and idle users to the online user list in real time and removing offline users.
[0040] The online user list provided by this solution is recorded in the cache service and maintained and managed by the corresponding task allocation service. The cache service provided by this solution also records pending tasks waiting to be assigned for execution (which can be identified based on the task identifier of the pending task). The task allocation service of each partition can retrieve active pending tasks from the cache service and execute the allocation of pending tasks.
[0041] Exemplarily, the task allocation service provided by this solution periodically obtains pending tasks and a list of online users from the cache service, and respectively sets a first distributed lock and a second distributed lock in the cache service based on the task identifier of the pending task and the list of online users, that is, sets a first distributed lock in the cache service based on the task identifier of the pending task, and sets a second distributed lock in the cache service based on the list of online users, wherein the task identifier of the pending task is generated by the task allocation service in response to a task request from a third user (i.e., the user requesting the task) and saved to the cache service.
[0042] In one embodiment, the task allocation service master can assign pending tasks to specific task allocation services for execution. Specifically, the task allocation service master periodically retrieves active pending orders from the cache service, selects pending tasks with an unassigned and non-timed-out status, and then assigns the pending tasks to other task allocation services (e.g., other task allocation services in the same data center) for processing.
[0043] After receiving a pending task assigned by the task assignment service master, the task assignment service obtains a pre-stored list of online users who can receive the task from the cache service and uses the received task identifier of the pending task to place a first distributed lock in the cache service. The task assignment service obtains the dispatch data for the pending task from the cache service and, upon determining that the task status of the pending task is unassigned, places a second distributed lock in the cache service based on the online user list (e.g., using the list identifier of the online user list to place a second distributed lock in the cache service).
[0044] In this solution, the task allocation process is managed by the backend. The task allocation timer interval, the number of tasks to be dispatched at a time, and the number of users to whom tasks are dispatched can all be dynamically adjusted based on business conditions. For example, when the number of tasks is excessive, the number of tasks to be dispatched at a time can be limited, allowing subsequent tasks to queue and ensure that previously requested tasks are processed first. When the number of users available to receive tasks is low, the number of users to whom a task is dispatched can be dynamically reduced to ensure that more tasks can be processed. Conversely, the number of users to whom a task is dispatched can be increased, improving the efficiency of task acceptance. All subsequent logic involving task status modifications can be handled in the server room, ensuring that the first distributed lock, which relies on the cache service, is in effect. This first distributed lock effectively ensures the consistency of task and related user data in distributed concurrent scenarios, ensuring uniqueness (i.e., one task is bound to one server and one server) and mutual exclusivity (i.e., a user cannot reuse the service while a task is in effect), ensuring the correct and orderly execution of services. Furthermore, a second distributed lock is applied to the online user list to effectively prevent uneven instantaneous task allocation probabilities caused by concurrent task dispatching.
[0045] S120: The task allocation service determines multiple first users from the online user list, unlocks the second distributed lock in the cache service, updates the task status of the pending tasks and the multiple first users to dispatched in the cache service, and unlocks the first distributed lock in the cache service.
[0046] After successfully acquiring the first and second distributed locks in the cache service, the task allocation service identifies multiple first users from the online user list and, after successfully identifying the multiple first users, unlocks the second distributed lock in the cache service. In one embodiment, the task allocation service updates the status of the pending tasks and the tasks of the multiple identified first users to dispatched in the cache service and unlocks the first distributed lock in the cache service.
[0047] As shown in a task state transition diagram provided in FIG3 , the task states provided by this solution include 6 types: unassigned, dispatched, received, confirmed, processed, and ended. The task state can indicate the task and user's task processing status or progress. For example, an unassigned pending task is a task created in response to a user's task request. The unassigned pending task can be automatically assigned by the system so that the task state of the pending task is converted to dispatched. If the unassigned pending task is canceled by the service recipient (third user), or multiple dispatches time out, the task state of the pending task is converted to ended. For tasks in the dispatched state, if no one receives it after the timeout, it is converted to the unassigned state. If the service recipient (second user) receives the dispatched pending task, the pending task is converted to received. When the service recipient confirms (for example, automatically confirms) that the pending task has been received, the task state of the pending task is converted to confirmed. If it is not confirmed after the timeout, it is converted to ended. For confirmed pending tasks, the business service is called to process the pending tasks, and the status is updated to processed after the processing is completed. If the pending task is not successfully processed within the time limit, it is converted to ended, thereby realizing the conversion between different task states and facilitating the entire life cycle of task allocation management.
[0048] In one embodiment, when the task assignment service provided by this solution determines multiple first users from the online user list, it may be: determining the latest delivery time of each online user in the online user list, and determining multiple first users from the multiple online users based on the latest delivery time.
[0049] The cache service provided by this solution records the latest delivery time of each online user in its online user list. This latest delivery time is updated by the task allocation service based on the corresponding latest delivery time in the online user list of multiple first users determined from the online users. This means that the latest delivery time recorded for each first user in the cache service is updated, lowering the task dispatch priority of the first user after the task is dispatched. After successfully acquiring the first and second distributed locks in the cache service, the task allocation service determines the latest delivery time of each online user in the online user list and determines a set number of first users in ascending order of the minimum delivery time, that is, giving priority to online users whose last task was dispatched more recently as first users. This solution balances the time users wait for task dispatch by determining the multiple first users corresponding to the task dispatched based on the latest delivery time of the online users, reduces situations where users wait too long, and ensures user experience.
[0050] S130: The task allocation service sends task dispatch information to the front-end service based on the pending tasks and the multiple first users.
[0051] S140: The front-end service sends task dispatch information to the plurality of first users, so that the plurality of first users can receive the pending tasks based on the task dispatch information.
[0052] After determining multiple first users, the task assignment service asynchronously sends task dispatch information to the front-end service based on the pending tasks and multiple first users. After receiving the task dispatch information sent by the task assignment service, the front-end service asynchronously sends the task dispatch information to the multiple first users determined above. Among them, after receiving the task dispatch information, the user terminal corresponding to each first user can display the task dispatch information (for example, a task collection prompt corresponding to the task dispatch information can be popped up in the form of an information pop-up window), and the first user can choose whether to collect the pending task based on the task dispatch information, and when it is necessary to collect the pending task, the user can send a task collection request to the front-end service to collect the pending task (this solution defines the user who sends the task collection request as the second user), and the front-end service notifies the task assignment service to respond to the user's task collection request.
[0053] In the above, the task allocation service obtains the pending tasks and the online user list from the cache service, and respectively sets the first distributed lock and the second distributed lock in the cache service according to the task identifier of the pending task and the online user list. After determining multiple first users from the online user list, the second distributed lock is unlocked, and the pending tasks and the task status of each first user are updated in the cache service. Then, the front-end service sends task dispatch information to the multiple first users so that each first user can receive the pending tasks based on the task dispatch information. Multiple first users are selected from the online user list to dispatch the pending tasks. Each first user can choose to receive the task according to demand, and the number of users who can preempt each pending task is limited, thereby improving the efficiency of task allocation. In addition, the first distributed lock can ensure the consistency of the task status of tasks and related users in distributed concurrent scenarios, effectively ensuring the uniqueness and mutual exclusivity of task allocation. The second distributed lock can reduce the uneven instantaneous task allocation probability caused by concurrent task allocation, thereby improving the quality of task allocation.
[0054] In one embodiment, as shown in a task receiving process diagram provided in FIG4 , the task allocation management method provided by this solution further includes, after the front-end service sends task dispatch information to multiple first users:
[0055] S210: The front-end service receives a task receiving request sent by a second user based on the task dispatching information, and forwards the task receiving request to the task allocation service, where the second user is one or more of the multiple first users.
[0056] S220: Based on the task claiming request, the task assignment service updates the pending task and the task status of the second user to claimed in the cache service, and removes the second user from the online user list.
[0057] S230: The task allocation service deletes the delivery record of the pending task from the cache service, and notifies the second user through the front-end service that the pending task has been successfully received.
[0058] After the front-end service sends task dispatch information to multiple first users, each first user can choose whether to receive the task based on the task dispatch information, and when they need to receive the task, they can send a task collection request to the front-end service. At this time, the first user who sends the task collection request is the second user, that is, the second user provided by this solution can be one or more of the multiple first users determined above. Each first user can send a task collection request to the front-end service as a second user to preempt the pending task.
[0059] For example, upon receiving a task claim request from the second user based on the task dispatch information, the front-end service forwards the task claim request to the task allocation service (e.g., the task allocation service in the computer room). Optionally, upon receiving a task claim request from the second user, the front-end service may perform a business verification on the task claim request based on pre-defined verification logic, and forward the task claim request to the task allocation service after the business verification passes.
[0060] After receiving the task claim request, the task assignment service updates the pending task corresponding to the new task claim request and the task status of the second user to claimed in the cache service, and removes the second user from the online user list. Before the pending task is completed, the second user will no longer participate in the dispatch process of new pending tasks, effectively reducing the situation where users repeatedly claim tasks.
[0061] In one embodiment, the task assignment service deletes the dispatch record of the pending task from the cache service. The pending task is no longer dispatched to other users during normal processing, thereby reducing the duplication of tasks. The task assignment service also notifies the second user of the successful receipt of the pending task by notifying the front-end service. The front-end service asynchronously notifies the second user of the successful receipt of the pending task. Optionally, the task assignment service may also notify the third user who initiated the task request through the front-end service that the corresponding pending task has been received, making it easier for the third user to understand the processing status of the pending task.
[0062] Optionally, since only one second user can successfully claim the pending task, for the second user who fails to claim the pending task first, the task allocation service can notify the second user of the failure to claim the task through the front-end service. At the same time, when the second user successfully claims the pending task, the task allocation service asynchronously sends a task status update to the front-end service, and the front-end service asynchronously notifies the first user (the first user who did not choose to claim the task) that the task delivery is cancelled. After receiving the task delivery cancellation information, the user terminal can automatically delete / hide the task delivery information of the corresponding task. Optionally, from the time the second user receives the notification of successful claiming of the pending task until the entire task claiming process is completed, the user terminal receiving the task can periodically send heartbeat checks to the front-end service to inquire about the progress of task claiming.
[0063] This solution allocates pending tasks to the second user in response to the task collection request issued by the second user, and updates the pending tasks and the task status of the second user, effectively reducing the situation where the second user repeatedly collects tasks and the pending tasks are repeatedly distributed, thereby improving the efficiency and quality of task allocation.
[0064] In one embodiment, the task assignment service provided by this solution updates the status of the pending task and the second user's task to "claimed" in the cache service based on the task claim request, and removes the second user from the online user list, including:
[0065] S221: Based on the task claim request, the task allocation service grabs the third distributed lock and the fourth distributed lock in the cache service according to the task identifier of the task to be processed and the second user identifier of the second user, respectively. If the grabbing of the third distributed lock and the fourth distributed lock is successful, the task allocation service obtains the fifth distributed lock in the cache service according to the task identifier of the task to be processed.
[0066] S222: The task allocation service updates the pending task and the task status of the second user to received in the cache service, removes the second user from the online user list, and unlocks the fifth distributed lock in the cache service.
[0067] For example, after receiving a task claim request, the task allocation service attempts to grab the third distributed lock and the fourth distributed lock in the cache service based on the task identifier of the pending task and the second user identifier of the second user, respectively. Specifically, the task allocation service first attempts to grab the third distributed lock in the cache service using the task identifier of the pending task. After successfully grabbing the third distributed lock, the task allocation service then attempts to grab the fourth distributed lock in the cache service using the second user identifier. Only after successfully grabbing both the third and fourth distributed locks can the subsequent task claim process proceed. At this point, the task allocation service acquires the fifth distributed lock in the cache service based on the task identifier of the pending task.
[0068] After the task allocation service sets the fifth distributed lock in the cache service, it can pull the delivery record of the pending task from the cache service, and determine whether the second user is one of the corresponding multiple first users based on the delivery record. If so, the task allocation service will update the task status of the pending task, the second user, and the third user who requested the pending task to received in the cache service, remove the second user from the online user list to reduce repeated dispatches to the second user, and unlock the fifth distributed lock in the cache service.
[0069] This solution effectively reduces the situation where a task is claimed by multiple users through the third distributed lock, and effectively reduces the situation where a user claims multiple tasks at the same time through the fourth distributed lock, effectively preventing users from maliciously placing orders. Among them, the third and fourth distributed locks use non-blocking locking (that is, if the user fails to claim the task, it will be directly considered as a failed operation and returned) and automatic unlocking upon expiration, while the fifth distributed lock is a blocking locking (multiple attempts until the lock is successful), which improves the success rate and efficiency of the second user's task claiming. At the same time, locking the task to be processed first and then locking the second user ensures that if the second user with a slower hand speed fails to grab the previous task, he can immediately claim it if there are subsequent tasks, reducing the situation where the user fails to grab the previous task and has to wait until the user lock expires before grabbing the next task, thereby improving the user experience.
[0070] In one embodiment, as shown in a task request process diagram provided in FIG5 , the task allocation management method provided by this solution further includes:
[0071] S101: When the front-end service receives a task request from a third user, it forwards the task request to a task allocation service based on a consistent hashing method according to a third user identifier of the third user.
[0072] S102: The task allocation service sets a queue lock based on the third user identifier of the third user based on the task request, adds a pending task to the cache service, and initializes the task status of the third user and the pending task to unassigned.
[0073] When a third-party user needs to request a task, they can send a task request to the front-end service through the corresponding user terminal. For example, in a takeout scenario, the diner, as the third-party user, can use the corresponding ordering application to send a task request to the front-end service for food delivery. Or in a live voice chat scenario, the host, as the third-party user, can use the live broadcast application to send a task request to the front-end service to connect with other hosts.
[0074] Illustratively, when the front-end service receives a task request from a third user, it may select a task assignment service based on consistent hashing according to a third user identifier of the third user, and forward the task request to the selected task assignment service.
[0075] After receiving the task request, the task allocation service may set a queue lock based on the third user's third user identifier and add a pending task corresponding to the task request to the cache service. In one embodiment, the task allocation service adds the third user and the pending task's task status to the cache service, initializes the task status of the third user and the pending task to unassigned, and releases the queue lock.
[0076] This solution effectively serializes task requests from individual users by using consistent hashing to select a task assignment service based on a third-party user identifier and by enqueuing a lock on that third-party identifier. This prevents cache synchronization delays in concurrent scenarios, leading to duplicate user requests and malicious order manipulation. The user and task identifiers provided by this solution are both unique and non-duplicate, effectively preventing task assignment anomalies. Third-party users are also bound to a single pending task, ensuring uniqueness and mutual exclusivity in task assignments. Pending tasks generated in response to third-party task requests are recorded in a cache, transforming the previously synchronous, highly concurrent task request, dispatch, and claim operations into asynchronous ones. This also facilitates subsequent control of the task dispatch rate based on task volume, reducing server pressure. Furthermore, user terminals can send heartbeat checks to the front-end service to verify task status. Even if notifications of subsequent task status changes are lost, the user terminal can detect the anomaly through the heartbeat check and proactively retrieve the latest status to correct the problem.
[0077] In one embodiment, as shown in a task confirmation flow diagram provided in FIG6 , the task allocation management method provided in this solution, after the front-end service sends task dispatch information to multiple first users, further includes:
[0078] S310: When receiving the task confirmation request from the third user, the front-end service forwards the task confirmation request to the task allocation service.
[0079] S320: The task allocation service sets a sixth distributed lock in the cache service according to the third user identifier of the third user based on the task confirmation request.
[0080] S330: The task allocation service calls the business service corresponding to the pending task, and executes the pending task through the business service.
[0081] S340: When the pending task is completed, the task allocation service updates the task status of the pending task, the third user, and the second user who receives the pending task to processed, and unlocks the sixth distributed lock in the cache service.
[0082] After the third user initiates a task request to the front-end service and receives a notification from the front-end service indicating that the pending task has been claimed, the third user's user client may send a task confirmation request to the front-end service. Optionally, the third user's user client may automatically send a task confirmation request to the front-end service after receiving a notification from the front-end service indicating that the pending task has been claimed.
[0083] Illustratively, after receiving the task confirmation request from the third user, the front-end service forwards the task confirmation request to the task allocation service (e.g., the task allocation service in the computer room). After receiving the task confirmation request, the task allocation service sets a sixth distributed lock in the cache service based on the third user's third user identifier.
[0084] In one embodiment, the task assignment service calls the business service corresponding to the pending task and executes the pending task through the business service. In one embodiment, when the task assignment service calls the business service corresponding to the pending task and executes the pending task through the business service, the task assignment service may obtain the task status of the pending task from the cache service and, if the task status of the pending task is claimed, update the task status of the pending task, the third user, and the second user who claimed the pending task to confirmed.
[0085] The Task Assignment Service pulls the pending task's task status from the Cache Service and checks whether the pending task's task status is Claimed. If the pending task's task status is confirmed as Claimed, the cache service updates the task status of the pending task, the corresponding third user, and the second user who claimed the pending task to Confirmed.
[0086] In one embodiment, when the pending task is completed, the task allocation service updates the task status of the pending task, the third user, and the third user who receives the pending task to processed in the cache service, and unlocks the above-mentioned sixth distributed lock in the cache service. It needs to be explained that there is a certain time interval between the third user requesting the task and the second user receiving the task. After the second user successfully notifies the third user of the task, the third user's confirmation step is to ensure that the third user is still online, the network is normal, etc., to ensure the normal processing of the pending task. And in the user confirmation process, the task status will change twice (from received to confirmed, from confirmed to processed), which can effectively distinguish whether the call to the business service is successful, so as to handle abnormal tasks in a timely manner.
[0087] It should be explained that this solution notifies the first user of the task automatically after the task is requested, and actively displays a pop-up window on the first user's user terminal, providing the user with the right to independently choose whether to receive the task, and selects the second user on a first-come, first-served basis to improve service efficiency. By separating the two steps of requesting and receiving tasks, overall control of tasks is achieved, the processing speed of tasks is dynamically adjusted, the effect of shaving peaks and filling valleys is achieved, and service performance is optimized. By dynamically adjusting the number of tasks and / or the number of users to whom tasks are dispatched in a single task dispatch operation, the task dispatch ratio is dynamically adjusted according to business conditions, thereby improving the success rate and efficiency of task collection for the service provider.
[0088] This solution also defines the task state flow and transition relationships and maintains them throughout the entire process, ensuring that the entire task lifecycle is traceable and controllable, enabling repeated task dispatch in the event of a timeout, and automatic repair of anomalies. Furthermore, through the established routing rules, designated distributed lock operations, and specific business verification, it ensures that neither service providers nor service demanders can maliciously manipulate orders, ensuring a normal user experience. A chronological priority queue is used to record online users eligible for tasks, and specific logic is used to maintain and update queue data to ensure that the probability of service providers receiving tasks is close, thereby improving the fairness of the system. The adoption of a classification and partitioning approach facilitates the parallel expansion of task allocation management, eliminates regional isolation between users, and supports the global strategic deployment of the business.
[0089] In one embodiment, the task allocation management method provided by this solution further includes, after the task allocation service sends task dispatch information to the front-end service based on the pending tasks and the plurality of first users:
[0090] S410: The task allocation service periodically determines from the cache service a first timed-out task whose task status is dispatched, and sets a seventh distributed lock in the cache service according to the task identifier of the first timed-out task.
[0091] S420: The task allocation service updates the task status of the first timed-out task and the third user corresponding to the first timed-out task to unassigned in the cache service, deletes the delivery record of the first timed-out task from the cache service, and unlocks the seventh distributed lock in the cache service.
[0092] Exemplarily, the task allocation service periodically retrieves active pending tasks from the cache service, determines the task status of the pending tasks, identifies pending tasks with a task status of "delivered," and selects pending tasks whose duration in the "delivered" task status exceeds a set time threshold (e.g., pending tasks that have timed out and are not claimed by anyone), and identifies these selected pending tasks as first timed-out tasks. In one embodiment, the task allocation service places a seventh distributed lock in the cache service based on the task identifier of the first timed-out task.
[0093] Optionally, the first timed-out task can be determined by the task allocation service master point and assigned to other task allocation services, that is, the task allocation service master point periodically retrieves active pending tasks from the cache service, selects the first timed-out task from these pending tasks, and randomly assigns it to other task allocation services in the main computer room for processing, and other task allocation services set the seventh distributed lock and subsequent processes in the cache service according to the task identifier of the first timed-out task.
[0094] In one embodiment, the task allocation service pulls the task status of the first timeout task from the cache service, and further confirms whether the task status of the first timeout task is dispatched. When determining whether the task status of the first timeout task is dispatched, the task allocation service updates the task status of the first timeout task and the third user corresponding to the first timeout task to unassigned in the cache service, deletes the dispatch record of the first timeout task from the cache service, and unlocks the seventh distributed lock in the cache service to implement the timeout reset processing of the first timeout task. Optionally, after completing the timeout reset processing of the first timeout task, the third user can be asynchronously notified of the change in task status through the preceding process, and the corresponding first user can be asynchronously notified of the cancellation of the task dispatch. This solution resets the pending task with a task status of dispatched and timed out to an unassigned pending task. The pending task can be dispatched again the next time the task allocation timer is executed, thereby improving the order acceptance rate for tasks, ensuring that the user's task request is processed in a timely manner, and improving the user experience.
[0095] In one embodiment, the task allocation management method provided by this solution further includes, after the task allocation service sends task dispatch information to the front-end service based on the pending tasks and the plurality of first users:
[0096] S510: The task allocation service periodically determines from the cache service a second timeout task whose task status is unassigned, received, or confirmed, and sets an eighth distributed lock in the cache service according to the task identifier of the second timeout task.
[0097] S520: The task allocation service updates the task status of the second timed-out task to ended in the cache service, deletes the task status of the second user and the third user corresponding to the second timed-out task, and the dispatch record of the second timed-out task, and unlocks the eighth distributed lock in the cache service.
[0098] Exemplarily, the task allocation service periodically retrieves active pending tasks from the cache service, determines the task status of the pending tasks, identifies pending tasks with a task status of unassigned, claimed, or confirmed, and selects pending tasks whose duration in the unassigned, claimed, or confirmed task status exceeds a set time threshold. These selected pending tasks are then identified as second timed-out tasks. In one embodiment, the task allocation service places an eighth distributed lock in the cache service based on the task identifier of the second timed-out task.
[0099] Optionally, the second timeout task can be determined by the task allocation service main point and assigned to other task allocation services, that is, the task allocation service main point periodically retrieves active pending tasks from the cache service, filters out the second timeout task from these pending tasks, and randomly assigns it to other task allocation services in the main computer room for processing, and other task allocation services set the eighth distributed lock and subsequent processes in the cache service according to the task identifier of the second timeout task.
[0100] In one embodiment, the task allocation service pulls the task status of the second timeout task from the cache service, removes the second timeout task whose task status cannot be canceled as processed or completed, and then updates the task status of the second timeout task to completed in the cache service, deletes the task status of the second user and the third user corresponding to the second timeout task in the cache service, deletes the dispatch record of the second timeout task in the cache service, and unlocks the eighth distributed lock in the cache service to complete the timeout cancellation processing of the second timeout task. Optionally, after completing the timeout cancellation processing of the second timeout task, the cancellation of the corresponding tasks of the first user and the third user can be asynchronously notified through the preceding process.
[0101] Unassigned second timeout tasks are caused by normal business processes, while claimed and confirmed second timeout tasks are caused by abnormal conditions. When an unassigned second timeout task occurs, the second timeout task will be canceled to notify the user that no one has claimed the task, prompting the user to try again later. This also prevents repeated task dispatching and wastes server resources. Claimed second timeout tasks are mainly caused by the second user successfully claiming the task, but the third user not confirming it for a long time due to some abnormality, such as unstable network or exiting the program after placing an order.
[0102] The second timeout for confirmed timeout tasks is caused by the failure of the business service to start the service even though both users are ready. The second timeout for claimed and confirmed timeout tasks is caused by either a user anomaly or a service anomaly. In both cases, both users are already bound to the task, and the second user is no longer able to claim other tasks. Canceling the task notifies the third user of the service anomaly and releases the second user, allowing them to claim new tasks. After the task is canceled, the task status of both users is deleted, allowing the third user to request the task again. The second user will be re-added to the online user list by the task allocation service to participate in the next task distribution, ensuring a better user experience.
[0103] In one embodiment, the task allocation management method provided by this solution further includes, after the task allocation service sends task dispatch information to the front-end service based on the pending tasks and the plurality of first users:
[0104] S610: When receiving a task termination request from a third user, the front-end service forwards the task termination request to the task allocation service.
[0105] S620: The task allocation service sets a ninth distributed lock in the cache service according to the task identifier of the task to be processed based on the task termination request.
[0106] S630: The task allocation service notifies the business service corresponding to the pending task to stop executing the pending task, updates the task status of the pending task to ended in the cache service, deletes the task status of the second user and the third user corresponding to the pending task, and unlocks the ninth distributed lock in the cache service.
[0107] When the third user needs to terminate the execution of the service request issued by it, it can send a task termination request to the front-end service. Upon receiving the task termination request from the third user, the front-end service forwards the task termination request to the task allocation service (e.g., the task allocation service in the computer room).
[0108] After receiving the task termination request, the task allocation service sets the ninth distributed lock in the cache service according to the task identifier of the pending task. In one embodiment, the task allocation service pulls the task status of the corresponding pending task from the cache service, determines whether the task status is processed, and the task allocation service notifies the business service corresponding to the pending task to stop executing the pending task. Among them, when the task status is processed, stopping the execution of the pending task means stopping the processing process of the pending task (at this time, the second user has already claimed the task and executed it). When the task status is not processed, the pending task is directly canceled (at this time, the second user has not claimed the task).
[0109] In one embodiment, the task allocation service updates the task status of the pending task to "ended" in the cache service, deletes the task status of the second user and the third user corresponding to the pending task, and unlocks the ninth distributed lock in the cache service to complete the termination of the pending task. Optionally, after completing the termination of the pending task, the termination of the task corresponding to the first user and the third user can be asynchronously notified through the preceding process. By responding to the task termination request of the third user and locking the pending task with the ninth distributed lock, the situation in which concurrent operations modify task-related information is avoided, the pending task is terminated in a timely manner, and the user experience is guaranteed.
[0110] It should be explained that the user identifiers and task identifiers used in this solution are both globally unique. By performing consistent hashing and queuing lock operations on user task requests, the consistency of task request operations can be guaranteed by relying on local cache. In addition to responding to task requests, all subsequent sensitive operations and state modifications can be processed in the main computer room. Distributed locks are added to the core processes. Even with a non-strongly consistent multi-cluster cache deployment, data consistency can still be guaranteed in concurrent scenarios. The task states provided by this solution have a strict state flow relationship, and each task state has a corresponding timeout check mechanism to ensure that tasks will eventually reach the completed state, and tasks in abnormal states can also be detected and repaired. The task allocation service adopts a multi-computer room multi-instance deployment. If the task allocation service master node fails, another task allocation service node can still quickly take over as the new master node. To avoid data inconsistencies caused by cache synchronization across computer rooms due to frequent switching of the task allocation service master node, a specific task allocation service master node selection logic and service operation and maintenance methods are used to ensure that the task allocation service master node is located in a fixed computer room. User-related operations, such as requesting and receiving tasks, are subject to various verification and locking restrictions to ensure that neither service demanders nor service providers can maliciously manipulate orders, impacting the fairness of the system and disrupting the user experience of other normal users. Furthermore, most distributed lock operations are unlocked at the end of the process or upon error interruption, ensuring that service anomalies or logical errors do not affect user continued use. Furthermore, all distributed locks can be set with a short automatic expiration time, ensuring that even in the event of a serious system failure, they can be restored to service within a short period of time, without permanently blocking the task status flow, and ensuring the correct allocation and execution of tasks.
[0111] The embodiment of the present application also provides a task allocation management device, which can integrate the task allocation management system provided by the embodiment of the present application. Figure 7 is a structural diagram of a task allocation management device provided by the embodiment of the present application. Referring to Figure 7, the task allocation management device includes: an input device 73, an output device 74, a memory 72 and one or more processors 71; the memory 72 is used to store one or more programs; when one or more programs are executed by one or more processors 71, the one or more processors 71 implement the task allocation management method provided by the above embodiment. The task allocation management system, device and computer provided above can be used to execute the task allocation management method provided by any of the above embodiments, and have corresponding functions and beneficial effects.
[0112] The embodiments of the present application also provide a non-volatile storage medium that stores computer-executable instructions, which are used to execute the task allocation management method provided in the above embodiments when executed by a computer processor. Of course, the non-volatile storage medium that stores computer-executable instructions provided in the embodiments of the present application, whose computer-executable instructions are not limited to the task allocation management method provided above, can also execute the relevant operations in the task allocation management method provided in any embodiment of the present application. The task allocation management system, device and storage medium provided in the above embodiments can execute the task allocation management method provided in any embodiment of the present application. For technical details not described in detail in the above embodiments, please refer to the task allocation management method provided in any embodiment of the present application.
[0113] Based on the above embodiments, the embodiments of the present application also provide a computer program product. The technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer program product is stored in a storage medium and includes a number of instructions for enabling a computer device, a mobile terminal or the processor therein to execute all or part of the steps of the task allocation management method provided in each embodiment of the present application.
Claims
1. A task allocation management method, applied to a task allocation management system, wherein: The task allocation management system includes a distributed front-end service, a task allocation service and a cache service, and the task allocation management method includes: The task allocation service obtains the pending tasks and the online user list from the cache service, and respectively sets a first distributed lock and a second distributed lock in the cache service according to the task identifier of the pending tasks and the online user list, and the online user list is updated by the task allocation service based on the online users who can receive tasks; The task allocation service determines a plurality of first users from the online user list, unlocks the second distributed lock in the cache service, updates the task status of the pending task and the plurality of first users to dispatched in the cache service, and unlocks the first distributed lock in the cache service; The task allocation service sends task dispatch information to the front-end service based on the to-be-processed tasks and the plurality of first users; The front-end service sends the task dispatching information to the multiple first users, so that the multiple first users can receive the to-be-processed tasks based on the task dispatching information.
2. The task allocation management method according to claim 1, wherein: The task assignment service determines a plurality of first users from the online user list, including: The task assignment service determines the latest delivery time of each online user in the online user list, and determines a plurality of first users from the plurality of online users based on the latest delivery time.
3. The task allocation management method according to claim 1, wherein: After the front-end service sends the task dispatching information to the multiple first users, the method further includes: The front-end service receives a task claiming request issued by a second user based on the task dispatching information, and forwards the task claiming request to the task allocation service, where the second user is one or more of the plurality of first users; Based on the task claiming request, the task assignment service updates the task status of the pending task and the second user to claimed in the cache service, and removes the second user from the online user list; The task allocation service deletes the delivery record of the pending task from the cache service, and notifies the second user through the front-end service that the pending task has been successfully received.
4. The task allocation management method according to claim 3, wherein: The task assignment service updates the task status of the pending task and the second user to received in the cache service based on the task receiving request, and removes the second user from the online user list, including: The task allocation service grabs a third distributed lock and a fourth distributed lock in the cache service based on the task claim request according to the task identifier of the task to be processed and the second user identifier of the second user, respectively, and acquires a fifth distributed lock in the cache service according to the task identifier of the task to be processed when the grabbing of the third distributed lock and the fourth distributed lock is successful; The task allocation service updates the pending task and the task status of the second user to received in the cache service, removes the second user from the online user list, and unlocks the fifth distributed lock in the cache service.
5. The task allocation management method according to claim 1, wherein: Before the task allocation service obtains the pending tasks and the online user list from the cache service, the task allocation service further includes: When the front-end service receives a task request from a third user, the front-end service selects, based on a consistent hashing method and according to a third user identifier of the third user, to forward the task request to a task allocation service; The task allocation service sets a queue lock based on the task request and the third user identifier of the third user, adds a pending task to the cache service, and initializes the task status of the third user and the pending task to unallocated.
6. The task allocation management method according to claim 1, wherein: After the front-end service sends the task dispatching information to the multiple first users, the method further includes: When the front-end service receives the task confirmation request sent by the third user, the front-end service forwards the task confirmation request to the task allocation service; The task allocation service places a sixth distributed lock in the cache service according to a third user identifier of the third user based on the task confirmation request; The task allocation service calls the business service corresponding to the task to be processed, and executes the task to be processed through the business service; When the pending task is executed, the task allocation service updates the task status of the pending task, the third user, and the second user who receives the pending task to processed as processed, and unlocks the sixth distributed lock in the cache service.
7. The task allocation management method according to claim 6, wherein: The task allocation service calls the business service corresponding to the task to be processed, and executes the task to be processed through the business service, including: The task allocation service obtains the task status of the pending task from the cache service, and when the task status of the pending task is claimed, updates the task status of the pending task, the third user, and the second user who claims the pending task to confirmed.
8. The task allocation management method according to claim 1, wherein: After the task assignment service sends task dispatch information to the front-end service based on the to-be-processed tasks and the plurality of first users, the task assignment service further includes: The task allocation service periodically determines from the cache service a first timeout task whose task status is that it has been dispatched, and sets a seventh distributed lock in the cache service according to a task identifier of the first timeout task; The task allocation service allocates the first timeout task and the first timeout task corresponding to the task in the cache service. The task status of the third user is updated to unassigned, the dispatch record of the first timed-out task is deleted from the cache service, and the seventh distributed lock is unlocked in the cache service.
9. The task allocation management method according to claim 1, wherein: After the task assignment service sends task dispatch information to the front-end service based on the to-be-processed tasks and the plurality of first users, the task assignment service further includes: The task allocation service periodically determines from the cache service a second timeout task whose task status is unallocated, received or confirmed, and sets an eighth distributed lock in the cache service according to the task identifier of the second timeout task; The task allocation service updates the task status of the second timeout task to ended in the cache service, deletes the task status of the second user and the third user corresponding to the second timeout task, and the dispatch record of the second timeout task, and unlocks the eighth distributed lock in the cache service.
10. The task allocation management method according to claim 1, wherein: After the task assignment service sends task dispatch information to the front-end service based on the to-be-processed tasks and the plurality of first users, the task assignment service further includes: When receiving a task termination request sent by a third user, the front-end service forwards the task termination request to the task allocation service; The task allocation service places a ninth distributed lock in the cache service according to the task identifier of the task to be processed based on the task termination request; The task allocation service notifies the business service corresponding to the pending task to stop executing the pending task, updates the task status of the pending task to ended in the cache service, deletes the task status of the second user and the third user corresponding to the pending task, and unlocks the ninth distributed lock in the cache service.
11. A task allocation management system, wherein: It includes distributed front-end services, task allocation services, and cache services, including: The task allocation service is configured to obtain pending tasks and a list of online users from the cache service, and respectively set a first distributed lock and a second distributed lock in the cache service according to a task identifier of the pending task and the list of online users, wherein the online user list is updated by the task allocation service based on online users who can receive tasks; determine a plurality of first users from the online user list, unlock the second distributed lock in the cache service, and update the task status of the pending task and the plurality of first users to dispatched in the cache service, and unlock the first distributed lock in the cache service; send task dispatch information to the front-end service based on the pending task and the plurality of first users; The front-end service is configured to send the task dispatching information to the multiple first users, so that the multiple first users can receive the to-be-processed tasks based on the task dispatching information.
12. A task allocation management device, wherein: include: memory and one or more processors; The memory is used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the task allocation management method according to any one of claims 1 to 10.
13. A non-volatile storage medium storing computer executable instructions, wherein: The computer executable instructions are used to execute the task allocation management method according to any one of claims 1 to 10 when executed by a computer processor.
14. A computer program product comprising a computer program, wherein: When the computer program is executed by a processor, the task allocation management method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Method and device for dispatching management task orders
CN107909304A
Task allocation method and device, storage medium and program product
CN114707902A
Third-party service management method, device, equipment and medium
CN115439094A
Timed task scheduling method under multi-service cluster of application system
CN115934287A
Task allocation management method and system
CN116596260A
