Weighted polling method, data synchronization method, manufacturing execution system and equipment

By using a bitmask-weighted round-robin algorithm, which replaces traditional calculations with bitwise operations, the problem of high computational complexity in load balancing of MES systems is solved, achieving efficient server load balancing and data synchronization.

CN121050890APending Publication Date: 2025-12-02THINKCAR TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511239606.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-01
Publication Date
2025-12-02

AI Technical Summary

Technical Problem

Existing MES systems suffer from high computational complexity and low processing efficiency during load balancing, especially in high-performance distributed environments, leading to performance bottlenecks.

Method used

A weighted round-robin algorithm based on bitmasks is used to achieve server load balancing by setting the server weights to powers of 2 and replacing division, multiplication, and modulo operations with bitwise operations.

Benefits of technology

Significantly reduces computational complexity, improves the efficiency of data synchronization and server request allocation, and ensures excellent performance in high-performance load balancing scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121050890A_ABST
    Figure CN121050890A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, in particular to a weighted polling method, a data synchronization method, a manufacturing execution system and equipment. In the weighted polling method, a first operation value is calculated through a first calculation strategy according to the total weight; wherein the total weight is the sum of the weights of all the objects; traversing all objects allowed to be scheduled, and performing bit operation by utilizing the first operation value, the bit mask of the current object and the second operation value until the first operation value is determined to be matched with the bit mask of the current object, and taking the current object as a target object to be scheduled; wherein the second operation value is obtained according to the bit mask of the current object. According to the method, bit operation is used for replacing traditional division, multiplication and modular operation, the calculation complexity is extremely low, and especially in a high-performance distributed environment, the efficiency of data synchronization and object (server) request distribution can be improved. According to the method and the device, extremely low calculation complexity and excellent performance can be provided in a high-performance load balancing scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a weighted polling method, a data synchronization method, a manufacturing execution system and equipment. Background Technology

[0002] A Manufacturing Execution System (MES) is a production information management system for the shop floor execution layer of manufacturing enterprises. It sits between the upper-level Enterprise Resource Planning (ERP) system and the lower-level industrial control system (such as PLCs and DCS), playing a crucial role in bridging the gap between them. The main objectives of an MES system are to optimize production scheduling, improve product quality, reduce production losses, increase equipment utilization, and achieve traceability of the production process.

[0003] Currently, common load balancing algorithms in MES (Manufacturing Execution System) systems include round-robin, weighted round-robin, and hashing. However, while traditional weighted round-robin algorithms can allocate requests based on weights, they often use complex division or modulo operations, leading to performance bottlenecks, especially when there are many servers. Existing weighted round-robin algorithms are inefficient in high-performance distributed environments, necessitating a more efficient and less complex algorithm. Summary of the Invention

[0004] In view of this, embodiments of this application provide a weighted polling method, a data synchronization method, a manufacturing execution system and equipment, which can effectively solve the problems of high computational complexity and low processing efficiency in existing MES systems when achieving load balancing.

[0005] In a first aspect, embodiments of this application provide a weighted round-robin method applicable to a manufacturing execution system, wherein the manufacturing execution system is used to invoke multiple objects to achieve load balancing; the method includes: The first calculated value is obtained by using a first calculation strategy based on the total weight; wherein the total weight is the sum of the weights of all objects; Traverse all objects that are allowed to be scheduled, and perform bitwise operations using the first operation value, the bitmask of the current object, and the second operation value until it is determined that the first operation value matches the bitmask of the current object. Then, the current object is taken as the target object to be scheduled; wherein, the second operation value is obtained based on the bitmask of the current object.

[0006] In some embodiments, the method further includes: Before calculating the first calculated value, different weights are assigned to all objects; wherein the weights are powers of 2. The bitmask is generated according to the weight of the object and the bitmask generation rules.

