Data update methods, devices, electronic equipment, and storage media
By using a combination of message queues and dynamic thread pools in the live streaming platform, update messages for the target object are distributed to multiple service nodes for processing, solving the problem of excessive processor utilization on a single service node and achieving more efficient resource allocation and information updates.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-28
- Publication Date
- 2026-03-10
AI Technical Summary
In live streaming platforms, when updating resource allocation information for popular items, a single service node needs to perform a large number of update tasks, resulting in excessive processor utilization and poor operating efficiency.
The update messages of the target object are distributed to multiple service nodes for processing by using a message queue. The combination of message queue and dynamic thread pool is used to select an appropriate processing strategy based on the number of target objects, thereby reducing the processor utilization of the service nodes.
This effectively reduced the processor utilization of service nodes, improved the overall service efficiency, avoided CPU alarm and rate limiting issues, and enhanced the stability and reliability of the service.
Smart Images

Figure CN116095079B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a data updating method, apparatus, electronic device, and storage medium. Background Technology
[0002] With the continuous development of internet technology, live streaming platforms can provide a variety of live streaming formats to meet the diverse needs of the public. For example, the streamer displays interactive items in the item interaction list for viewers to view. When a viewer successfully interacts with an item, the live streaming platform allocates a portion of the item's resources to the streamer based on the item's resource allocation information.
[0003] Currently, when the resource allocation information of an item changes, the live streaming platform needs to update the resource allocation information for that item for each streamer in the database. This update process is typically performed by a single service node. However, for some popular items, hundreds of thousands of streamers may select them for display in the live stream's item interaction list. This results in a single service node needing to perform hundreds of thousands of resource allocation information update tasks, leading to excessively high processor utilization and poor operating efficiency. Summary of the Invention
[0004] This disclosure provides a data update method, apparatus, electronic device, and storage medium, which can reduce the utilization rate of server node processors and improve operating efficiency. The technical solution of this disclosure is as follows:
[0005] According to a first aspect of the present disclosure, a data update method is provided, the method comprising:
[0006] In response to an update request for resource allocation information for a target item, multiple target objects corresponding to the target item are identified. The resource allocation information indicates the amount of resources allocated to the target object when the target item is interacted with through the target object.
[0007] If the number of multiple target objects exceeds the target threshold, an update message for each target object is generated based on the resource allocation information and the multiple target objects. The update message for each target object is stored in the message queue. The update message for the target object indicates the resource allocation information and the target object.
[0008] The update messages for each target object are sent to multiple service nodes in the message queue, so that the multiple service nodes update the amount of resources allocated to each target object based on the received update messages.
[0009] By using the above method, in response to update requests for resource allocation information for a target item, when the number of multiple target objects corresponding to the target item exceeds the target threshold, a large number of update messages are distributed to multiple different service nodes for processing through a message queue, thereby reducing the processor utilization of the service nodes and improving the overall service efficiency.
[0010] In some embodiments, based on the resource allocation information and the plurality of target objects, an update message for each target object is generated, and the update message for each target object is stored in a message queue, including:
[0011] Determine the number of partitions for this message queue;
[0012] Based on the resource allocation information and the multiple target objects, update messages for each target object are generated, and the update messages for each target object are stored in their respective partitions of the message queue.
[0013] In some embodiments, determining the number of partitions for the message queue includes:
[0014] Based on the number of service nodes, determine the number of partitions for the message queue so that the number of partitions for the message queue is equal to the number of service nodes.
[0015] Sending update messages for each target object to multiple service nodes of the message queue includes: sending update messages from each partition to each service node respectively, so that the update messages received by the service node come from the same partition.
[0016] In some embodiments, determining the number of partitions for the message queue includes:
[0017] Based on the multiple object categories corresponding to the multiple target objects, the number of partitions of the message queue is determined so that the number of partitions of the message queue is equal to the number of the multiple object categories. The object category indicates the update method by which the service node updates the amount of resources allocated to the target object.
[0018] The update messages of each target object are stored in the respective partitions of the message queue, including: based on the object category to which each target object belongs, the update messages of each target object are stored in the respective partitions, so that each partition stores the update messages of the target object belonging to different object categories;
[0019] Sending update messages for each target object to multiple service nodes of the message queue includes: sending update messages for each partition to at least one service node corresponding to each partition, so that at least one service node corresponding to the partition updates the amount of resources allocated to the target object corresponding to the partition according to the update method corresponding to the partition.
[0020] In some embodiments, the method further includes:
[0021] Based on the number of the multiple target objects, determine the number of consumer threads for the message queue, so that the number of the multiple target objects is equal to a multiple of the number of consumer threads for the message queue.
[0022] In some embodiments, the method further includes:
[0023] If the number of multiple target objects is less than or equal to the target threshold, a data update task is generated for each target object based on the resource allocation information and the multiple target objects. The data update task is used to update the amount of resources allocated to the target object.
[0024] By creating a dynamic thread pool, data update tasks for each target object are executed.
[0025] In some embodiments, in response to an update request for resource allocation information for a target item, multiple target objects corresponding to the target item are determined, including:
[0026] In response to receiving multiple update requests for resource allocation information within a target time period, the multiple target objects are determined based on the last update request received within the target time period.
[0027] According to a second aspect of the present disclosure, a data updating apparatus is provided, the apparatus comprising:
[0028] The determining unit is configured to perform an update request for resource allocation information for a target item, in response to such an update request, to determine multiple target objects corresponding to the target item, wherein the resource allocation information indicates the amount of resources allocated to the target object when the target item is interacted with through the target object;
[0029] The generation unit is configured to, when the number of multiple target objects exceeds a target threshold, generate an update message for each target object based on the resource allocation information and the multiple target objects, and store the update message for each target object in a message queue. The update message for the target object indicates the resource allocation information and the target object.
[0030] The sending unit is configured to send update messages for each of the target objects to multiple service nodes of the message queue, so that the multiple service nodes update the amount of resources allocated to each of the target objects based on the received update messages.
[0031] In some embodiments, the generating unit includes:
[0032] The sub-determination unit is configured to determine the number of partitions for the message queue;
[0033] The sub-storage unit is configured to generate update messages for each target object based on the resource allocation information and the multiple target objects, and store the update messages for each target object into the respective partitions of the message queue.
[0034] In some embodiments, the sub-determining unit is configured to perform:
[0035] Based on the number of service nodes, determine the number of partitions for the message queue so that the number of partitions for the message queue is equal to the number of service nodes.
[0036] The sub-storage unit is configured to perform the following: send update messages from each partition to each service node, so that the update messages received by the service node come from the same partition.
[0037] In some embodiments, the sub-determining unit is configured to perform:
[0038] Based on the multiple object categories corresponding to the multiple target objects, the number of partitions of the message queue is determined so that the number of partitions of the message queue is equal to the number of the multiple object categories. The object category indicates the update method by which the service node updates the amount of resources allocated to the target object.
[0039] The sub-storage unit is configured to perform the following: based on the object category to which each target object belongs, store the update messages of each target object into each partition, so that each partition stores the update messages of the target object belonging to different object categories;
[0040] The sending unit is configured to send the update messages in each partition to at least one service node corresponding to each partition, so that at least one service node corresponding to the partition updates the amount of resources allocated to the target object corresponding to the partition according to the update method corresponding to the partition.
[0041] In some embodiments, the device further includes:
[0042] The consumer thread number determination unit is configured to determine the number of consumer threads for the message queue based on the number of the multiple target objects, such that the number of the multiple target objects is equal to a multiple of the number of consumer threads for the message queue.
[0043] In some embodiments, the device further includes:
[0044] The task generation unit is configured to generate a data update task for each target object based on the resource allocation information and the multiple target objects when the number of the multiple target objects is less than or equal to the target threshold. The data update task is used to update the amount of resources allocated to the target object.
[0045] The task execution unit is configured to execute data update tasks for each target object by creating a dynamic thread pool.
[0046] In some embodiments, the determining unit is configured to perform:
[0047] In response to receiving multiple update requests for resource allocation information within a target time period, the multiple target objects are determined based on the last update request received within the target time period.
[0048] According to a third aspect of the present disclosure, an electronic device is provided, the electronic device comprising:
[0049] One or more processors;
[0050] Memory used to store the executable program code of the processor;
[0051] The processor is configured to execute the program code to implement the aforementioned data update method.
[0052] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, the computer-readable storage medium comprising: when program code in the computer-readable storage medium is executed by a processor of an electronic device, enabling the electronic device to perform the above-described data update method.
[0053] According to a fifth aspect of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the above-described data update method.
[0054] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0055] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0056] Figure 1 This is a schematic diagram illustrating the implementation environment of a data update method provided in this embodiment of the disclosure;
[0057] Figure 2 This is a flowchart of a data update method provided in an embodiment of this disclosure;
[0058] Figure 3 This is a flowchart of another data update method provided in this embodiment of the disclosure;
[0059] Figure 4 This is a schematic diagram of a data update method provided in an embodiment of this disclosure;
[0060] Figure 5 This is a schematic diagram illustrating the utilization rate of a service node processor according to an embodiment of this disclosure;
[0061] Figure 6 This is a structural block diagram of a data update device provided in an embodiment of this disclosure;
[0062] Figure 7 This is a structural block diagram of a server provided in an embodiment of this disclosure. Detailed Implementation
[0063] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0064] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0065] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this disclosure are authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, resource allocation information involved in the embodiments of this disclosure was obtained under full authorization.
[0066] Figure 1 This is a schematic diagram illustrating the implementation environment of a data update method provided in this embodiment of the disclosure, such as... Figure 1 As shown, the implementation environment includes: terminal 101 and server 102. The terminal 101 and server 102 are directly or indirectly connected through wired or wireless communication, and there is no limitation on this.
[0067] Terminal 101 is at least one of the following devices: smartphone, smartwatch, desktop computer, laptop, virtual reality terminal, augmented reality terminal, wireless terminal, and laptop computer. Terminal 101 can refer to one of multiple terminals; this embodiment only uses terminal 101 as an example. Those skilled in the art will understand that the number of terminals can be more or less.
[0068] In this embodiment, terminal 101 includes a first terminal 1011 and a second terminal 1012. The first terminal 1011 is the terminal used by a first object. A first client runs on the first terminal 1011, allowing the first object to set (including update) resource allocation information for items. This resource allocation information indicates the amount of resources allocated to the second object when the item is interacted with by the second object. Indicatively, the resource amount can be virtual currency or real currency, etc., and is not limited thereto. Interacting with an item refers to any interactive behavior performed on an item, such as trading an item, clicking on an item, or collecting an item, and is not limited thereto. The second terminal 1012 is the terminal used by the second object. A second client runs on the second terminal 1012, allowing the second object to publish (e.g., promote, introduce, or sell) items corresponding to the first object through the second client. Based on the resource allocation information set by the first object, the second object obtains the corresponding resource amount when the item is interacted with by the second object by the third object. For example, both the first and second clients are live streaming clients. The first target is the merchant, the second target is the streamer, and the third target is the viewers in the live stream. The items are commodities (including virtual and physical goods). The merchant sets the resource allocation information for commodity A through the live streaming client, such as 10% of the price of commodity A (100 yuan). The streamer displays commodity A in the item interaction list in the live stream and introduces commodity A for viewers to purchase. When a viewer purchases commodity A, the streamer can obtain the corresponding resource amount (10 yuan) based on the resource allocation information of commodity A. It should be understood that the example here is only illustrative and does not constitute a limitation of this disclosure.
[0069] Server 102 is an independent physical server, a server cluster consisting of multiple physical servers, a distributed file system, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The number of servers 102 can be more or less, and this disclosure does not limit this. Indicatively, server 102 is used to provide background services for clients running on the first terminal 1011 and the second terminal 1012. In this disclosure embodiment, server 102 includes multiple service nodes (i.e., a service cluster, which can be multiple machines, multiple processes on a single machine, or multiple objects of a single process, without limitation), and these multiple service nodes are used to provide data update functions. Schematic illustration: Server 102 is associated with a target database, which stores object information of the second object and resource allocation information of the item. In response to an update request for resource allocation information of the item sent by the first terminal 1101, server 102 updates the information in the target database through a service node; this can also be understood as a disk flushing process. Of course, server 102 may also include other functional servers to provide more comprehensive and diversified services; this embodiment does not limit this.
[0070] Based on the above implementation environment, the data update method provided by the embodiments of this disclosure is described below.
[0071] Figure 2 This is a flowchart of a data update method provided in an embodiment of this disclosure. Figure 2 As shown, the data update method is executed by the server, illustratively by the server's operating system, and includes the following steps 201 to 203.
[0072] In step 201, in response to an update request for resource allocation information for a target item, the server determines multiple target objects corresponding to the target item. The resource allocation information indicates the amount of resources allocated to the target objects when they interact with the target item.
[0073] In this embodiment of the disclosure, the target item refers to any item associated with the first object. For example, the target item is a commodity, including virtual and physical commodities, etc., and is not limited thereto. The target object refers to the second object that publishes the target item, where publishing the target item includes introducing, promoting, or selling the target item. For example, the target object is a live streamer, who displays the target item in the interactive list of the live stream room so that viewers in the live stream room can interact with the target item. The resource allocation information of the target item refers to the amount of resources allocated to the target object when a third object interacts with the target item through the target object after the target object publishes the target item. That is, after a third object interacts with the target item through the target object's publishing channel, the target object can obtain the corresponding amount of resources.
[0074] The specific meanings of the first object, the second object, and the third object mentioned above are as follows: Figure 1 The implementation environment shown will not be described in detail here.
[0075] In step 202, when the number of multiple target objects exceeds the target threshold, the server generates update messages for each target object based on resource allocation information and the multiple target objects, and stores the update messages for each target object in the message queue.
[0076] In this embodiment, the update message for the target object indicates the resource allocation information and the target object. The target threshold is a preset threshold that can be set according to actual needs; for example, the target threshold is 500, and this is not limited. For any target object, the server generates an update message for the target object based on the resource allocation information of the target item and the target object, and stores the update message in a message queue. Illustratively, a message queue (MQ) is a "first-in, first-out" data structure, meaning that data (messages) to be transmitted are placed in a queue, and a queue mechanism is used to realize message delivery. In other words, the producer generates a message and puts it into the queue, and then the consumer processes it. The consumer can pull messages from a specified queue or subscribe to the corresponding queue. Both the producer and consumer implement their functions through multiple service nodes of the server.
[0077] In step 203, the server sends update messages for each target object to multiple service nodes in the message queue, so that the multiple service nodes update the amount of resources allocated to each target object based on the received update messages.
[0078] In this embodiment, the server is associated with a target database, which stores object information of target objects and resource allocation information of the target objects based on the target items. The server sends update messages for each target object to multiple service nodes, and each service node updates the resource allocation information of the target objects based on the target items in the target database based on the received update messages, that is, updates the amount of resources allocated to each target object.
[0079] In some embodiments, the server distributes update messages for each target object equally among multiple service nodes based on an average distribution algorithm. For example, if the message queue contains 10,000 update messages and the number of service nodes is 100, the server divides the 10,000 update messages into 100 equal parts, with each service node receiving 100 update messages. In other embodiments, the server can also employ other algorithms to distribute update messages among multiple service nodes, such as Allocate Message Queue Averagely By Circle, Allocate Message Queue By Config, Allocate Message Queue By Machine Room, and Allocate Message Queue Consistent Hash, etc., which are not limited in this disclosure.
[0080] In summary, in the data update method provided in this embodiment, in response to an update request for resource allocation information for a target item, when the number of multiple target objects corresponding to the target item is greater than a target threshold, a large number of update messages are distributed to multiple different service nodes for processing through a message queue, thereby reducing the processor utilization of the service nodes and improving the overall service operating efficiency.
[0081] The above Figure 2 A brief flowchart of the data update method provided in the embodiments of this disclosure is introduced. The following is based on... Figure 3 The illustrated embodiment provides a detailed description of this data update method.
[0082] Figure 3 This is a flowchart of another data update method provided in an embodiment of this disclosure. For example... Figure 3 As shown, the data update method is executed by the server, illustratively by the server's operating system, and includes the following steps 301 to 307.
[0083] In step 301, in response to an update request for resource allocation information for a target item, the server determines multiple target objects corresponding to the target item. The resource allocation information indicates the amount of resources allocated to the target objects when they interact with the target item.
[0084] In this embodiment of the disclosure, the server and the first terminal used by the first object are connected via wired or wireless means. Indicatively, the first terminal runs a first client, and displays an application interface of the first client. This application interface provides an update function for resource allocation information of items. In response to the first object's update operation on the application interface for resource allocation information of a target item, the first terminal sends an update request to the server.
[0085] In some embodiments, the update request includes item information of the target item. In response to the update request, the server determines multiple target objects corresponding to the target item based on the item information. For example, the item information may be an item identifier ID. The server is associated with a first database that stores object information of each second object and item information published by each second object. Based on the item ID of the target item, the server queries the first database for second objects that have published the target item, thereby determining the multiple target objects corresponding to the target item.
[0086] In some embodiments, in response to receiving multiple update requests for resource allocation information within a target time period, the server determines the multiple target objects based on the last update request received within that target time period. The target time period is a preset time period that can be set according to actual needs; for example, the target time period could be 10 seconds, without limitation. It should be understood that since the number of target objects corresponding to a target item is often large, the server performs many update tasks for resource allocation information. Therefore, the above method can handle only the last update request received within a short period when the resource allocation information of a certain item is frequently updated, avoiding frequent data updates by the server and effectively saving server computing resources. For example, taking a merchant as the first object and a product as the target item, the merchant enters the product's resource allocation information on the application interface, triggering the first terminal to send a corresponding update request to the server. Considering that the merchant may enter the resource allocation information incorrectly, the merchant may update the resource allocation information again within a short period, causing the first terminal to send multiple update requests to the server within a short time. In this case, the above method can effectively avoid frequent data updates by the server within a short period, thus effectively saving server computing resources.
[0087] Schematic illustration: The server is associated with a second database used to store received update requests. For example, this second database could be a Remote Dictionary Server (Redis) database, but this is not limited. In some embodiments, the server stores received update requests in the second database and deduplicates the update requests in the second database at preset time intervals. That is, for update requests regarding resource allocation information for the same item within a target time period, the last received update request within that time period is retained, so that the server can execute subsequent steps based on that update request. For example, if the resource allocation information for a certain item is frequently updated multiple times within a short period (e.g., 10 seconds), changing from status=1 to status=2 and then back to status=1. The server stores multiple update requests for the product in a zset set in the Redis database (with the product ID as the key and resource allocation information as the value). Through a scheduled task (e.g. every 2 seconds), the zset set in the Redis database is deduplicated, and the last resource allocation information of the product within 10 seconds is retained (status=1). This can also be understood as ignoring the data that changes within 10 seconds. Based on the update request of the last resource allocation information, multiple target objects are determined.
[0088] In step 302, the server determines whether the number of multiple target objects is greater than the target threshold.
[0089] In this embodiment, the target threshold is a preset threshold that can be set according to actual needs, and will not be elaborated further here. When the number of multiple target objects exceeds the target threshold, the server executes steps 303 to 305, using a message queue to update the resource allocation information of each target object in the target database based on the target item. Conversely, when the number of multiple target objects is less than or equal to the target threshold, the server executes steps 306 to 307, using a dynamic thread executor to update the resource allocation information of each target object in the target database based on the target item. This approach differentiates the resource allocation information update tasks based on the number of multiple target objects. When the number of multiple target objects is large, using a message queue reduces the processor utilization of the service node and improves the overall service efficiency. When the number of multiple target objects is small, using a dynamic thread pool improves the processing efficiency of the service node, thereby improving the timeliness of data updates.
[0090] The two data update schemes described above will be introduced below through steps 303 to 307.
[0091] In step 303, the server generates update messages for each target object based on resource allocation information and multiple target objects.
[0092] In this embodiment of the disclosure, for any target object, the update message for that target object includes the object identifier of the target object and the resource allocation identifier of the resource allocation information. By generating update messages for each target object, technical support is provided for subsequent data updates based on message queues, enabling the server to send the key execution parameters in the data update task—object ID and resource allocation ID—to the service node via messages.
[0093] In step 304, the server stores the update messages for each target object into a message queue.
[0094] In this embodiment of the disclosure, the message queue refers to the above. Figure 2 Step 202 in the illustrated embodiment will not be repeated here. It should be noted that in some embodiments, the message queue includes multiple partitions. Schematic, the server determines the number of partitions in the message queue and stores the update messages for each target object in their respective partitions. Partitioning the message queue makes message distribution more granular, thereby improving parallelism and effectively increasing service throughput. It should be understood that the number of partitions in the message queue can be a default number set by developers based on experience, or it can be adaptively adjusted according to the application scenario; there is no limitation on this. Adaptively adjusting the number of partitions in the message queue can further improve service throughput. Several methods for determining the number of partitions in the message queue are described below.
[0095] The first method involves determining the number of partitions in the message queue based on the number of service nodes, ensuring that the number of partitions equals the number of service nodes. This approach allows each service node to process update messages for one partition, effectively improving service throughput.
[0096] The second method involves determining the number of message queue partitions based on multiple object categories corresponding to multiple target objects, ensuring that the number of message queue partitions equals the number of object categories. Here, the object category indicates the update method by which the service node updates the resource allocation to the target object. Illustratively, different object categories correspond to different update methods. For example, taking a resource allocation of 10% of the product price and the target object as a live streamer, the object categories include A, B, and C. For category A streamers, due to the larger amount of resources involved in historical product interactions within the live stream, the update method is: multiply the resource allocation information by a first coefficient of 1.2, i.e., 10% * 1.2. For category B streamers, due to the moderate amount of resources involved in historical product interactions within the live stream, the update method is: multiply the resource allocation information by a second coefficient of 1, i.e., 10% * 1. For category C streamers, due to the smaller amount of resources involved in historical product interactions within the live stream, the update method is: multiply the resource allocation information by a third coefficient of 0.8, i.e., 10% * 0.8. It should be understood that the description of object categories here is only for illustrative purposes. In other embodiments, object categories can also be determined by combining other factors, such as the number of followers, number of followers, activity level, number of items posted by the target object, etc., without limitation.
[0097] It's important to note that in this approach, the server stores update messages for each target object separately into different partitions of the message queue. This includes storing update messages for each target object in a partition based on its object category, ensuring that each partition stores update messages for target objects belonging to different object categories. In other words, different partitions store update messages for target objects of different categories. For example, if there are three object categories: A, B, and C, and the message queue has three partitions (partition 1, partition 2, and partition 3), then partition 1 stores update messages for target objects of category A, partition 2 stores update messages for target objects of category B, and partition 3 stores update messages for target objects of category C. This method ensures that each partition's update messages are processed by at least one service node. Specifically, each service node corresponding to a partition can update data based on the received update messages using the same update method, effectively improving service throughput.
[0098] In step 305, the server sends update messages for each target object to multiple service nodes in the message queue, so that the multiple service nodes update the amount of resources allocated to each target object based on the received update messages.
[0099] In this embodiment of the disclosure, the method by which the server sends update messages is as described above. Figure 2Step 203 in the illustrated embodiment will not be repeated here. It should be noted that the server sends update messages to multiple service nodes through message queue consumption threads. The number of consumption threads affects service throughput. Therefore, the server can adjust the number of message queue consumption threads based on the application scenario to further improve service throughput. For example, the number of consumption threads can be a default number set by developers based on experience (e.g., 100 consumption threads), or it can be adjusted based on the number of multiple target objects (i.e., the number of update messages in the message queue). Illustratively, the server determines the number of message queue consumption threads based on the number of multiple target objects, so that the number of multiple target objects is equal to a multiple of the number of message queue consumption threads. In this way, service throughput can be further improved, and the overall service operating efficiency can be enhanced.
[0100] Furthermore, based on step 305 above, it is known that the server can determine the number of partitions in the message queue in multiple ways. Correspondingly, the process of the server sending update messages also includes the following:
[0101] In the first scenario, where the number of message queue partitions equals the number of service nodes, the server sends update messages from each partition to the respective service nodes, ensuring that the update messages received by each service node originate from the same partition. In other words, there is a one-to-one correspondence between service nodes and partitions, with one service node handling update messages for one partition, thereby effectively improving service throughput.
[0102] The second method involves sending update messages for each target object to multiple service nodes in the message queue when the number of partitions in the message queue equals the number of object categories. This includes sending update messages from each partition to at least one service node corresponding to each partition, so that at least one service node corresponding to each partition updates the resource allocation to the target object corresponding to that partition according to the update method for that partition. In some embodiments, when sending update messages to service nodes, the server synchronously sends object category information corresponding to each partition to the service nodes, so that the service nodes can update the data according to the corresponding update method. For example, continuing with the example of step 304 above, there are three object categories, including A, B, and C, corresponding to partitions 1, 2, and 3 respectively. The server sends update messages from partition 1 to service node a, which then updates the resource allocation to the broadcaster corresponding to partition 1 according to the update method for partition 1 (resource allocation information 10% * 1.2). Through this method, each service node corresponding to a partition can update the data based on the received update messages according to the same update method, thereby effectively improving service throughput.
[0103] In some embodiments, taking any update message as an example, the process by which a service node updates the amount of resources allocated to the target object based on the received update message includes: the service node, based on the received update message, retrieves the data update reference information of the target object from the server's cache; and, based on the data update reference information, updates the amount of resources allocated to the target object based on the target item. Here, the data update reference information can be understood as the metadata on which the service node relies to implement the data update. For example, the data update reference information includes the target object's profile information, historical interaction information, etc., without limitation. It should be understood that by transforming the metadata on which the data update relies from the database (DB) to a cache mode, the number of database queries can be reduced, overall query efficiency can be improved, and service throughput and the timeliness of data updates can be further improved.
[0104] The above steps 303 to 305 describe the process of updating data using a message queue when the number of target objects is large. Steps 306 and 307 describe the process of updating data using a dynamic thread pool when the number of target objects is small.
[0105] In step 306, the server generates a data update task for each target object based on the resource allocation information and multiple target objects. This data update task is used to update the amount of resources allocated to the target objects.
[0106] In this embodiment of the disclosure, for any target object, the server generates a data update task for the target object based on the object identifier of the target object and the resource allocation identifier of the resource allocation information.
[0107] In step 307, the server executes data update tasks for each target object by creating a dynamic thread pool.
[0108] In this embodiment, the dynamic thread pool is executed by at least one service node of the server. Illustratively, a dynamic thread pool is a type of thread pool that allows adjustments to parameters such as thread pool size and queue size without requiring a service restart, enabling asynchronous, fast-forwarding and fast-out data updates based on a multi-threaded model. It should be understood that, since the number of target objects is relatively small, creating a dynamic thread pool to execute data update tasks for each target object improves overall processing efficiency by over 90% compared to single-threaded or loop-based methods in related technologies. This demonstrates that this method effectively improves the timeliness of data updates.
[0109] The following is for reference. Figure 4 The data update method shown in steps 301 to 307 above will be illustrated in the following description. Figure 4This is a schematic diagram of a data update method provided in an embodiment of this disclosure. Figure 4 As shown, after a target item is listed, if a merchant initiates multiple update requests for the resource allocation information of that target item within a target time period, the server stores these multiple update requests in a zset set in the Redis database (status=1 changes to status=2, then back to status=1). A scheduled task deduplicates the zset set in the Redis database, retaining the last resource allocation information for the item within 10 seconds, where status=1. Further, based on the update request corresponding to this last resource allocation information, the server deletes the currently stored resource allocation information for that target item from the cache and determines multiple target objects for publishing the target item based on its item ID. If the number of multiple target objects exceeds a target threshold (e.g., 500) (which can be understood as the target item being a hot item), a message queue (MQ) is used to send the update messages for each target object to multiple different service nodes (i.e., traffic forwarding), allowing the service nodes to update the resource allocation for each target object based on the received update messages. When multiple target objects are less than or equal to the target threshold (which can also be understood as non-hotspot items), a dynamic thread pool is used, with at least one service node executing the data update tasks for each target object. Using this method, in scenarios involving updates to resource allocation information for items, when there are many update tasks to be executed, a message queue is used to break down the multi-task process, and then tasks are distributed to multiple service nodes based on a load balancing strategy, avoiding excessive load on a single service node. Furthermore, Redis's zset collection deduplication feature is used to deduplicate multiple update requests within a short period, processing them only once and reducing the service processing load. Further, a divide-and-conquer approach is adopted, applying different strategies to resource allocation information updates for different types of items (hotspot items and non-hotspot items), providing targeted solutions and improving the timeliness of data updates.
[0110] The following is for reference. Figure 5 The processor utilization of the service node is compared when the data update method provided in the embodiments of this disclosure is used and when related technologies are used. Figure 5 This is a schematic diagram illustrating the utilization rate of a service node processor according to an embodiment of this disclosure. Figure 5 As shown in Figure (a), when using the relevant technology, the CPU (Central Processing Unit) utilization of each service node exhibits numerous spikes, with some even exceeding 80% utilization. Figure 5As shown in Figure (b), by using the data update method provided in this embodiment, the CPU utilization of each service node is relatively stable, without spikes, and the average utilization is relatively low, thus avoiding CPU alarm and rate limiting issues, which greatly improves the stability and reliability of the entire service.
[0111] In summary, in the data update method provided in this embodiment, in response to an update request for resource allocation information for a target item, when the number of multiple target objects corresponding to the target item is greater than a target threshold, a large number of update messages are distributed to multiple different service nodes for processing through a message queue, thereby reducing the processor utilization of the service nodes and improving the overall service operating efficiency.
[0112] Figure 6 This is a structural block diagram of a data update device provided in an embodiment of this disclosure. (Refer to...) Figure 6 The device includes a determining unit 601, a generating unit 602, and a sending unit 603.
[0113] The determining unit 601 is configured to perform an update request for resource allocation information for a target item, in response to the target item, to determine multiple target objects corresponding to the target item, wherein the resource allocation information indicates the amount of resources allocated to the target object when the target item is interacted with through the target object;
[0114] The generation unit 602 is configured to, when the number of the plurality of target objects is greater than a target threshold, generate an update message for each target object based on the resource allocation information and the plurality of target objects, and store the update message for each target object in a message queue, wherein the update message for the target object indicates the resource allocation information and the target object;
[0115] Sending unit 603 is configured to send update messages for each of the target objects to multiple service nodes of the message queue, so that the multiple service nodes update the amount of resources allocated to each of the target objects based on the received update messages.
[0116] In some embodiments, the generation unit 602 includes:
[0117] The sub-determination unit is configured to determine the number of partitions for the message queue;
[0118] The sub-storage unit is configured to generate update messages for each target object based on the resource allocation information and the multiple target objects, and store the update messages for each target object into the respective partitions of the message queue.
[0119] In some embodiments, the sub-determining unit is configured to perform:
[0120] Based on the number of service nodes, determine the number of partitions for the message queue so that the number of partitions for the message queue is equal to the number of service nodes.
[0121] The sub-storage unit is configured to perform the following: send update messages from each partition to each service node, so that the update messages received by the service node come from the same partition.
[0122] In some embodiments, the sub-determining unit is configured to perform:
[0123] Based on the multiple object categories corresponding to the multiple target objects, the number of partitions of the message queue is determined so that the number of partitions of the message queue is equal to the number of the multiple object categories. The object category indicates the update method by which the service node updates the amount of resources allocated to the target object.
[0124] The sub-storage unit is configured to perform the following: based on the object category to which each target object belongs, store the update messages of each target object into each partition, so that each partition stores the update messages of the target object belonging to different object categories;
[0125] The sending unit 603 is configured to send the update messages in each partition to at least one service node corresponding to each partition, so that at least one service node corresponding to the partition updates the amount of resources allocated to the target object corresponding to the partition according to the update method corresponding to the partition.
[0126] In some embodiments, the device further includes:
[0127] The consumer thread number determination unit is configured to determine the number of consumer threads for the message queue based on the number of the multiple target objects, such that the number of the multiple target objects is equal to a multiple of the number of consumer threads for the message queue.
[0128] In some embodiments, the device further includes:
[0129] The task generation unit is configured to generate a data update task for each target object based on the resource allocation information and the multiple target objects when the number of the multiple target objects is less than or equal to the target threshold. The data update task is used to update the amount of resources allocated to the target object.
[0130] The task execution unit is configured to execute data update tasks for each target object by creating a dynamic thread pool.
[0131] In some embodiments, the determining unit 601 is configured to perform:
[0132] In response to receiving multiple update requests for resource allocation information within a target time period, the multiple target objects are determined based on the last update request received within the target time period.
[0133] In the data update apparatus provided in this embodiment, in response to an update request for resource allocation information for a target item, when the number of multiple target objects corresponding to the target item is greater than a target threshold, a large number of update messages are distributed to multiple different service nodes for processing through a message queue, thereby reducing the processor utilization of the service nodes and improving the overall service operating efficiency.
[0134] It should be noted that the data update device provided in the above embodiments is only illustrated by the division of the above functional modules during data update. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the data update device and data update method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0135] This disclosure also provides an electronic device, which includes:
[0136] One or more processors;
[0137] Memory used to store the executable program code of the processor;
[0138] The processor is configured to execute the program code to implement the server-executed process in the data update method provided in the above-described method embodiments.
[0139] In some embodiments, the program code involved in the present application embodiments may be deployed on an electronic device for execution, or executed on multiple electronic devices located in one location. Multiple electronic devices distributed in multiple locations and interconnected through wired or wireless networks may constitute a blockchain system.
[0140] Taking electronic devices as servers as an example, Figure 7This is a structural block diagram of a server provided in an embodiment of the present disclosure. The server 700 can vary significantly due to different configurations or performance. It may include one or more Central Processing Units (CPUs) 701 and one or more memories 702. Each memory 702 stores at least one line of program code, which is loaded and executed by the one or more processors 701 to implement the server's execution process in the data update methods provided in the various method embodiments described above. Of course, the server 700 may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input / output. The server 700 may also include other components for implementing device functions, which will not be elaborated upon here.
[0141] In an exemplary embodiment, a computer-readable storage medium including program code is also provided, such as a memory 702 including program code, which can be executed by the processor 701 of the server 700 to complete the data update method described above. Optionally, the computer-readable storage medium may be read-only memory (ROM), random access memory (RAM), compact-disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device, etc.
[0142] In an exemplary embodiment, a computer program product is also provided, including one or more instructions executed by one or more processors of an electronic device, enabling the electronic device to perform the data update method described above.
[0143] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0144] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A data updating method characterized by comprising: The method comprises: in response to receiving a plurality of update requests for resource allocation information of a target item within a target time period, determining a plurality of target objects corresponding to the target item based on the last received update request within the target time period, the resource allocation information indicating the amount of resources allocated to the target object if the target object interacts with the target item; in a case where the number of the plurality of target objects is greater than a target threshold, generating an update message for each of the target objects based on the resource allocation information and the plurality of target objects, storing the update message for each of the target objects to a message queue, the update message for each of the target objects indicating the resource allocation information and the target object, and sending the update message for each of the target objects to a plurality of service nodes of the message queue, so that the plurality of service nodes update the amount of resources allocated to each of the target objects based on the received update message; in a case where the number of the plurality of target objects is less than or equal to the target threshold, for any target object, generating a data update task for the target object based on a resource allocation identifier of the resource allocation information and an object identifier of the target object, the data update task being used to update the amount of resources allocated to the target object, and executing the data update task for each of the target objects by at least one service node through creation of a dynamic thread pool.
2. The data updating method according to claim 1, characterized by, The method comprises: determining the number of partitions of the message queue; generating an update message for each of the target objects based on the resource allocation information and the plurality of target objects, and storing the update message for each of the target objects in each partition of the message queue.
3. The data updating method according to claim 2, characterized by, The method comprises: determining the number of partitions of the message queue based on the number of the plurality of service nodes, so that the number of partitions of the message queue is equal to the number of the plurality of service nodes; The method comprises:
4. The data updating method according to claim 2, characterized by, sending the update message for each of the target objects to the plurality of service nodes of the message queue, so that the service nodes receive the update message from the same partition. The method comprises: determining the number of partitions of the message queue based on a plurality of object categories corresponding to the plurality of target objects, so that the number of partitions of the message queue is equal to the number of the plurality of object categories, the object category indicating an update manner of the service node for updating the amount of resources allocated to the target object; The method comprises: storing the update message for each of the target objects in each partition of the message queue based on the object category to which each of the target objects belongs, so that each of the partitions stores the update message for the target object belonging to a different object category. The sending of the update message of each target object to the plurality of service nodes of the message queue comprises: sending the update message in each partition to at least one service node corresponding to the partition, respectively, so that the at least one service node corresponding to the partition updates the resource amount allocated to the target object corresponding to the partition according to the update mode corresponding to the partition.
5. The data updating method according to claim 1, characterized by, The method further comprises: determining the number of consumption threads of the message queue based on the number of target objects, so that the number of target objects is equal to a multiple of the number of consumption threads of the message queue.
6. A data updating apparatus characterized by comprising: The apparatus comprises: a determination unit configured to determine, in response to receiving a plurality of update requests for resource allocation information of a target item within a target time period, a plurality of target objects corresponding to the target item based on the last received update request within the target time period, the resource allocation information indicating the resource amount allocated to the target object in the case of interacting with the target item through the target object; a generation unit configured to generate, in the case that the number of target objects is greater than a target threshold, an update message of each target object based on the resource allocation information and the plurality of target objects, and store the update message of each target object to a message queue, the update message of the target object indicating the resource allocation information and the target object; a sending unit configured to send the update message of each target object to a plurality of service nodes of the message queue, so that the plurality of service nodes update the resource amount allocated to each target object based on the received update message; a task generation unit configured to generate, in the case that the number of target objects is less than or equal to the target threshold, for any target object, a data update task of the target object based on the resource allocation identifier of the resource allocation information and the object identifier of the target object, the data update task being used to update the resource amount allocated to the target object; a task execution unit configured to execute the data update task of each target object by creating a dynamic thread pool through at least one service node.
7. An electronic device, comprising: The electronic device comprises: one or more processors; a memory for storing program code executable by the processor; wherein the processor is configured to execute the program code to implement the data update method of any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, When the program code in the computer readable storage medium is executed by the processor of the electronic device, the electronic device can execute the data update method of any one of claims 1 to 5.
Citation Information
Patent Citations
Message pushing method and device, computer equipment and storage medium
CN113596150A
Order data processing method, system and equipment based on kafka technology and storage medium
CN114707926A