Message queue scheduling method based on centralized architecture and related equipment thereof
By dynamically adjusting the timer timeout threshold and full load management, the problem of increased service registration center delay in the centralized service discovery system is solved, and the system processing efficiency and user experience are improved.
Patent Information
- Application Number
- CN202510360114.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-07-29
AI Technical Summary
In the centralized service discovery system, when a large number of services are online at the same time, the service registration center will increase the delay in service discovery, affecting the system performance and user experience.
By obtaining the real-time system load of the service discovery system, dynamically adjust the timeout threshold of the timer, and determine the full load based on the effective load length of the message queue and the length of the individual service discovery message. Send the message immediately when the waiting time or the number of messages reaches the threshold, avoiding the message staying in the queue for too long.
It effectively reduces the average delay in service discovery under large data conditions, improves system processing efficiency, reduces the subcontract burden caused by excessive message length, and ensures the stability and response speed of the system.
Smart Images

Figure CN120390033A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technologies, and in particular, to a message queue scheduling method based on a centralized architecture, a message queue scheduling system based on a centralized architecture, an electronic device, and a computer-readable storage medium. Background Art
[0002] In the trend of the increasing complexity of the current service architecture, the number of services in the application system is extremely large. In the model of the centralized service discovery system, most of the related technologies adopt fixed time intervals to send service discovery, or random value intervals with fixed upper and lower limits to send service discovery. However, when a large number of services try to go online simultaneously, it will cause the service registration center to receive a large number of requests in a short period of time, resulting in a significant increase in the average delay of service discovery, affecting the performance and response time of the entire system, and reducing the user experience. Summary of the Invention
[0003] The present invention aims to solve at least one of the technical problems in the related technologies to some extent. To this end, the first object of the present invention is to propose a message queue scheduling method based on a centralized architecture, which can effectively reduce the delay of sending service discovery messages.
[0004] The second object of the present invention is to propose a message queue scheduling system based on a centralized architecture.
[0005] The third object of the present invention is to propose an electronic device.
[0006] The fourth object of the present invention is to propose a computer-readable storage medium.
[0007] To achieve the above object, an embodiment of the first aspect of the present invention proposes a message queue scheduling method based on a centralized architecture, which is applied to a service discovery system based on a centralized architecture. The service discovery system includes a message queue and a timer. The method is characterized in that it includes: obtaining the real-time system load of the service discovery system, and determining the timeout threshold of the timer according to the real-time system load; determining the effective load length of the message queue, and determining the full load capacity of the message queue according to the effective load length and the length of a single service discovery message; wherein, the effective load length is the available length in the message queue; in response to the waiting time of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load capacity, sending the service discovery messages in the message queue to the target address.
[0008] In addition, the message queue scheduling method based on a centralized architecture according to the above embodiment of the present invention may further have the following additional technical features:
[0009] According to some embodiments of the present invention, determining a timeout threshold of a timer according to a real-time system load includes: determining a range of timeout thresholds of the timer according to the real-time system load; determining at least one timeout threshold from the range of timeout thresholds based on a random number algorithm.
[0010] According to some embodiments of the present invention, determining a range of timeout thresholds of a timer according to a real-time system load includes: using the real-time system load as an index to determine, from a preset lookup table, the range of timeout thresholds corresponding to the real-time system load; wherein, the maximum value of the range of timeout thresholds is proportional to the real-time system load.
[0011] According to some embodiments of the present invention, determining the payload length of a message queue includes: determining the communication protocol applied by the service discovery system, and determining the communication protocol format of the message queue according to the communication protocol; determining the placeholder length of a general message in the communication protocol format; subtracting the placeholder length from the total length of the communication protocol format to obtain the payload length for carrying service discovery messages.
[0012] According to some embodiments of the present invention, determining the full load capacity of a message queue according to the payload length and the length of a single service discovery message includes: calculating the ratio of the payload length to the length of a single service discovery message, and rounding down the ratio to obtain the full load capacity.
[0013] According to some embodiments of the present invention, before sending the service discovery messages in the message queue to a target address in response to the waiting duration of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load capacity, the method further includes: listening for service online notifications in real time; in response to receiving a service online notification, parsing the service online notification and creating a service discovery message according to the service online notification; adding the service discovery message to the message queue.
[0014] According to some embodiments of the present invention, clearing the message queue; obtaining the real-time system load of the service discovery system again, and adjusting the timeout threshold of the timer according to the real-time system load to obtain an updated timeout threshold; wherein, the updated timeout threshold is used to time the sending of service discovery messages at the next moment.
[0015] According to the message queue scheduling method based on a centralized architecture in embodiments of the present invention, by dynamically updating the timer timeout threshold according to the real-time system load, the efficiency of the system in processing data is improved. In addition, the message queue scheduling method based on the centralized architecture provided by the present invention can also perform message scheduling according to the full load capacity of the message queue, and immediately send service discovery messages when the message queue reaches the full load capacity, so as to avoid slow service online caused by service discovery data staying in the process for too long, and at the same time reduce the burden on the system caused by packet splitting due to too long message length, effectively reducing the average service discovery latency under the condition of large data volume.
[0016] To achieve the above object, an embodiment of the second aspect of the present invention provides a message queue scheduling system based on a centralized architecture, which is applied to a service discovery system based on a centralized architecture. The service discovery system includes a message queue and a timer. The system includes:
[0017] An acquisition module, configured to acquire the real-time system load of the service discovery system and determine the timeout threshold of the timer according to the real-time system load;
[0018] A determination module, configured to determine the effective load length of the message queue and determine the full load capacity of the message queue according to the effective load length and the length of a single service discovery message; wherein, the effective load length is the available length in the message queue;
[0019] A response module, configured to, in response to the waiting duration of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load capacity, send the service discovery messages in the message queue to the target address.
[0020] According to the message queue scheduling system based on the centralized architecture provided by the embodiment of the present invention, by dynamically updating the timer timeout threshold according to the real-time system load, the efficiency of the system in processing data is improved. In addition, the message queue scheduling method based on the centralized architecture provided by the present invention can also perform message scheduling according to the full load capacity of the message queue, and immediately send service discovery messages when the message queue reaches the full load capacity, so as to avoid the slow service go-live caused by the service discovery data staying in the process for too long, and at the same time reduce the burden on the system caused by packet splitting due to too long message length, effectively reducing the average service discovery delay under the condition of large data volume.
[0021] To achieve the above object, an embodiment of the third aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the above-mentioned message queue scheduling method based on the centralized architecture when executing the program.
[0022] To achieve the above object, an embodiment of the fourth aspect of the present invention provides a computer-readable storage medium, and the computer-readable storage medium stores computer instructions for causing a computer to execute the above-mentioned message queue scheduling method based on the centralized architecture.
[0023] Additional aspects and advantages of the present invention will be given in part in the following description, become apparent in part from the following description, or be learned through the practice of the present invention. Description of the Drawings
[0024] To more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the accompanying drawings required in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only those of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0025] Figure 1 It is a flowchart of the message queue scheduling method for the centralized architecture in the related art.
[0026] Figure 2 It is a schematic diagram of the centralized architecture in the related art.
[0027] Figure 3 It is a flowchart of the message queue scheduling method for the centralized architecture provided by the embodiments of the present invention.
[0028] Figure 4 It is a flowchart of determining the timeout threshold of the timer according to the real-time system load provided by the embodiments of the present invention.
[0029] Figure 5 It is a random number algorithm provided by the embodiments of the present invention.
[0030] Figure 6 It is a flowchart of determining the payload length of the message queue provided by the embodiments of the present invention.
[0031] Figure 7 It is a part of the flowchart of the message queue scheduling method based on the centralized architecture provided by the embodiments of the present invention.
[0032] Figure 8 It is another part of the flowchart of the message queue scheduling method based on the centralized architecture provided by the embodiments of the present invention.
[0033] Figure 9 It is a flowchart of the message queue scheduling method for the centralized architecture provided by the embodiments of the present invention.
[0034] Figure 10 It is a schematic diagram of a message queue scheduling system for the centralized architecture provided by the embodiments of the present invention.
[0035] Figure 11 It is a more specific schematic diagram of the hardware structure of the electronic device provided by the embodiments of the present invention.
[0036] Reference numerals: 1010 - acquisition module; 1020 - determination module; 1030 - response module; 1110 - processor; 1120 - memory; 1130 - input / output interface; 1140 - communication interface; 1150 - bus. Detailed implementation manners
[0037] To make the objectives, technical solutions, and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below with reference to specific embodiments and the accompanying drawings.
[0038] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the present invention should have the ordinary meanings understood by those with ordinary skills in the field to which the present invention pertains. The "first", "second", and similar terms used in the present invention do not indicate any order, quantity, or importance, but are only used to distinguish different components. The terms such as "comprising" or "including" mean that the elements or objects appearing before this term cover the elements or objects listed after this term and their equivalents, without excluding other elements or objects. The terms such as "connected" or "linked" are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The terms such as "upper", "lower", "left", "right", etc. are only used to indicate relative positional relationships, and when the absolute position of the object being described changes, the relative positional relationship may also change accordingly.
[0039] As described in the background art section, under the current general trend of the development of vehicle intelligence, there are hundreds of services in mainstream vehicles. In a system adopting a centralized service discovery model, there is a problem of a large average service discovery delay when a large number of services go online simultaneously. In related technologies, the sending of service discovery is usually in the form of a fixed time interval or a random value interval with fixed upper and lower limits. However, when facing a large number of services attempting to go online simultaneously, this traditional service discovery mechanism will cause the service registration center to receive a large number of requests in a short period of time. When the processing capacity of the service registration center is insufficient to handle such high-concurrency requests, there will be processing delays, resulting in a significant increase in the average delay of service discovery, thereby increasing the processing burden on the service registration center, affecting the performance and response time of the entire system, wasting network resources, and reducing the user experience.
[0040] To solve the problem of high service discovery latency caused by the large-scale service online in the vehicle intelligence scenario, the applicant found during the implementation of the present invention that the timeout value of the service discovery message sending timer can be dynamically adjusted according to the feedback value of the system load, and at the same time, the threshold of the service discovery data cache queue can be further determined according to the size of the service discovery data and the type of the bearer protocol to avoid the problem of too long latency in the sending of service discovery messages.
[0041] The technical solution of the present invention will be further described in detail below through specific embodiments.
[0042] Refer to Figure 1 , which is a flowchart of the message queue scheduling method for the centralized architecture in related technologies.
[0043] Step S101, the service process sends service information to the routing process.
[0044] Specifically, after the service processes Service 1 to Service n on the same domain go online, they will connect to the routing process in the domain. Among them, the connection can be based on the TCP / IP protocol for subsequent communication. Further, the service process can send the service information (such as service name, port number, protocol type, etc.) contained in the process to the routing process.
[0045] Step S102, the routing process stores the service information in a queue.
[0046] Specifically, after receiving the service information, the routing process will store the service information in a message queue. The message queue is used to temporarily store the service information until a certain condition (such as timer timeout) is met and then further processing is carried out.
[0047] Step S103, wait for the timer to timeout.
[0048] Specifically, there is a timer inside the routing process. The timer will timeout after a set time interval. During the process of waiting for the timer to timeout, the routing process will continuously receive service data from the service process and store it in the message queue.
[0049] Step S104, the routing process sends the service discovery message.
[0050] Specifically, the routing process combines all the service information in the queue into a service discovery message, which contains all the registered service information. Further, the routing process packs the service discovery message in the message queue and sends it to the configured target address. Among them, the target address is a special IP address used to send the message to a specific group of nodes in the network (which can be other service discovery components or clients).
[0051] Step S105, the consumer receives and distributes the service information.
[0052] Specifically, the routing process of the service consumer receives these service discovery messages from the target address and further distributes them to the consumer processes on the same domain.
[0053] Reference Figure 2 , is a schematic diagram of a centralized architecture in related technologies.
[0054] Specifically, in the related art, the basic architecture of centralized service discovery can operate orderly in a small-scale service configuration and operation environment. However, when the number of service processes is large, since the latency of a single service discovery message is the sum of the times for each step, the average latency of service discovery is large at this time. Further, it may cause the system response time to be too long, affecting the user experience.
[0055] Therefore, the embodiments of the present invention provide a message queue scheduling method based on a centralized architecture, which dynamically updates the timer timeout threshold according to the real-time system load to improve the efficiency of the system in processing data. In addition, the message queue scheduling method of the centralized architecture provided by the present invention also performs message scheduling according to the full load capacity of the message queue, and immediately sends a service discovery message when the message queue reaches the full load capacity, so as to avoid the slow service online caused by the service discovery data staying in the process for too long, and at the same time reduce the burden on the system caused by packet splitting due to too long message length, effectively reducing the average latency of service discovery under the condition of large data volume.
[0056] Reference Figure 3 , which is a flowchart of the message queue scheduling method of the centralized architecture provided by the embodiments of the present invention.
[0057] Step S301, obtain the real-time system load of the service discovery system, and determine the timeout threshold of the timer according to the real-time system load.
[0058] In a specific implementation, the real-time system load of the service discovery system can be the average load of the CPU, denoted as cpu_load_average. The CPU average load represents the average number of tasks waiting to run in the system within a specific time interval. This value can reflect the busyness of the system.
[0059] The timeout threshold of the timer is the maximum time length that the timer waits before triggering an event or performing an operation. This time length is usually measured in milliseconds (ms), seconds (s) or longer time units. Once the timer starts timing from the start, when it reaches or exceeds this threshold, a preset event or operation will be triggered. Name the lower limit of the timeout threshold of the timer as sd_offer_min, and the upper limit of the timeout threshold as sd_offer_max.
[0060] In this embodiment, set the lower limit value of the timeout threshold to 10, and the upper limit value of the timeout threshold to 100, with the unit of ms. Further, the values of sd_offer_min and sd_offer_max can be determined according to the range of cpu_load_average.
[0061] Reference Figure 4, which is a flowchart for determining the timeout threshold of a timer according to the real-time system load provided by an embodiment of the present invention.
[0062] As an optional embodiment, determining the timeout threshold of a timer according to the real-time system load includes:
[0063] Step S401, determining the timeout threshold range of the timer according to the real-time system load;
[0064] Step S402, determining at least one timeout threshold from the timeout threshold range based on a random number algorithm.
[0065] As an optional embodiment, determining the timeout threshold range of the timer according to the real-time system load includes: using the real-time system load as an index to determine the corresponding timeout threshold range from a preset lookup table; wherein, the maximum value of the timeout threshold range is proportional to the real-time system load.
[0066] Specifically, referring to Table 1, which is a preset lookup table of a timeout threshold provided by an embodiment of the present invention.
[0067] level cpu_load_average sd_offer_min(ms) sd_offer_max(ms) 1 [0,40%) 10 30 2 [40%,60%) 10 50 3 [60%,80%) 10 70 4 [80%,100%] 10 100
[0068] Table 1
[0069] As can be seen from Table 1, the real-time system load can be set to four levels, namely level1-level4. Further, different system load levels correspond to corresponding timeout threshold value ranges. Among them, when the real-time system load is smaller, the timeout threshold value range is smaller; when the real-time system load is larger, the timeout threshold value range is larger. Using the real-time system load as an index, the timeout threshold value range is determined according to different levels in the preset lookup table, and then the corresponding timeout threshold is calculated through a random number generation algorithm.
[0070] For example, when the real-time system load (cpu_load_average) is 50%, after index lookup, the level of the real-time system load at this time is level 2, and the corresponding timeout threshold range of the timer is 10ms - 50ms.
[0071] It should be noted that in the way of obtaining the timeout threshold provided in Table 1, there may be a situation where the timeout thresholds generated by random numbers are the same when the system load is at different levels. For example, when the system load is 35%, the system load is at level1, and the timeout threshold generated by the random number algorithm is 28ms. When the system load is 50%, the system load is at level2, and the timeout threshold generated by the random number algorithm can also be 28ms. At this time, it cannot be ensured that when the system load is large, the generated timeout threshold is correspondingly large. Therefore, after randomly generating the timeout threshold, the value of the timeout threshold can be further limited. That is, assuming that the system load is at level2, the generated timeout threshold is judged at this time. If the generated timeout threshold is greater than the maximum value of level1, it can be directly used. If the generated timeout threshold is less than the maximum value of level1, a random number will be regenerated and further judged.
[0072] Referring to Table 2, another preset lookup table for the timeout threshold provided by the embodiment of the present invention is shown.
[0073]
[0074]
[0075] Table 2
[0076] As can be seen from Table 2, the real-time system load can be set to four levels, namely level1-level4. Further, corresponding timeout threshold value ranges correspond to different system load levels. Among them, when the system load is smaller, the value of the timeout threshold is smaller, and when the system load is larger, the value of the timeout threshold is smaller. The system further calculates the corresponding timeout threshold through the random number generation algorithm according to the timeout threshold value ranges of different levels.
[0077] Reference Figure 5 , a random number algorithm provided by the embodiment of the present invention is shown.
[0078] Specifically, the algorithm includes a function signature:
[0079] std::chrono::milliseconds / / refers to the function return type, indicating that the returned time length is in milliseconds;
[0080] service_discovery_impl::get_random_chrono_value_by_range / / refers to the function name, indicating that it is a class member function of service_discovery_impl;
[0081] std::uint32_t min, std::uint32_t max / / Refer to the parameters of the function, representing the lower and upper limits of the random time value respectively;
[0082] The algorithm also includes a random number generator:
[0083] std::default_random_engine generator / / Refer to creating a random number generator object generator. std::default_random_engine is a default random number engine provided by the standard library;
[0084] std::chrono::steady_clock::now().time_since_epoch().count() / / Refer to the seed used to initialize the random number generator. Among them, std::chrono::steady_clock::now() refers to obtaining the current time point, time_since_epoch() refers to obtaining the duration from a certain fixed time point (usually the system startup time) to now, and count() refers to converting this time into the number of clock cycles (a very large integer). This value is used as the seed of the random number to ensure that the random number sequence generated each time the program runs is different.
[0085] The algorithm also includes a uniform distribution:
[0086] std::uniform_int_distribution<std::uint32_t> distribution(min, max) / / Refer to a uniform distribution object distribution. This distribution will generate random integers within the range [min, max]. uint32_t refers to the type of the generated random number as an unsigned 32-bit integer.
[0087] The algorithm also includes generating a random millisecond value:
[0088] return std::chrono::milliseconds(distribution(generator)) / / Refer to using generator to generate a random number and restricting it within the range [min, max] through distribution. Further, convert the generated random integer into a time length of type std::chrono::milliseconds and use it as the return value of the function.
[0089] It should be noted that other random number generation algorithms can also be used for the random generation method of the timeout threshold, such as differential evolution algorithm, ant colony algorithm, genetic algorithm, etc. The random number generation algorithm can be replaced according to actual needs.
[0090] By obtaining the real-time system load of the service discovery system and dynamically adjusting the timeout threshold of the timer according to the real-time system load, it can be ensured that the system can efficiently process information under different load conditions, effectively guaranteeing the efficient operation and stability of the system.
[0091] Step S302: Determine the effective payload length of the message queue, and determine the full load capacity of the message queue according to the effective payload length and the length of a single service discovery message; where the effective payload length is the available length in the message queue.
[0092] Specifically, during the message transmission process, in addition to the actual data content, the message queue also includes some additional information, such as protocol headers, checksums, etc. Therefore, the length that can store data content in the message queue is the effective payload length, without calculating the additional information.
[0093] Reference Figure 6 , which is the flowchart for determining the effective payload length of the message queue provided by the embodiment of the present invention.
[0094] As an optional embodiment, determining the effective payload length of the message queue includes:
[0095] Step S601: Determine the communication protocol applied by the service discovery system, and determine the communication protocol format of the message queue according to the communication protocol;
[0096] Specifically, the communication formats of message queues for different communication protocols are generally different. Taking the UDP protocol as an example, generally, the UDP protocol itself does not define a message format, and it can define a format based on the service discovery system (such as SOME / IP-SD) on the basis of UDP. Further, the message format of SOME / IP-SD includes two parts: a header and a payload. The header consists of multiple fields, including message ID, length, request ID, protocol version, interface version, message type, and return code, etc. The payload part is used to carry the specific message content of service discovery.
[0097] Step S602: Determine the placeholder length of the general message in the communication protocol format;
[0098] Specifically, the placeholders for general messages in the communication protocol format generally include fixed-length fields and variable-length fields. Taking the UDP protocol as an example, the fixed-length field can be a fixed header, whose length is fixed (usually 2 bytes or more, depending on the protocol version and the setting of flag bits), while the variable-length field can be a variable header, whose length depends on the length of the topic name and the existence of fields such as message identifiers.
[0099] In addition, the placeholders for general messages in the communication protocol format may also include check codes, which are mainly used to detect errors during data transmission or storage and can help identify whether the data has been accidentally modified. In step S603, subtract the placeholder length from the total length of the communication protocol format to obtain the effective payload length for carrying service discovery messages.
[0100] Specifically, subtracting the placeholder length from the total length of the communication protocol format can obtain the effective payload length for carrying service discovery messages. Taking the UDP protocol as an example, assume that the fixed header length is h1 and the length of the service discovery application layer protocol header (i.e., the variable header) is h2. Further, subtracting the fixed header length and the service discovery application layer protocol header length from the total length of the UDP protocol can obtain an effective payload length of L.
[0101] It should be noted that since the communication protocol format may contain multiple optional fields and variable-length fields, various situations may need to be considered in actual calculations. In addition, the calculation of the effective payload length may also be affected by additional header information that may be added by the network transport layer (such as the TCP / IP layer).
[0102] As an optional embodiment, determining the full load of the message queue according to the effective payload length and the length of a single service discovery message includes: calculating the ratio of the effective payload length to the length of a single service discovery message, and rounding down the ratio to obtain the full load.
[0103] Specifically, the calculation formula for the full load can be:
[0104]
[0105] where K is the length of the service discovery message, L is the effective payload length, is the full load, representing rounding down the result.
[0106] In step S303, in response to the waiting duration of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load, send the service discovery messages in the message queue to the target address.
[0107] Specifically, if the current state of the system is that the waiting duration of the message queue reaches a preset timeout threshold, or the number of service discovery messages in the message queue reaches the full load capacity, select the service discovery messages to be sent from the message queue. Among them, the service discovery messages can be packed, encrypted, or other preprocessing operations according to the requirements of the target address and the communication protocol. The target address can be a server, a service registry, or other system components capable of processing these messages.
[0108] Reference Figure 7 , which is a part of the flowchart of the message queue scheduling method based on the centralized architecture provided by the embodiments of the present invention.
[0109] As an optional embodiment, after the service discovery messages in the message queue reach the target address in response to the waiting duration of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load capacity, the method further includes:
[0110] Step S701, monitor the service online notification in real time;
[0111] Specifically, the system sets up a listener to capture the event notification of service online in real time. These notifications may come from the registration request of the service itself or from other monitoring and discovery mechanisms.
[0112] Step S702, in response to receiving the service online notification, parse the service online notification and create a service discovery message according to the service online notification;
[0113] Specifically, when receiving the service online notification, the listener parses the notification content and extracts the relevant information of the service, such as the service name, version number, IP address, port number, etc.; further, according to the parsed service information, the system constructs a service discovery message. This message usually contains the unique identifier of the service, location information, metadata, etc., so that other services can discover and communicate with it.
[0114] Step S703, add the service discovery message to the message queue.
[0115] Specifically, the created service discovery message is added to the message queue for waiting to be processed. Among them, the queue is used to store the service discovery messages to be sent or processed. Further, the system continuously monitors the status of the message queue, including the number of messages in the queue and the waiting time of each message.
[0116] Reference Figure 8 , which is another part of the flowchart of the message queue scheduling method based on the centralized architecture provided by the embodiments of the present invention.
[0117] As an optional embodiment, after the service discovery messages in the message queue are sent to the target address, the method further includes:
[0118] Step S801, clear the message queue;
[0119] Specifically, after the service discovery message in the message queue is sent to the target address, clear all the sent messages in the message queue to ensure that only new messages to be processed are included in the queue.
[0120] Step S802, obtain the real-time system load of the service discovery system again, and adjust the timeout threshold of the timer according to the real-time system load to obtain an updated timeout threshold; wherein, the updated timeout threshold is used to time the sending of the service discovery message at the next moment.
[0121] Specifically, after clearing the message queue, obtain the real-time system load of the service discovery system again. Further, determine the timeout threshold of the timer according to the current real-time system load to obtain an updated timeout threshold. The adjusted updated timeout threshold is used as the timing reference for sending the service discovery message at the next moment, and further wait for the sending of the next service discovery message.
[0122] It should be noted that the priority of the number of service discovery messages in the message queue reaching the full load amount is higher than the waiting duration of the message queue reaching the preset timeout threshold. That is, when there are service discovery messages in the message queue, and the number of service discovery messages has not reached the full load amount while the waiting duration reaches the preset timeout threshold, at this time, the service discovery messages in the message queue can be sent to the target address, further clear the message queue, and update the timeout threshold according to the real-time system load; when the number of service discovery messages reaches the full load amount while the waiting duration has not reached the preset timeout threshold, there is no need to wait for the timer to time out, and the service discovery messages in the message queue can be sent to the target address, further clear the message queue, and update the timeout threshold according to the real-time system load.
[0123] Reference Figure 9 , which is the flowchart of the message queue scheduling method for the centralized architecture provided by the embodiment of the present invention.
[0124] Specifically, when it is monitored that a service process in the domain goes online, the service process connects to the routing process and sends the service information contained in the process to the routing process. Further, after receiving the service information, the routing process starts to store the service information in the message queue. At this time, the timer starts to determine the timeout threshold according to the real-time system load and starts timing. At the same time, the message queue calculates the full load amount of the message queue according to the communication protocol and judges whether the number of service discovery messages in the message queue reaches the full load amount.
[0125] When the waiting duration of the timer reaches the preset timeout threshold and there is a service discovery message in the message queue, a sending action is triggered to send the service discovery message in the message queue to the target address, further empty the message queue, and update the timeout threshold according to the real-time system load; when the number of service discovery messages in the message queue reaches the full load amount, a sending action is directly triggered without waiting for the timer to timeout, send the service discovery message in the message queue to the target address, further empty the message queue, and update the timeout threshold according to the real-time system load.
[0126] As can be seen from the above, the message queue scheduling method of the centralized architecture provided by the present invention can dynamically update the timer timeout threshold according to the real-time system load to improve the efficiency of the system in processing data. In addition, the message queue scheduling method of the centralized architecture provided by the present invention can also perform message scheduling according to the full load amount of the message queue, and immediately send the service discovery message when the message queue reaches the full load amount, so as to avoid the slow service online caused by the service discovery data staying in the process for too long, and at the same time reduce the burden on the system caused by packet splitting due to too long message length, effectively reducing the average service discovery delay under the condition of large data volume.
[0127] It should be noted that the method of the embodiment of the present invention can be executed by a single device, such as a computer or a server. The method of this embodiment can also be applied to a distributed scenario and completed by multiple devices cooperating with each other. In this case of a distributed scenario, one of the multiple devices can only execute one or more steps of the method of the embodiment of the present invention, and these multiple devices will interact with each other to complete the described method.
[0128] It should be noted that some embodiments of the present invention have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be executed in a different order than in the above embodiments and still achieve the desired results. Additionally, the processes depicted in the figures do not necessarily require the specific order or sequential order shown to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0129] Based on the same inventive concept, corresponding to the method provided in any of the above embodiments, the present invention also provides a message queue scheduling system for a centralized architecture, which is applied to a service discovery system based on a centralized architecture. The service discovery system includes a message queue and a timer.
[0130] Refer to Figure 10 , which is a schematic diagram of a message queue scheduling system for a centralized architecture provided by an embodiment of the present invention.
[0131] The message queue scheduling system with a centralized architecture includes: an acquisition module 1010, a determination module 1020, and a response module 1030.
[0132] The acquisition module 1010 is configured to acquire the real-time system load of the service discovery system and determine the timeout threshold of the timer according to the real-time system load;
[0133] The determination module 1020 is configured to determine the effective payload length of the message queue and determine the full load capacity of the message queue according to the effective payload length and the length of a single service discovery message; wherein, the effective payload length is the available length in the message queue.
[0134] The response module 1030 is configured to, in response to the waiting duration of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load capacity, send the service discovery messages in the message queue to the target address.
[0135] Optionally, the acquisition module 1010 is further configured to:
[0136] Determine the timeout threshold range of the timer according to the real-time system load;
[0137] Determine at least one timeout threshold from the timeout threshold range based on a random number algorithm.
[0138] Optionally, the acquisition module 1010 is further configured to:
[0139] Use the real-time system load as an index to determine the timeout threshold range corresponding to the real-time system load from a preset lookup table; wherein, the maximum value of the timeout threshold range is proportional to the real-time system load.
[0140] Optionally, the determination module 1020 is further configured to:
[0141] Determine the communication protocol applied by the service discovery system and determine the communication protocol format of the message queue according to the communication protocol;
[0142] Determine the placeholder length of the general message in the communication protocol format;
[0143] Subtract the placeholder length from the total length of the communication protocol format to obtain the effective payload length for carrying service discovery messages.
[0144] Optionally, the determination module 1020 is further configured to:
[0145] Calculate the ratio of the effective payload length to the length of a single service discovery message and round down the ratio to obtain the full load capacity.
[0146] Optionally, the response module 1030 is further configured to:
[0147] Real-time monitoring of service online notifications;
[0148] In response to receiving the service online notification, parsing the service online notification and creating a service discovery message according to the service online notification;
[0149] Add a service discovery message to the message queue.
[0150] Optionally, the response module 1030 is further configured to:
[0151] Clear the message queue;
[0152] The real-time system load of the service discovery system is obtained again, and the timeout threshold of the timer is adjusted according to the real-time system load to obtain an updated timeout threshold; wherein the updated timeout threshold is used to time the next time a service discovery message is sent.
[0153] For the convenience of description, the above system is described as being divided into various modules according to their functions. Of course, when implementing the present invention, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0154] According to an embodiment of the present invention, a message queue scheduling system with a centralized architecture is provided. The timer timeout threshold is dynamically updated according to the real-time system load to improve the efficiency of the system in processing data. In addition, the message queue scheduling method with a centralized architecture provided by the present invention can also schedule messages according to the full load of the message queue. When the message queue reaches the full load, the service discovery message is immediately sent to avoid the service discovery data staying in the process for too long, resulting in slow service launch. At the same time, the burden on the system caused by subpackaging due to the excessive length of the message is reduced, and the average delay of service discovery under conditions with large data volumes is effectively reduced.
[0155] Based on the same inventive concept, corresponding to the message queue scheduling method of the centralized architecture of any of the above embodiments, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, the message queue scheduling method of the centralized architecture of any of the above embodiments is implemented.
[0156] Figure 11 11 shows a more specific hardware structure diagram of an electronic device provided by this embodiment. The device may include: a processor 1110, a memory 1120, an input / output interface 1130, a communication interface 1140, and a bus 1150. The processor 1110, the memory 1120, the input / output interface 1130, and the communication interface 1140 are connected to each other within the device via the bus 1150.
[0157] The processor 1110 can be implemented in the form of a general - purpose CPU (Central Processing Unit), a microprocessor, an Application Specific Integrated Circuit (ASIC), or one or more integrated circuits, etc., and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0158] The memory 1120 can be implemented in the form of a ROM (Read Only Memory), a RAM (Random Access Memory), a static storage device, a dynamic storage device, etc. The memory 1120 can store an operating system and other application programs. When implementing the technical solutions provided in the embodiments of this specification through software or firmware, the relevant program codes are stored in the memory 1120 and are called and executed by the processor 1110.
[0159] The input / output interface 1130 is used to connect to the input / output module to achieve information input and output. The input / output module can be configured as a component in the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Among them, the input device can include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device can include a display, a speaker, a vibrator, an indicator light, etc.
[0160] The communication interface 1140 is used to connect to a communication module (not shown in the figure) to achieve communication and interaction between this device and other devices. Among them, the communication module can achieve communication through a wired method (such as USB, network cable, etc.) or through a wireless method (such as a mobile network, WIFI, Bluetooth, etc.).
[0161] The bus 1150 includes a path for transmitting information between various components of the device (such as the processor 1110, the memory 1120, the input / output interface 1130, and the communication interface 1140).
[0162] It should be noted that although the above - mentioned device only shows the processor 1110, the memory 1120, the input / output interface 1130, the communication interface 1140, and the bus 1150, in the specific implementation process, this device may also include other components necessary for normal operation. In addition, those skilled in the art can understand that the above - mentioned device may also only include the components necessary to implement the solutions of the embodiments of this specification, and does not necessarily include all the components shown in the figure.
[0163] The electronic device of the above embodiment is used to implement the message queue scheduling method of the corresponding centralized architecture in any of the foregoing embodiments, and has the beneficial effects of the embodiments of the message queue scheduling method of the corresponding centralized architecture, which will not be elaborated here.
[0164] Based on the same inventive concept, corresponding to the message queue scheduling method of the centralized architecture in any of the above embodiments, the present invention also provides a non-transitory computer-readable storage medium. The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to cause a computer to execute the message queue scheduling method of the centralized architecture in any of the foregoing embodiments.
[0165] The above non-transitory computer-readable storage medium may be any available medium or data storage device accessible by a computer, including but not limited to magnetic memories (such as floppy disks, hard disks, magnetic tapes, magneto-optical discs (MO), etc.), optical memories (such as CDs, DVDs, BDs, HVDs, etc.), and semiconductor memories (such as ROMs, EPROMs, EEPROMs, non-volatile memories (NAND FLASH), solid state drives (SSD), etc.).
[0166] The computer instructions stored in the storage medium of the above embodiment are used to cause the computer to execute the method in any of the embodiments in the above exemplary method part, and have the beneficial effects of the embodiments of the message queue scheduling method of the corresponding centralized architecture, which will not be elaborated here.
[0167] In addition, although the operations of the method of the present invention are described in a specific order in the drawings, this does not require or imply that these operations must be performed in that specific order, or that all the shown operations must be performed to achieve the desired result. On the contrary, the steps depicted in the flowchart may be changed in the order of execution. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step for execution, and / or one step may be decomposed into multiple steps for execution.
[0168] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or a combination of the following well-known technologies in the art can be used: discrete logic circuits having logic gate circuits for implementing logical functions on data signals, application specific integrated circuits having appropriate combinational logic gate circuits, programmable gate arrays (PGAs), field programmable gate arrays (FPGAs), etc.
[0169] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present invention should have the ordinary meanings understood by those of ordinary skill in the art to which the present invention pertains. The "first", "second" and similar terms used in the embodiments of the present invention do not denote any order, quantity or importance, but are only used to distinguish different components. Words such as "comprising" or "including" mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Words such as "connected" or "coupled" are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Upper", "lower", "left", "right", etc. are only used to indicate relative positional relationships, and when the absolute position of the object being described changes, the relative positional relationship may also change accordingly.
[0170] Although the spirit and principles of the present invention have been described with reference to several specific embodiments, it should be understood that the present invention is not limited to the specific embodiments disclosed, and the division of each aspect does not mean that the features in these aspects cannot be combined for benefit. This division is only for convenience of expression. The present invention is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims. The scope of the appended claims is to be accorded the broadest interpretation so as to encompass all such modifications and equivalent structures and functions.
Claims
1. A message queue scheduling method based on a centralized architecture, which is applied to a service discovery system based on a centralized architecture. The service discovery system includes a message queue and a timer, and is characterized in that The method includes: Obtaining the real-time system load of the service discovery system, and determining the timeout threshold of the timer according to the real-time system load; Determining the effective payload length of the message queue, and determining the full load capacity of the message queue according to the effective payload length and the length of a single service discovery message; wherein, the effective payload length is the available length in the message queue; In response to the waiting duration of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load capacity, sending the service discovery messages in the message queue to the target address.
2. The message queue scheduling method based on a centralized architecture according to claim 1, wherein The determining the timeout threshold of the timer according to the real-time system load includes: Determining the timeout threshold range of the timer according to the real-time system load; Determining at least one of the timeout thresholds from the timeout threshold range based on a random number algorithm.
3. The message queue scheduling method based on a centralized architecture according to claim 2, wherein The determining the timeout threshold range of the timer according to the real-time system load includes: Using the real-time system load as an index to determine the corresponding timeout threshold range of the real-time system load from a preset lookup table; wherein, the maximum value of the timeout threshold range is proportional to the real-time system load.
4. The message queue scheduling method based on a centralized architecture according to claim 1, characterized in that, The determining the effective payload length of the message queue includes: Determining the communication protocol applied by the service discovery system, and determining the communication protocol format of the message queue according to the communication protocol; Determining the placeholder length of the general message in the communication protocol format; Subtracting the placeholder length from the total length of the communication protocol format to obtain the effective payload length for carrying the service discovery message.
5. The message queue scheduling method based on a centralized architecture according to claim 4, wherein, The determining the full load capacity of the message queue according to the effective payload length and the length of a single service discovery message includes: Calculating the ratio of the effective payload length to the length of a single service discovery message, and rounding down the ratio to obtain the full load capacity.
6. The message queue scheduling method based on a centralized architecture according to claim 5, wherein Before the step of, in response to the waiting duration of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load capacity, sending the service discovery messages in the message queue to the target address, the method further includes: Listening for service online notifications in real time; In response to receiving a service online notification, parsing the service online notification and creating a service discovery message according to the service online notification; Adding the service discovery message to the message queue.
7. The message queue scheduling method based on a centralized architecture according to claim 6, wherein, After the step of sending the service discovery messages in the message queue to the target address, the method further includes: Clearing the message queue; Obtaining the real-time system load of the service discovery system again, and adjusting the timeout threshold of the timer according to the real-time system load to obtain an updated timeout threshold; wherein, the updated timeout threshold is used to time the sending of service discovery messages at the next moment.
8. A message queue scheduling system based on a centralized architecture, which is applied to a service discovery system based on a centralized architecture. The service discovery system includes a message queue and a timer, and is characterized in that including: An obtaining module, configured to obtain the real-time system load of the service discovery system, and determine the timeout threshold of the timer according to the real-time system load; A determination module, configured to determine the payload length of the message queue, and determine the full load capacity of the message queue according to the payload length and the length of a single service discovery message; wherein, the payload length is the available length in the message queue; A response module, configured to, in response to the waiting duration of the message queue reaching the timeout threshold or the number of service discovery messages in the message queue reaching the full load capacity, send the service discovery messages in the message queue to a target address.
9. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the message queue scheduling system based on a centralized architecture according to any one of claims 1 to 7.
10. A computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to implement the message queue scheduling system based on a centralized architecture according to any one of claims 1 to 7.