[0007] In some embodiments, the step of traversing all objects that can be scheduled and performing bitwise operations using the first operation value, the bitmask of the current object, and the second operation value until it is determined that the first operation value matches the bitmask of the current object includes: Iterate through all objects that are allowed to be scheduled, and perform a bitwise AND operation between the first operation value and the bitmask of the current object to obtain the first intermediate value; Perform a bitwise AND operation between the bitmask of the current object and the second operand value to obtain a second intermediate value; wherein, the second operand value is obtained by right-shifting the bitmask of the current object by one bit; If the first intermediate value is equal to the second intermediate value, then it is determined that the first calculated value matches the bitmask of the current object.

[0008] In some embodiments, the first calculated value obtained according to the total weight through a first calculation strategy includes: During each polling, the target count value is obtained using a preset incrementing calculator; The first calculated value is obtained by performing a modulo operation between the target count value and the total weight.

[0009] In some embodiments, the method further includes: constructing an object class; The object class includes attributes such as object identifier, weight, and bitmask; the object class also includes attribute setting functions. The method further includes: instantiating an object class instance for each object; calling the corresponding attribute setting function through the object class instance to set the object identifier and weight of the corresponding object; and shifting the weight of the object one bit to the right to obtain a mask value and assigning it to the bitmask.

[0010] In some embodiments, the method further includes: a target object selection function; The target object selection function is used for: During each polling, the target count value is obtained using a preset incrementing calculator; The first calculated value is obtained by performing a modulo operation between the target count value and the total weight; Traverse all objects and determine whether the first intermediate value is equal to the second intermediate value; wherein, the first intermediate value is obtained by performing a bitwise AND operation between the first operand value and the bitmask of the current object; the second intermediate value is obtained by performing a bitwise AND operation between the bitmask of the current object and the second operand value; If the first intermediate value is equal to the second intermediate value, then the object identifier is obtained through the object class instance of the current object.

[0011] Secondly, embodiments of this application provide a data synchronization method, including: Based on the scheduled task mechanism in the preset development framework, target data is periodically retrieved from the enterprise resource planning system using the interface provided by the preset enterprise resource planning system. Multiple synchronization service instances are scheduled using a weighted round-robin algorithm as provided in the first aspect of this application; The target data is synchronized to the manufacturing execution system using a scheduled synchronization service instance.

[0012] In some embodiments, the method of synchronizing the target data to the manufacturing execution system via a scheduled synchronization service instance includes: Each of the target data is cached in a message queue; The system consumes the target data from the message queue through the scheduled synchronization service instance, performs deduplication verification on the target data, and then synchronizes the successfully verified target data to the manufacturing execution system.

[0013] Thirdly, embodiments of this application provide a manufacturing execution system that uses a weighted round-robin method as provided in the first aspect of this application to schedule multiple objects under its management in order to achieve load balancing.

[0014] Fourthly, embodiments of this application provide a terminal device, the terminal device including a processor and a memory, the memory storing a computer program, and the processor executing the computer program to implement a weighted polling method provided in the first aspect of this application.

[0015] The embodiments of this application have the following beneficial effects: This application calculates a first operational value based on the total weight using a first calculation strategy; wherein the total weight is the sum of the weights of all objects; it iterates through all objects that are allowed to be scheduled, and performs bitwise operations using the first operational value, the bitmask of the current object, and a second operational value until it is determined that the first operational value matches the bitmask of the current object, then the current object is taken as the target object to be scheduled; wherein the second operational value is obtained based on the bitmask of the current object. This application uses bitwise operations instead of traditional division, multiplication, and modulo operations, resulting in extremely low computational complexity, especially in high-performance distributed environments where it can improve the efficiency of data synchronization and object (server) request allocation. This application can provide extremely low computational complexity and excellent performance in high-performance load balancing scenarios. Attached Figure Description

[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 A flowchart of a weighted polling method according to an embodiment of this application is shown; Figure 2 This paper shows a flowchart illustrating the calculation of the operational value output by the incrementing counter in the weighted polling method of this application embodiment; Figure 3 This paper illustrates a flowchart of bitwise operations involved in the weighted polling method according to an embodiment of this application; Figure 4 A flowchart of a data synchronization method according to an embodiment of this application is shown; Figure 5 This paper shows a structural block diagram of a data synchronization platform according to an embodiment of the present application; Figure 6 Another structural block diagram of the data synchronization platform according to an embodiment of this application is shown. Detailed Implementation

[0018] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.

[0019] The components of the embodiments of this application described and illustrated in the accompanying drawings can be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of this application provided in the drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.

[0020] In the following text, the terms "comprising," "having," and their cognates, which may be used in various embodiments of this application, are intended only to indicate a particular feature, number, step, operation, element, component, or combination thereof, and should not be construed as primarily excluding the presence of one or more other features, numbers, steps, operations, elements, components, or combinations thereof, or adding the possibility of one or more combinations thereof. Furthermore, the terms "first," "second," "third," etc., are used only for distinguishing descriptions and should not be construed as indicating or implying relative importance.

[0021] Unless otherwise specified, all terms used herein (including technical and scientific terms) shall have the same meaning as commonly understood by one of ordinary skill in the art to which the various embodiments of this application pertain. Terms (such as those defined in commonly used dictionaries) shall be interpreted as having the same meaning as in their contextual meaning in the relevant technical field and shall not be construed as having an idealized or overly formal meaning, unless clearly defined in the various embodiments of this application.

[0022] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0023] To address the technical problem that existing weighted round-robin algorithms suffer from high computational complexity and low efficiency, leading to performance bottlenecks in high-performance distributed environments, this application provides a weighted round-robin method, a data synchronization method, a manufacturing execution system, and equipment.

[0024] The main idea of ​​the weighted round-robin method in this application includes: This application is a weighted round-robin algorithm based on bitmasks. By setting the weight of the server to a power of 2, bitwise operations are used to replace traditional division, multiplication, and modulo operations, thereby improving the efficiency of data synchronization and server request allocation. The algorithm of this application has extremely low computational complexity and excellent performance in high-performance load balancing scenarios.

[0025] Firstly, this application provides a manufacturing execution system, which, exemplary, uses the weighted polling method of this application to schedule multiple objects it manages. These objects include, but are not limited to, task events, servers, etc.

[0026] For example, the object is a server. The manufacturing execution system uses a weighted round-robin method to schedule the servers to achieve load balancing.

[0027] The weighted polling method will be explained below with reference to some specific embodiments.

[0028] Figure 1 A flowchart of a weighted round-robin method according to an embodiment of this application is shown. Exemplarily, this weighted round-robin method is applicable to the manufacturing execution system provided in this application, which is used to invoke multiple objects to achieve load balancing. The weighted round-robin method includes the following steps: S100, the first calculated value obtained by the first calculation strategy based on the total weight; wherein, the total weight is the sum of the weights of all objects.

[0029] In this application's embodiments, the objects include, but are not limited to, servers, task events, and service instances. For example, if the object is a server, then a weight is assigned to each server, and the weights of each server are added together to obtain the total weight.

[0030] The first calculation strategy in the embodiments of this application includes, but is not limited to, modulo operation, arithmetic operations, etc.

[0031] Furthermore, to improve computation speed, in this embodiment, different weights are assigned to all objects before calculating the first operation value; wherein the weights are powers of 2. Specifically, before calculating the first operation value, a weight of 2ⁿ is assigned to all objects, where n∈(0,N-1), and N is the total number of objects. For example, a manufacturing execution system schedules and manages multiple servers, and the weight of each server is set to a different power of 2, such as 1, 2, 4, 8...

[0032] In one implementation, such as Figure 2 As shown, the first calculated value obtained according to the total weight through the first calculation strategy includes: S110 obtains the target count value through a preset incrementing calculator during each polling.

[0033] In this embodiment, an incrementing counter is used to determine the requested allocation object (e.g., a server), and subsequent bitwise operations are used to determine whether to select the server.

[0034] Furthermore, if the counter's step value is set to 1, then during each polling, the counter increments by 1 to obtain the target count value. For example, the target count value counter = (counter + 1).

[0035] S120, Perform a modulo operation between the target count value and the total weight to obtain the first calculated value.

[0036] In order to avoid exceeding the total number of objects, in this embodiment of the application, the counter is incremented during each polling, and the counting result is moduloed with the total weight, that is, the first operation value value = (counter + 1) % totalWeight, to ensure that the final result circulates within the range of [0, totalWeight-1], where counter is the target count value obtained in the previous polling, and totalWeight is the total weight.

[0037] S200: Traverse all objects that are allowed to be scheduled, and perform bitwise operations using the first operand value, the bitmask of the current object, and the second operand value until it is determined that the first operand value matches the bitmask of the current object. Then, the current object is taken as the target object to be scheduled. The second operand value is obtained based on the bitmask of the current object.

[0038] In other words, each object's bitmask is used to perform bitwise operations with the first and second operands to determine if the first operand matches the current object's bitmask. If they match, the traversal ends, and the current object is designated as the target object to be scheduled.

[0039] Furthermore, to improve computation speed, in this embodiment, before calculating the first operation value, a bitmask is generated according to the object's weight and a bitmask generation rule. This bitmask generation rule sets the bitmask for all objects to 2ⁿ-1, where n∈(0, N-1), and N is the total number of objects. In other words, the weight of each object is set to a power of 2, and the mask of an object with weight n is represented as a binary number consisting of n 1s. This design in this embodiment can effectively utilize bitwise operations to calculate object selection conditions. For example, a manufacturing execution system schedules and manages multiple servers, and each server's weight is set to a different power of 2, such as 1, 2, or 4. The corresponding bitmasks are as follows: For a server with weight 1, mask = 1 (0b1). Server with weight 2, mask = 3 (0b11); The server with a weight of 4 has a mask of 15 (0b1111).

[0040] Understandably, the detailed process of bitmask generation rules is as follows: For servers with a weight of 4: 1 << 4 = 16; 16 - 1 = 15 (binary 1111).

[0041] In one embodiment, to improve efficiency and reduce computational complexity, it is understood that, as Figure 3 As shown, in step S200, all objects that are allowed to be scheduled are traversed, and bitwise operations are performed using the first operation value, the bitmask of the current object, and the second operation value until it is determined that the first operation value matches the bitmask of the current object, including: S210: Traverse all objects that are allowed to be scheduled, perform a bitwise AND operation between the first operation value and the bitmask of the current object, and obtain the first intermediate value.

[0042] The mathematical expression for the first intermediate value is (value&server.mask), where value is the first operand and server.mask is the bitmask of the current object. A bitwise AND operation is performed between the first operand and the bitmask of the current object. This is to extract the bits in the incrementing counter value (value) that correspond to the bits in the bitmask.

[0043] S220: Perform a bitwise AND operation on the current object's bitmask and the second operand to obtain a second intermediate value; the second operand is obtained by right-shifting the current object's bitmask by one bit. Second operand = server.mask >>> 1. In other words, unsigned right-shifting the bitmask by one bit is equivalent to right-shifting the binary bitmask by one bit, padding the high-order bits with 0.

[0044] The mathematical expression for the second intermediate value is (server.mask&(server.mask>>>1)). A bitwise AND operation is performed on the current object's bitmask and the second operand. This is to extract the high-order bits of the mask, thus obtaining the server's "weight center point". S230, if the first intermediate value is equal to the second intermediate value, then determine that the first operation value matches the bitmask of the current object.

[0045] Specifically, it checks if the equation `(value&server.mask) == (server.mask&(server.mask>>>1))` is true. It then checks if the current `value&mask` equals `mask&(mask>>>1)`, i.e., whether it falls within the server's "weight center interval". If true, the object is scheduled; otherwise, the process continues to the next object. Bitwise operations are used to determine if the current counter value matches the object's mask, thus deciding whether to schedule the object.

[0046] In an example where the object is a server, for a server with a weight of 2ⁿ: The bitmask server.mask = 2ⁿ - 1 (corresponding to n ones); server.mask>>>1 = server.mask / 2; server.mask&(server.mask>>>1) = the high-order part of server.mask.

[0047] When value&mask equals this value (the high-order part of server.mask), it means that the value of the incrementing counter falls within the weight range of this server, which means that the server is matched.

[0048] In one embodiment, the method further includes: constructing an object class.

[0049] The attributes in an object class include object identifier, weight, and bitmask; the object class also includes attribute setting functions.

[0050] For example, if the object is a server, in the embodiments of the present application, the server is designed as a structure including attributes such as a server identifier (e.g., server name, encoding, etc.), weight, and bit mask, as shown in the following code: The method further includes: instantiating an object class instance for each object respectively; calling the corresponding attribute setting function through the object class instance, thereby setting the object identifier and weight of the corresponding object, and shifting the weight of the object one bit to the right to obtain a mask value and assigning it to the bit mask.

[0051] private static class Server { / / Static server class String name; / / Server name int weight; / / Server weight (must be a power of 2) int mask; / / Calculated bit mask Server(String name, int weight) { / / When this Server function is called externally, assign values to the server name and weight. And calculate the bit mask based on the weight this.name = name; this.weight = weight; ​​​​​​​​​​​​​​​​​​​​​​​value = (counter + 1) % totalWeight; / / Increment the counter by 1 and take the modulo of the total weight to get the first calculated value. for (Server server : servers) { / / Iterate through all servers if ((value&server.mask) == (server.mask&(server.mask>>>1))) { / / Determine if the current counter value matches the mask of the server using bitwise operations. return server.name; / / If a match is found, return the server name to facilitate finding the server object. } } The weighted polling method of this application embodiment will be described below with reference to an example: (a) In this example, for a server with a weight of 2ⁿ, the mask is calculated as: mask = 2ⁿ - 1, which is a binary number consisting of n 1s. Taking a server with a weight of 4 as an example, the bitmask for this server is generated as follows: 1<<4= 16; 16 - 1 = 15 (the binary bitmask is 1111), the bitmask is 15, and the binary bitmask is 0b1111.

[0053] (b) Shift the bitmask right by one bit. Taking a server with a weight of 4 (mask 15 / 0b1111) as an example, the server selection criteria are set as follows: server .mask>>>1= 7 (0b0111).

[0054] (c) The value after shifting the bitmask one bit to the right is bitwise ANDed with the original mask to obtain a high-order part, which is used to represent the load range of the server.

[0055] server .mask&(server .mask>>>1)= 7 (0b0111).

[0056] When value&mask equals 7, it indicates that the load falls within this range, so select this server: value=7 (0b0111) → 7&15 = 7 → Select; value=15 (0b1111) → 15&15 = 15 → Do not select.

[0057] Table 1 shows the server weight configuration, the incrementing counter value, and the matching server information.

[0058] Table 1. Matching of Servers with Incremental Calculators

[0059] As shown in Table 1 above, in this embodiment, the number of times a server is matched is consistent with the weight assigned to it. Servers with higher weights are selected more often, and the distribution is even, with efficient judgment achieved through bitwise operations.

[0060] In this embodiment, each server with a weight of 2ⁿ corresponds to an "interval" of length 2ⁿ, which is the interval "responsible" for by that server from the integer from 0 to totalWeight - 1. Each time the counter increments, it will fall within the "interval" of a certain server. Whether the current counter falls within the "interval" of that server can be determined by `value&mask == mask&(mask>>1)`.

[0061] In summary, this application has the following advantages: High efficiency: By replacing multiplication, division, and modular arithmetic with bitwise operations, computational complexity is significantly reduced.

[0062] Stateless: Only an incrementing counter needs to be maintained, without needing to record the current weight state of each server.

[0063] Determinism: The same counter value always selects the same server, ensuring the stability of load balancing.

[0064] The weighted round-robin method in this application uses a bitmask and a round-robin counter mechanism to make the server allocation process stateless and low-latency, maintaining high efficiency and stability of the synchronization logic even in high-frequency synchronization requests. Compared with traditional weighted round-robin algorithms, this algorithm significantly improves request processing efficiency without increasing memory consumption, and avoids data loss or duplicate synchronization problems caused by SAP response timeouts or uneven load.

[0065] In existing technologies, SAP systems and MES systems synchronize data through low-frequency fetching via scheduled tasks or manual import, resulting in low data synchronization efficiency. Therefore, this application also provides a data synchronization method. This data synchronization method employs a Java SpringBoot + SpringCloud microservice architecture, combined with the weighted round-robin algorithm of this application, to achieve high-frequency, automatic, and stable data synchronization of the SAP system.

[0066] Exemplary, such as Figure 4 As shown, the data synchronization method includes: S310, based on the scheduled task mechanism in the preset development framework, uses the interface provided by the preset enterprise resource planning system to periodically pull target data from the enterprise resource planning system.

[0067] Furthermore, the method in this application embodiment also includes using a data synchronization service to monitor data changes within the enterprise resource planning system. Once data changes within the enterprise resource planning system, the changed target data is retrieved using an interface provided by the enterprise resource planning system through a scheduled task mechanism.

[0068] As an example, the default development framework is the Java Spring Boot framework. Java Spring Boot is an open-source Java framework developed by the Pivotal team (now part of VMware) to simplify the initial setup and development of Spring applications, enabling developers to create standalone, production-ready Spring applications more quickly and easily.

[0069] The scheduled task mechanism is Spring Boot's scheduled task mechanism (@Scheduled). Periodic fetching is implemented using Spring Boot's @Scheduled annotation.

[0070] The default enterprise resource planning (ERP) system uses SAP. SAP is an enterprise resource planning (ERP) system developed by the German company SAP SE (Systems, Applications, and Products in Data Processing), widely used in the core business management of large global enterprises, multinational corporations, and various industries such as manufacturing, retail, finance, and logistics. For example, target data is retrieved through SAP OData / WebService interfaces. For example, publicly available REST-style interfaces are configured using SAP Gateway or NetWeaver. JCo (Java Connector) is used to connect to the SAP system, calling RFC_READ_TABLE or business BAPIs. This embodiment supports pagination and incremental retrieval, avoiding performance bottlenecks caused by full synchronization.

[0071] For example, the data synchronization method of this application embodiment is applicable to a data synchronization platform, such as... Figure 5 As shown, this data synchronization platform includes an SAP system (Enterprise Resource Planning, ERP system) and a MES system (Manufacturing Execution System). This data synchronization method runs on the MES system. Understandably, the SAP system provides APIs for collecting and writing data.

[0072] S320, the weighted round-robin algorithm as described in the embodiments of this application is used to schedule multiple synchronization service instances.

[0073] SAP system data synchronization tasks are encapsulated into multiple microservice components (corresponding synchronization service instances). These microservice components are dynamically scheduled using a weighted round-robin algorithm. In other words, low-overhead bitwise operations combined with a round-robin algorithm are used to control load balancing.

[0074] This data synchronization method also includes configuring the Spring Cloud Configuration Center. The Spring Cloud Configuration Center (Spring Cloud Config) is a core component of the Spring Cloud microservice architecture, primarily used to centrally manage the configuration information of multiple microservice instances and to achieve dynamic updates, unified management, and version control of configurations. It has significant engineering value in enterprise-level microservice systems, especially in complex business scenarios involving SAP system integration and high-frequency data synchronization.

[0075] S330 synchronizes target data to the manufacturing execution system through a scheduled synchronization service instance.

[0076] The data synchronization method of this application embodiment can significantly improve the system's concurrent processing capability, synchronization efficiency, system stability and scalability, and is suitable for large-scale enterprise-level data integration scenarios.

[0077] Furthermore, to improve concurrency and stability, asynchronous message queues are used to achieve high concurrency and high stability for data synchronization. Understandably, the target data is synchronized to the manufacturing execution system via a scheduled synchronization service instance, including: S331 caches each target data to the message queue.

[0078] S332 consumes target data from the message queue through the scheduled synchronization service instance, performs deduplication verification on the target data, and then synchronizes the successfully verified target data to the manufacturing execution system.

[0079] Before writing target data to the MES local database, deduplication verification is performed (e.g., based on Redis key or version number). If synchronization is successful, it is written to the log; otherwise, it can be reprocessed through the retry queue to prevent data errors caused by duplicate message consumption or scheduling.

[0080] like Figure 6As shown, SAP data synchronization tasks are pushed to message queues (Kafka / RabbitMQ), and multiple consumer instances (corresponding to synchronization service instances) consume and process them concurrently and asynchronously. The specific process is as follows: SAP interface → pull data → put into message queue → multiple processing nodes consume concurrently → store in MES (MES database).

[0081] The aforementioned message queue serves as an intermediate buffer, decoupling producers and consumers; multiple synchronization service consumers (corresponding to synchronization service instances) consume tasks from the queue; and consumers schedule tasks among themselves using a weighted round-robin algorithm.

[0082] Furthermore, the data synchronization method in this application embodiment also includes: dynamically adjusting the call frequency in conjunction with a configuration center. For example, by modifying the value of sap.sync.cron through Apollo, the synchronization frequency can be dynamically controlled without restarting the service.

[0083] The data synchronization method of this application embodiment has the following advantages: High-frequency scheduling: @Scheduled(cron) can achieve a minimum granularity accurate to the second; Low-latency transmission: SAP interfaces employ a paging / incremental strategy to avoid full transmission; Exception retries: Data that fails to synchronize can be temporarily stored in the Redis / MQ background retry queue; Synchronization status record: Record the last synchronization timestamp and perform incremental retrieval (e.g., updatedAt>lastTime).

[0084] This application uses a weighted round-robin algorithm to achieve consumer load balancing, improving the concurrent processing capability and stability of the synchronization service. Furthermore, this application also supports breakpoint resumption and failure retry mechanisms.

[0085] This application also provides a weighted polling apparatus. Exemplarily, the weighted polling apparatus includes: The calculation module is used to calculate the first calculation value based on the total weight using a first calculation strategy; wherein the total weight is the sum of the weights of all objects; The target object determination module is used to traverse all objects that are allowed to be scheduled, and perform bit operations using the first operation value, the bitmask of the current object, and the second operation value until it is determined that the first operation value matches the bitmask of the current object. If so, the current object is taken as the target object to be scheduled. The second operation value is obtained based on the bitmask of the current object.

[0086] It is understood that the apparatus in this embodiment corresponds to the weighted polling method in the above embodiments, and the options in the above embodiments are also applicable to this embodiment, so they will not be described again here.

[0087] This application also provides a terminal device, exemplary of which includes a processor and a memory, wherein the memory stores a computer program, and the processor executes the computer program to enable the terminal device to perform the functions of the various modules in the weighted polling method or the weighted polling apparatus described above.

[0088] The processor can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including at least one of a Central Processing Unit (CPU), Graphics Processing Unit (GPU), Network Processor (NP), Digital Signal Processor (DSP), Application-Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application.

[0089] The memory can be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), etc. The memory is used to store computer programs, and the processor can execute the computer programs accordingly after receiving execution instructions.

[0090] This application also provides a computer-readable storage medium for storing the computer program used in the aforementioned terminal device. For example, the computer-readable storage medium may include, but is not limited to, various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0091] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that, in alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0092] In addition, the functional modules or units in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0093] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a smartphone, personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application.

[0094] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. A weighted round-robin method, characterized in that, A method applicable to a manufacturing execution system (MAS) for invoking multiple objects to achieve load balancing; the method includes: The first calculated value is obtained by applying a first calculation strategy based on the total weight; wherein the total weight is the sum of the weights of all objects; Traverse all objects that are allowed to be scheduled, and perform bitwise operations using the first operation value, the bitmask of the current object, and the second operation value until it is determined that the first operation value matches the bitmask of the current object. Then, the current object is taken as the target object to be scheduled; wherein, the second operation value is obtained based on the bitmask of the current object.

2. The weighted round-robin method according to claim 1, characterized in that, The method further includes: Before calculating the first calculated value, different weights are assigned to all objects; wherein the weights are powers of 2. The bitmask is generated according to the weight of the object and the bitmask generation rules.

3. The weighted round-robin method according to claim 2, characterized in that, The step of traversing all objects that can be scheduled and performing bitwise operations using the first operation value, the bitmask of the current object, and the second operation value until it is determined that the first operation value matches the bitmask of the current object includes: Iterate through all objects that are allowed to be scheduled, and perform a bitwise AND operation between the first operation value and the bitmask of the current object to obtain the first intermediate value; Perform a bitwise AND operation between the bitmask of the current object and the second operand value to obtain a second intermediate value; wherein, the second operand value is obtained by right-shifting the bitmask of the current object by one bit; If the first intermediate value is equal to the second intermediate value, then it is determined that the first calculated value matches the bitmask of the current object.

4. The weighted round-robin method according to claim 3, characterized in that, The first calculated value obtained according to the total weight through the first calculation strategy includes: During each polling, the target count value is obtained using a preset incrementing calculator; The first calculated value is obtained by performing a modulo operation between the target count value and the total weight.

5. The weighted round-robin method according to claim 4, characterized in that, The method further includes: constructing an object class; The object class includes attributes such as object identifier, weight, and bitmask; the object class also includes attribute setting functions. The method further includes: instantiating an object class instance for each object; calling the corresponding attribute setting function through the object class instance to set the object identifier and weight of the corresponding object; and shifting the weight of the object one bit to the right to obtain a mask value and assigning it to the bitmask.

6. The weighted round-robin method according to claim 5, characterized in that, The method further includes: a target object selection function; The target object selection function is used for: During each polling, the target count value is obtained using a preset incrementing calculator; The first calculated value is obtained by performing a modulo operation between the target count value and the total weight; Traverse all objects and determine whether the first intermediate value is equal to the second intermediate value; wherein, the first intermediate value is obtained by performing a bitwise AND operation between the first operand value and the bitmask of the current object; the second intermediate value is obtained by performing a bitwise AND operation between the bitmask of the current object and the second operand value; If the first intermediate value is equal to the second intermediate value, then the object identifier is obtained through the object class instance of the current object.

7. A data synchronization method, characterized in that, include: Based on the scheduled task mechanism in the preset development framework, target data is periodically retrieved from the enterprise resource planning system using the interface provided by the preset enterprise resource planning system. Multiple synchronization service instances are scheduled using the weighted round-robin method as described in any one of claims 1-6; The target data is synchronized to the manufacturing execution system using a scheduled synchronization service instance.

8. The data synchronization method according to claim 7, characterized in that, The method of synchronizing the target data to the manufacturing execution system through a scheduled synchronization service instance includes: Each of the target data is cached in a message queue; The system consumes the target data from the message queue through the scheduled synchronization service instance, performs deduplication verification on the target data, and then synchronizes the successfully verified target data to the manufacturing execution system.

9. A manufacturing execution system, characterized in that, The manufacturing execution system uses the weighted round-robin method as described in any one of claims 1-6 to schedule multiple objects it manages in order to achieve load balancing.

10. A terminal device, characterized in that, The terminal device includes a processor and a memory, the memory storing a computer program, and the processor executing the computer program to implement the weighted polling method according to any one of claims 1-6.