Dynamic load balancing method, apparatus, medium, and electronic device
By introducing a dynamic load balancing module and auxiliary plugins into Nginx, a worker process cluster is built to dynamically synchronize upstream configuration information, which solves the problem of system resource degradation and rapid QPS drop caused by Nginx restarts, and improves the performance and processing efficiency of the proxy server.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU FANGGUI INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2023-03-28
- Publication Date
- 2026-07-21
AI Technical Summary
In existing technologies, restarting Nginx leads to a decrease in system resources and a sharp drop in QPS, an increase in the number of old worker processes, and an increased processing burden on the proxy server.
By introducing a dynamic load balancing module and auxiliary plugins into the proxy server, a worker process cluster is built to dynamically synchronize upstream configuration information, avoiding the need to restart worker processes and enabling dynamic adjustment of configuration information.
It improved the performance of the proxy server, reduced the processing burden, and ensured the stability and efficiency of QPS.
Smart Images

Figure CN116436921B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of load balancing technology, and in particular to a dynamic load balancing method, apparatus, medium, and electronic device. Background Technology
[0002] A proxy server is an intermediary in the network, forwarding access requests to backend servers and handling load balancing. Dynamic load balancing distributes tasks based on the server's real-time load status, effectively improving server performance. Nginx (engine x), a high-performance HTTP and proxy server, is widely used in load balancing services.
[0003] The following uses Nginx as an example to illustrate dynamic load balancing methods in related technologies. In these technologies, when a client running on a user device sends a request to Nginx, the worker processes receive the request and, based on the upstream configuration information, forward it to the backend servers for processing. Modifying the upstream configuration information in these technologies requires a reload operation to reload the upstream configuration. This reload operation restarts the worker processes. Firstly, after Nginx has been used for a period of time, the number of Nginx worker processes increases, and restarting all of them will lead to a decrease in system resources. Furthermore, the mutex lock contention between worker processes during restarts will cause a rapid drop in QPS (Queries Per Second, i.e., maximum throughput). Secondly, older worker processes will only release their resources after completing the current request's task. Therefore, if there are dead connections between older worker processes and backend servers, the number of older worker processes will increase exponentially with the number of reloads over a period of time, leading to a decrease in Nginx performance and an increased processing burden on Nginx. Summary of the Invention
[0004] To overcome the problems existing in related technologies, this application provides a dynamic load balancing method, apparatus, medium, and electronic device, which can improve the performance of proxy servers and reduce the processing burden of proxy servers.
[0005] According to a first aspect of the embodiments of this application, a dynamic load balancing method is provided, comprising the following steps:
[0006] After the proxy server configuration is parsed, the first upstream configuration information of the proxy server is obtained and saved to the dynamic load balancing module; the first upstream configuration information includes information on several servers that the proxy server reverse proxies.
[0007] When the dynamic load balancing module starts its working process, it configures an auxiliary plugin for each working process, stores the first upstream configuration information in the auxiliary plugin, and builds a working process cluster based on the auxiliary plugin; wherein, each working process forwards the data processing request sent by the client to the reverse proxy server based on the first upstream configuration information in its respective auxiliary plugin;
[0008] Upon receiving an upstream configuration information change request, based on the worker process cluster, update the first upstream configuration information in the auxiliary plugin of the worker process to obtain the second upstream configuration information, and synchronize the second upstream configuration information to the dynamic load balancing module.
[0009] According to a second aspect of the embodiments of this application, a dynamic load balancing device is provided, comprising:
[0010] The configuration information acquisition module is used to acquire the first upstream configuration information of the proxy server after the proxy server configuration is parsed, and save the first upstream configuration information to the dynamic load balancing module; the first upstream configuration information includes information on several servers that the proxy server reverse proxies.
[0011] The configuration information storage module is used to configure an auxiliary plugin for each working process when the dynamic load balancing module starts its working process, store the first upstream configuration information in the auxiliary plugin, and build a working process cluster based on the auxiliary plugin; wherein, each working process forwards the data processing request sent by the client to the reverse proxy server based on the first upstream configuration information in its respective auxiliary plugin;
[0012] The configuration information update module is used to receive upstream configuration information change requests, update the first upstream configuration information in the auxiliary plugin of the worker process based on the worker process cluster, obtain the second upstream configuration information, and synchronize the second upstream configuration information to the dynamic load balancing module.
[0013] According to a third aspect of the present application, an electronic device is provided, including a processor and a memory; the memory stores a computer program adapted to be loaded by the processor and executed as described above in the dynamic load balancing method.
[0014] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided, on which a computer program is stored, characterized in that the computer program, when executed by a processor, implements the dynamic load balancing method as described above.
[0015] This embodiment of the application obtains the first upstream configuration information of the proxy server after the proxy server configuration is parsed, and saves the first upstream configuration information to the dynamic load balancing module; when the dynamic load balancing module starts its working process, it configures an auxiliary plugin for each working process, stores the first upstream configuration information in the auxiliary plugin, and builds a working process cluster based on the auxiliary plugin; upon receiving an upstream configuration information change request, it updates the first upstream configuration information in the auxiliary plugin of the working process based on the working process cluster to obtain second upstream configuration information, and synchronizes the second upstream configuration information to the dynamic load balancing module. Thus, when the upstream configuration information changes, there is no need to perform a reload operation or restart the working process. Based on the dynamic load balancing module, auxiliary plugin, and working process cluster, the upstream configuration information of the working process and the proxy server is dynamically synchronized and adjusted, thereby improving the performance of the proxy server and reducing the processing burden of the proxy server.
[0016] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application.
[0017] To better understand and implement this invention, the following detailed description is provided in conjunction with the accompanying drawings. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 A schematic block diagram illustrating the application environment of the dynamic load balancing method provided in the embodiments of this application;
[0020] Figure 2 A flowchart of the dynamic load balancing method provided in the embodiments of this application;
[0021] Figure 3 A schematic diagram illustrating the dynamic load balancing principle provided in the embodiments of this application;
[0022] Figure 4 A flowchart illustrating the method for configuring local information of the synchronization assistance plugin and proxy server provided in the embodiments of this application;
[0023] Figure 5 A schematic block diagram of the dynamic load balancing device provided in this application;
[0024] Figure 6 A schematic block diagram of the structure of the electronic device provided in this application. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0026] It should be understood that the described embodiments are merely some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of the embodiments of this application.
[0027] In the following description, when referring to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. In the description of this application, it should be understood that the terms "first," "second," "third," etc., are used only to distinguish similar objects and are not necessarily used to describe a specific order or sequence, nor should they be construed as indicating or implying relative importance. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances. The singular forms "a," "the," and "the" used in this application and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. The word "if" as used herein can be interpreted as "when," "when," or "in response to determination."
[0028] Furthermore, in the description of this application, unless otherwise stated, "multiple" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0029] Those skilled in the art will understand that the terms "client," "terminal," and "terminal device" as used in this application include not only devices that are wireless signal transmitters, which are wireless signal transmitters with only transmitting capabilities, but also devices that are wireless signal receivers, which are wireless signal receivers with only receiving capabilities, and devices that have receiving and transmitting hardware capable of bidirectional communication on a bidirectional communication link. Such devices may include: cellular or other communication devices such as personal computers or tablets, having a single-line display, a multi-line display, or no multi-line display; PCS (Personal Communications Service), which can combine voice, data processing, fax, and / or data communication capabilities; PDA (Personal Digital Assistant), which may include a radio frequency receiver, pager, internet / intranet access, web browser, notepad, calendar, and / or GPS (Global Positioning System) receiver; and conventional laptops and / or handheld computers or other devices that have and / or include radio frequency receivers. As used herein, "client," "terminal," and "terminal device" can be portable, transportable, installed in a means of transportation (air, sea, and / or land), or suitable and / or configured to operate locally and / or in a distributed manner, operating in any other location on Earth and / or in space. "Client," "terminal," and "terminal device" as used herein can also be a communication terminal, an internet access terminal, or a music / video playback terminal, such as a PDA, a MID (Mobile Internet Device), and / or a mobile phone with music / video playback capabilities, or a smart TV, set-top box, etc.
[0030] The hardware referred to by the names "server," "client," and "service node" in this application is essentially a computer device with the equivalent capabilities of a personal computer. It is a hardware device with the necessary components revealed by the von Neumann architecture, such as a central processing unit (including an arithmetic logic unit and a control unit), memory, input devices, and output devices. The computer program is stored in its memory, and the central processing unit loads the program stored in the secondary storage into the main memory to run it, execute the instructions in the program, and interact with the input and output devices to complete specific functions.
[0031] It should be noted that the concept of "server" used in this application can also be extended to the case of server clusters. Based on the network deployment principles understood by those skilled in the art, the servers should be logically divided. Physically, these servers can be independent of each other but accessible through interfaces, or they can be integrated into a single physical computer or a computer cluster. Those skilled in the art should understand this flexibility and should not use it to constrain the implementation of the network deployment method in this application.
[0032] Please see Figure 1 , Figure 1 This is a schematic diagram of an application scenario for the dynamic load balancing method provided in this application embodiment. The application scenario includes a client 10, a proxy server 20, and a backend server 30.
[0033] Client 10 interacts with backend server 30 via proxy server 20. Specifically, client 10, proxy server 20, and backend server 30 can all access the Internet via network access, thereby establishing data communication links between client 10 and proxy server 20, and between proxy server 20 and backend server 30. The network can be any type of communication medium capable of providing communication links between client 10 and proxy server 20, and between proxy server 20 and backend server 30, such as wired communication links, wireless communication links, or fiber optic cables, etc., and this application does not impose any limitations on this.
[0034] Client 10 refers to the end that sends an access request to backend server 30. The hardware referred to by client 10 essentially refers to computer equipment, specifically, it can be computer equipment such as smartphones, smart interactive whiteboards, and personal computers.
[0035] Proxy server 20 refers to the end that forwards access requests to backend server 30. Proxy server 20 acts as a relay station for network information, primarily used to forward access requests from client 10 and perform load balancing. The hardware that proxy server 20 refers to is essentially a computer device, such as a computer. In this embodiment, proxy server 20 can be an Nginx device or other proxy devices.
[0036] It should be noted that for a backend server 30, there may be one or more proxy servers 20. The access request sent by the client 10 to the backend server 30 can be forwarded to the backend server 30 through one of the proxy servers 20.
[0037] The backend server 30 can be a server cluster system for data processing, consisting of multiple servers. For example, it can act as a business server, further connecting to related audio data servers, video streaming servers, and other servers providing related support, thus forming a logically interconnected service cluster to serve related terminal devices, such as… Figure 1 The client 10 shown provides services.
[0038] In practical applications, backend servers 30 are typically deployed in a cluster. For example, five computers can be deployed as backend servers 30, providing the same functionality and forming a backend server cluster. When client 10 sends a request to proxy server 20, proxy server 20 forwards the request to one of the five computers for further processing according to forwarding rules. This distributes client 10's request across the five computers, improving data processing capabilities.
[0039] To better understand the technical solution of this application, the following describes the load balancing technical solution in related technologies.
[0040] When implementing load balancing performance, a proxy server needs to obtain upstream configuration information. This upstream configuration information indicates the information of several backend servers that the proxy server reverse proxies, as well as the load balancing algorithm. Backend server information may include, but is not limited to, the IP address of the backend server and the port number it listens on. The load balancing algorithm can be any one or more algorithms based on relevant technologies, such as round-robin, weighted random, and least-connection algorithms.
[0041] To improve the load balancing performance of a proxy server, it is typically configured with worker processes to quickly process client requests. The number of worker processes can be configured as needed, generally corresponding to the number of CPU cores.
[0042] Specifically, taking a live streaming application scenario as an example, when the host client 10 or the viewer client 10 sends a live streaming data processing request to the proxy server, the worker process will receive the live streaming data processing request and forward it to the real backend server for processing according to the upstream configuration information of the proxy server.
[0043] During peak live streaming periods, when the number of live data processing requests sent by the broadcaster client 10 or the viewer client 10 increases, the pressure on the backend server 30 increases, requiring server expansion. Alternatively, when the operation and maintenance platform connected to the backend server 30 detects changes in the backend server 30, it is necessary to modify the upstream configuration information of the proxy server accordingly.
[0044] In related technologies, after modifying the upstream configuration information of a proxy server, a reload operation is required to reload the upstream configuration information. This reload operation restarts the worker processes. On the one hand, after the proxy server has been used for a period of time, the number of worker processes increases. Restarting all of them will lead to a decrease in system resources. Moreover, during the restart, the mutual exclusion lock contention between the worker processes will cause a rapid drop in QPS (Queries Per Second, which is the number of queries a server can respond to per second, a measure of the amount of traffic a specific query server can handle within a specified time, i.e., the number of response requests per second, or the maximum throughput). On the other hand, the old worker processes will only release their resources after completing the tasks of the current requests. Therefore, if there are dead connections between the old worker processes and the backend servers, the number of old worker processes will increase exponentially with the number of reloads over a period of time, leading to a decrease in proxy server performance and an increase in the processing burden of the proxy server.
[0045] To address the aforementioned issues, this application provides a dynamic load balancing method. Please refer to... Figure 2 , Figure 2 This is a flowchart illustrating the dynamic load balancing method provided in an embodiment of this application. The dynamic load balancing method in this embodiment includes the following steps:
[0046] Step S101: After the proxy server configuration is parsed, obtain the first upstream configuration information of the proxy server and save the first upstream configuration information to the dynamic load balancing module; the first upstream configuration information includes information on several servers that the proxy server reverse proxies.
[0047] The proxy server is configured with a dynamic load balancing module, which is a third-party plugin. It is used to receive user requests to change the configuration information of the first upstream, forward the request to the auxiliary plugin, and periodically check the latest first upstream configuration information of the auxiliary plugin and update its own first upstream configuration information.
[0048] In this embodiment, the dynamic load balancing module is a dynups module (Nginx_yy_dynups_module, hereinafter referred to as the dynups module), and the dynamic load balancing method of this application can be executed by the dynamic load balancing module. Specifically, the dynamic load balancing module obtains and saves the upstream configuration information. In the actual solution, the proxy server stores the first upstream configuration information. After the proxy server configuration is parsed, the dynamic load balancing module is started to obtain the first upstream configuration information and store it in the dynamic load balancing module.
[0049] The first upstream configuration information includes one or more upstream configuration files. These upstream configuration files include information about several backend servers configured for reverse proxying by the proxy server, as well as the load balancing algorithm. Backend server information may include, but is not limited to, the IP addresses of the backend servers and the port numbers they listen on. The load balancing algorithm can be any one or more algorithms based on relevant technologies, such as round-robin, weighted random, and least-connection algorithms.
[0050] Step S102: When the dynamic load balancing module starts the working process, an auxiliary plugin is configured for each working process, the first upstream configuration information is stored in the auxiliary plugin, and a working process cluster is built based on the auxiliary plugin; wherein, each working process forwards the data processing request sent by the client to the reverse proxy server based on the first upstream configuration information in its own auxiliary plugin.
[0051] When the dynamic load balancing module starts its working process, it will trigger the startup of auxiliary plugins, thereby configuring auxiliary plugins for each working process and storing upstream configuration information in the auxiliary plugins corresponding to the working process.
[0052] It should be understood that the working process is accompanied by a dynamic load balancing module and an auxiliary plugin. The first upstream configuration information stored in the dynamic load balancing module is used to indicate the configuration currently in use, and the first upstream configuration information stored in the auxiliary plugin is used to indicate the latest changed configuration.
[0053] Auxiliary plugins are tools that assist in data interaction and storage, and they are set up within each worker process. On one hand, auxiliary plugins provide interfaces for the dynamic load balancing module to call, enabling dynamic synchronization of upstream configuration information between the auxiliary plugin and the dynamic load balancing module. On the other hand, they establish collaborative connections among the various worker processes, building a worker process cluster to achieve dynamic synchronization of upstream configuration information among the various worker processes.
[0054] In this embodiment, the dynamic load balancing module also includes shared memory. When a worker process starts and calls an auxiliary plugin, the shared memory records the process's starting number to maintain a process startup count. During a reload operation, when the first process in a new batch starts, it retrieves the current process's startup count from the shared memory and broadcasts it to other processes within the worker process cluster. However, it should be noted that the shared memory in this application is not used to store upstream configuration information; it only records the process startup count. Once a worker process starts, the shared memory data will no longer be accessed.
[0055] Step S103: Receive the upstream configuration information change request, update the first upstream configuration information in the auxiliary plugin of the worker process based on the worker process cluster, obtain the second upstream configuration information, and synchronize the second upstream configuration information to the dynamic load balancing module.
[0056] Upstream configuration information change requests can be sent by the client, the backend server, or the maintenance equipment connected to the backend server. Specifically, taking a live streaming application scenario as an example, during peak live streaming periods, when the number of live data processing requests sent by the broadcaster's client or the viewer's client increases, the pressure on the backend server increases. When the conditions for expanding the backend server are met, or when the maintenance platform connected to the backend server detects a change in the backend server, the backend server cluster or maintenance platform will send an upstream configuration information change request to the proxy server.
[0057] Upstream configuration information change requests can include adding or modifying the upstream configuration file identifier and updating the upstream configuration file content.
[0058] It is understandable that after receiving the upstream configuration information change request, the first upstream configuration information in the auxiliary plugin of each worker process will be updated based on the worker process cluster to obtain the second upstream configuration information. At the same time, each worker process synchronizes the updated second upstream configuration information to the dynamic load balancing module based on the dynamic load balancing module that is matched with its auxiliary plugin. Then, the dynamic load balancing module updates the first upstream configuration information initially stored by the proxy server to the second upstream configuration information.
[0059] This application embodiment obtains the first upstream configuration information of the proxy server after the proxy server configuration is parsed, and saves the first upstream configuration information to the dynamic load balancing module. When the dynamic load balancing module starts its working process, it configures an auxiliary plugin for each working process, stores the first upstream configuration information in the auxiliary plugin, and builds a working process cluster based on the auxiliary plugin. Upon receiving a request to change the upstream configuration information, it updates the first upstream configuration information in the auxiliary plugin of the working process based on the working process cluster to obtain the second upstream configuration information, and synchronizes the second upstream configuration information to the dynamic load balancing module. Thus, when the upstream configuration information changes, there is no need to reload or restart the working process. Based on the dynamic load balancing module, auxiliary plugin, and working process cluster, the upstream configuration information of the working process and the dynamic load balancing module is dynamically and synchronously adjusted, thereby improving the performance of the proxy server and reducing the processing burden of the proxy server.
[0060] In an optional embodiment, after step S102, which involves building a worker process cluster based on the auxiliary plugin, the following steps are included:
[0061] Step S1021: Based on the auxiliary plugin, determine one of the working processes as the main process and the other working processes as slave processes according to the preset main process determination method.
[0062] A worker process is a process in which all business logic is performed. When the Reactor thread receives data from the client, it packages the data and sends it to a worker process through a pipe.
[0063] like Figure 3 As shown, the master process, also known as the management process, is a special process among the worker processes. There is only one master process, which is responsible for receiving external information, such as receiving upstream configuration information change requests. The master process also periodically synchronizes the status information of the master process with other slave processes.
[0064] There can be multiple slave processes. Generally speaking, in addition to the master process, the remaining slave processes are responsible for handling external requests.
[0065] Understandably, since all worker processes reside on the same proxy server host, the main process can be quickly and easily identified. In an optional embodiment, the main process can be determined using process locks, such as file locks. Specifically, as each auxiliary plugin runs alongside the worker processes, it attempts to lock a local file. The worker process corresponding to the auxiliary plugin that successfully locks that file is the main process.
[0066] Step S103, which involves receiving an upstream configuration information change request and updating the first upstream configuration information within the auxiliary plugin of each worker process based on the worker process cluster, includes:
[0067] Step S1031: Receive the upstream configuration information change request, update the first upstream configuration information in the auxiliary plugin corresponding to the main process, and obtain the second upstream configuration information; based on the worker process cluster, synchronize the second upstream configuration information to all slave processes.
[0068] The main process updates the upstream configuration information of its auxiliary plugins based on the received upstream configuration information change request, obtains the second upstream configuration information, and provides the updated second upstream configuration information to the slave processes for querying.
[0069] A process compares its own upstream configuration information with the upstream configuration information of the master process or other processes in the worker process cluster. If a process's upstream configuration information is newer than its own, then the process updates its own upstream configuration information.
[0070] This application embodiment updates the upstream configuration information of the auxiliary plugin of the main process when it receives a request to change the upstream configuration information, thereby obtaining the second upstream configuration information. Based on the worker process cluster, the second upstream configuration information is synchronized to the auxiliary plugins of all slave processes, so that each process does not interfere with each other when updating, avoiding resource competition and avoiding the problem of low update efficiency caused by waiting in queue to complete the update. This can achieve efficient and fast updating of upstream configuration information.
[0071] In an optional embodiment, step S1021, which determines one of the working processes as the main process and the others as slave processes based on the auxiliary plugin and according to a preset main process determination method, includes:
[0072] Step S10211: Each of the aforementioned working processes performs a file locking operation based on the auxiliary plugin, and the working process corresponding to the auxiliary plugin that successfully locks the file is determined as the main process, and the other working processes are determined as slave processes.
[0073] Since all the worker processes in this application are located within the same proxy server host and are in the same worker process cluster, the master process and slave processes can be quickly and synchronously determined by executing file locks.
[0074] In an optional embodiment, after step S10211, where each of the worker processes performs a file locking operation based on the auxiliary plugin, and the worker process corresponding to the auxiliary plugin that successfully locks the file is determined as the master process, and other worker processes are determined as slave processes, the following steps are included:
[0075] Step S10212: If it is detected that the master process exits the worker process cluster or the state of at least one worker process in the worker process cluster changes, control each worker process in the worker process cluster to re-execute the file lock operation based on the auxiliary plugin, and re-determine the master process and slave processes.
[0076] The master process periodically broadcasts its status information (including address, name, role, etc.) so that other slave processes in the worker process cluster can know in a timely manner who the master process is, if the master process has changed, etc. At the same time, the master process also monitors the status information of each slave process. Therefore, if it detects that the master process has left the worker process cluster, for example, the original master process left the worker process cluster after reloading; or if the status of at least one worker process in the worker process cluster changes, it controls each worker process in the worker process cluster to re-execute file lock operations based on the auxiliary plugin, and re-determine the master process and slave processes, thereby ensuring the stability of the master process in the cluster, and thus achieving accurate information updates and stable dynamic load balancing.
[0077] In an optional embodiment, step S1031, which synchronizes the updated second upstream configuration information of the auxiliary plugin of the master process to all slave processes based on the worker process cluster, includes:
[0078] Step S10311: Based on the worker process cluster, synchronize the second upstream configuration information to all slave processes according to the epidemic protocol.
[0079] The Epidemic Protocol (also known as the Gossip Protocol) is a peer-to-peer distributed protocol. Its core is to achieve consistency of state information across the entire cluster by partially transmitting information in a decentralized structure. The failure or restart of any node will not affect the propagation of messages.
[0080] It should be understood that when each slave process updates the upstream configuration information of its auxiliary plugin based on the worker process cluster, it can update either based on the second upstream configuration information obtained from the auxiliary plugin of the master process, or based on the second upstream configuration information obtained from other slave processes. As long as the update time of other processes is newer than its own, the slave process will update.
[0081] Specifically, in the worker process cluster, the first upstream configuration information stored in the auxiliary plugins of each slave process includes the update time corresponding to the first upstream configuration information, at least one upstream configuration file, and the file identifier corresponding to the upstream configuration file. The second upstream configuration information updated by the auxiliary plugins of each slave process includes the update time corresponding to the second upstream configuration information, the updated upstream configuration file, and the file identifier corresponding to the updated upstream configuration file. When performing gossip protocol synchronization, the current slave process will compare the update time of the upstream configuration information in other slave processes or the master process. If the time difference of the update time is not within the preset time range, the hash value corresponding to the identifier of each upstream configuration file in the auxiliary plugin with the newer update time will be compared with the hash value corresponding to the identifier of each upstream configuration file with the older update time. For upstream configuration files with different hash values, the upstream configuration file corresponding to the auxiliary plugin with the newer update time will be synchronized to the one with the older update time, and the update time of the upstream configuration information with the older update time will be the current time.
[0082] In this embodiment of the application, according to the epidemic protocol, the updated second upstream configuration information of the auxiliary plugin of the main process is synchronized to the auxiliary plugins of all slave processes, which can ensure that the upstream configuration information of each process remains consistent.
[0083] Please also refer to Figure 3 and Figure 4In an optional embodiment, the first upstream configuration information includes the update time corresponding to the first upstream configuration information, at least one upstream configuration file, and a file identifier corresponding to the upstream configuration file; the second upstream configuration information includes the update time corresponding to the second upstream configuration information, the updated upstream configuration file, and a file identifier corresponding to the updated upstream configuration file; the step of synchronizing the second upstream configuration information to the local proxy server in step S103 includes:
[0084] Step S10321: Compare the update time of upstream configuration information in the dynamic load balancing module and auxiliary plug-in within the same working process.
[0085] In the embodiments of this application, both the dynamic load balancing module and the auxiliary plugin are configured with an updatetime field in their upstream configuration information to identify the update time of their respective upstream configuration information. By comparing the updatetime field values of the proxy server and the auxiliary plugin, it is determined whether the proxy server needs to be updated.
[0086] Step S10322: If the update time of the upstream configuration information in the dynamic load balancing module is less than the update time of the upstream configuration information in the auxiliary plugin, compare the hash value corresponding to each upstream configuration file identifier in the auxiliary plugin with the hash value corresponding to each upstream configuration file identifier in the dynamic load balancing module.
[0087] Understandably, if the update time of the upstream configuration information in the dynamic load balancing module is less than the update time of the upstream configuration information in the auxiliary plugin, it means that the upstream configuration information of the auxiliary plugin has been updated. In this case, the hash value corresponding to the upstream configuration file identifier can be used to further determine which file was updated, so only the corresponding file needs to be updated, without changing the entire upstream configuration information, thus improving update efficiency. If the update time of the upstream configuration information in the dynamic load balancing module is less than the update time of the upstream configuration information in the auxiliary plugin, it means that the upstream configuration information of the auxiliary plugin has not been updated, and the upstream configuration information in the dynamic load balancing module remains unchanged.
[0088] Step S10323: For upstream configuration files with different hash values, call the auxiliary plugin to synchronize the corresponding upstream configuration file in the auxiliary plugin to the dynamic load balancing module, and update the update time of the upstream configuration information in the dynamic load balancing module to the current time.
[0089] This application embodiment compares the update times of the upstream configuration information of the dynamic load balancing module and the auxiliary plugin to initially determine whether the upstream configuration information of the dynamic load balancing module and the auxiliary plugin is consistent. If they are inconsistent, the updated upstream configuration file is quickly determined by the hash value corresponding to the upstream configuration file identifier. Thus, only the updated upstream configuration file of the auxiliary plugin needs to be updated, which improves the data update matching efficiency and data update efficiency.
[0090] In an optional embodiment, step S10321, comparing the update times of upstream configuration information in the dynamic load balancing module and the auxiliary plugin, includes: comparing the update times of upstream configuration information in the dynamic load balancing module and the auxiliary plugin at preset time intervals. This embodiment of the application determines whether the auxiliary plugin has been updated by comparing the update times of upstream configuration information in the dynamic load balancing module and the auxiliary plugin at preset time intervals, thereby ensuring dynamic synchronization of the upstream configuration information of the dynamic load balancing module and the auxiliary plugin.
[0091] In an optional embodiment, the load balancing method further includes the following step: when the auxiliary plugin is invoked, the hash value is updated and saved to both the auxiliary plugin and the dynamic load balancing module based on the hash value corresponding to the file identifier of the updated upstream configuration file in the auxiliary plugin. This embodiment updates the hash value corresponding to the upstream configuration file identifier of both the auxiliary plugin and the dynamic load balancing module when the auxiliary plugin is invoked, thereby quickly determining the changed upstream configuration file in both the auxiliary plugin and the dynamic load balancing module, ensuring dynamic synchronization of the upstream configuration information between the dynamic load balancing module and the auxiliary plugin.
[0092] Please see Figure 5 This is a schematic diagram of the dynamic load balancing device provided in an embodiment of this application. The device 200 includes:
[0093] The configuration information acquisition module 201 is used to acquire the first upstream configuration information of the proxy server after the proxy server configuration is parsed, and save the first upstream configuration information to the dynamic load balancing module; the first upstream configuration information includes information on several servers that the proxy server reverse proxies.
[0094] The configuration information storage module 202 is used to configure auxiliary plugins for each working process when the dynamic load balancing module starts its working process, store the first upstream configuration information in the auxiliary plugins, and build a working process cluster based on the auxiliary plugins; wherein, each working process forwards the data processing requests sent by the client to the reverse proxy server based on the first upstream configuration information in its respective auxiliary plugin;
[0095] The configuration information update module 203 is used to receive upstream configuration information change requests, update the first upstream configuration information in the auxiliary plugin of the worker process based on the worker process cluster, obtain the second upstream configuration information, and synchronize the second upstream configuration information to the dynamic load balancing module.
[0096] It should be noted that the dynamic load balancing device provided in this application embodiment is only illustrated by the above-described division of functional modules when executing the dynamic load balancing method. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the dynamic load balancing device provided in this application embodiment and the dynamic load balancing method provided in this application embodiment belong to the same concept, and the implementation process is detailed in the method embodiment, which will not be repeated here.
[0097] The dynamic load balancing device embodiments provided in this application can be applied to electronic devices, such as proxy servers. These devices can be implemented in software, hardware, or a combination of both. Taking software implementation as an example, as a logical device, it is formed by a processor that handles file processing, reading the corresponding computer program instructions from non-volatile memory into memory for execution. From a hardware perspective, the electronic device may include a processor, network interface, memory, and non-volatile memory, interconnected via a data bus or other known methods.
[0098] Please see Figure 6 This is a schematic diagram of the structure of the electronic device provided in this application. Figure 6 As shown, the electronic device 16 may include: a processor 160, a memory 161, and a computer program 162 stored in the memory 161 and capable of running on the processor 160, such as a dynamic load balancing application; when the processor 160 executes the computer program 162, it implements the steps in the dynamic load balancing method of the above embodiments.
[0099] The processor 160 may include one or more processing cores. The processor 160 connects to various parts within the electronic device 16 using various interfaces and lines. It executes various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 161, and by calling data from the memory 161. Optionally, the processor 160 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 160 may integrate one or more of the following: a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), and a modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content required for the touchscreen display; and the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the processor 160.
[0100] The memory 161 may include random access memory (RAM) or read-only memory. Optionally, the memory 161 may include a non-transitory computer-readable storage medium. The memory 161 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 161 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch instructions), instructions for implementing the various method embodiments described above, etc.; the data storage area may store data involved in the various method embodiments described above, etc. Optionally, the memory 161 may also be at least one storage device located remotely from the aforementioned processor 160.
[0101] This application also provides a computer storage medium that can store multiple instructions. These instructions are applicable to being loaded by a processor and executed by the method steps of the above embodiments. For details of the execution process, please refer to the specific description of the above embodiments, which will not be repeated here.
[0102] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0103] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0104] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0105] In the embodiments provided by this invention, it should be understood that the disclosed apparatus / terminal devices and methods can be implemented in other ways. For example, the apparatus / terminal device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0106] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0107] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0108] If integrated modules / units are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms.
[0109] This invention is not limited to the above-described embodiments. If any modifications or variations to this invention do not depart from the spirit and scope of this invention, and if such modifications and variations fall within the scope of the claims and equivalent technologies of this invention, then this invention also intends to include such modifications and variations.
Claims
1. A dynamic load balancing method, characterized in that, Includes the following steps: After the proxy server configuration is parsed, the first upstream configuration information of the proxy server is obtained and saved to the dynamic load balancing module; the first upstream configuration information includes information on several servers that the proxy server reverse proxies. When the dynamic load balancing module starts its working process, it configures an auxiliary plugin for each working process, stores the first upstream configuration information in the auxiliary plugin, and builds a working process cluster based on the auxiliary plugin; wherein, each working process forwards the data processing request sent by the client to the reverse proxy server based on the first upstream configuration information in its respective auxiliary plugin; Upon receiving an upstream configuration information change request, based on the worker process cluster, update the first upstream configuration information in the auxiliary plugin of the worker process to obtain the second upstream configuration information, and synchronize the second upstream configuration information to the dynamic load balancing module.
2. The dynamic load balancing method according to claim 1, characterized in that: Following the step of building a worker process cluster based on the auxiliary plugin, the following steps are included: Based on the aforementioned auxiliary plugin, one of the working processes is determined as the main process according to a preset main process determination method, and the other working processes are slave processes. The step of receiving an upstream configuration information change request and updating the first upstream configuration information within the auxiliary plugin corresponding to each worker process based on the worker process cluster includes: Upon receiving a request to change upstream configuration information, the first upstream configuration information in the auxiliary plugin of the main process is updated to obtain the second upstream configuration information; based on the worker process cluster, the second upstream configuration information is synchronized to all slave processes.
3. The dynamic load balancing method according to claim 2, characterized in that: The step of determining one worker process as the master process and the other worker processes as slave processes based on the auxiliary plugin and a preset master process determination method includes: Each of the aforementioned working processes performs a file locking operation based on the auxiliary plugin, and the working process corresponding to the auxiliary plugin that successfully locks the file is determined as the master process, while the other working processes are determined as slave processes.
4. The dynamic load balancing method according to claim 3, characterized in that: After each of the aforementioned worker processes performs a file locking operation based on the auxiliary plugin, and determines the worker process corresponding to the auxiliary plugin that successfully locks the file as the master process and the other worker processes as slave processes, the following steps are included: If the master process is detected to have exited the worker process cluster or at least one worker process in the worker process cluster has a changed state, the system controls each worker process in the worker process cluster to re-execute the file lock operation based on the auxiliary plugin, and to re-determine the master process and slave processes.
5. The dynamic load balancing method according to claim 2, characterized in that: The step of synchronizing the second upstream configuration information to all slave processes based on the worker process cluster includes: Based on the aforementioned worker process cluster, and in accordance with the epidemic protocol, the second upstream configuration information is synchronized to all slave processes.
6. The dynamic load balancing method according to any one of claims 1 to 5, characterized in that: The first upstream configuration information includes the update time corresponding to the first upstream configuration information, at least one upstream configuration file, and the file identifier corresponding to the upstream configuration file; the second upstream configuration information includes the update time corresponding to the second upstream configuration information, the updated upstream configuration file, and the file identifier corresponding to the updated upstream configuration file. The step of synchronizing the second upstream configuration information to the dynamic load balancing module includes: Compare the update times of the upstream configuration information in the dynamic load balancing module and the auxiliary plugin within the same working process; If the update time of the upstream configuration information in the dynamic load balancing module is less than the update time of the upstream configuration information in the auxiliary plugin, the hash value corresponding to each upstream configuration file identifier in the auxiliary plugin is compared with the hash value corresponding to each upstream configuration file identifier in the dynamic load balancing module. For upstream configuration files with different hash values, the auxiliary plugin is invoked to synchronize the corresponding upstream configuration file within the auxiliary plugin to the dynamic load balancing module, thereby obtaining the second upstream configuration information and updating the update time of the upstream configuration information of the dynamic load balancing module to the current time.
7. The dynamic load balancing method according to claim 6, characterized in that: The step of comparing the update time of the upstream configuration information in the dynamic load balancing module and the auxiliary plugin within the same working process includes: The update times of the upstream configuration information in the dynamic load balancing module and the auxiliary plug-in are compared at preset time intervals within the same working process.
8. The dynamic load balancing method according to claim 7, characterized in that: The method further includes the following steps: When the auxiliary plugin is invoked, a corresponding hash value is generated based on the file identifier of the updated upstream configuration file in the auxiliary plugin, and the hash value is updated and saved to the auxiliary plugin and the dynamic load balancing module.
9. A dynamic load balancing device, characterized in that, include: The configuration information acquisition module is used to acquire the first upstream configuration information of the proxy server after the proxy server configuration is parsed, and save the first upstream configuration information to the dynamic load balancing module; the first upstream configuration information includes information on several servers that the proxy server reverse proxies. The configuration information storage module is used to configure an auxiliary plugin for each working process when the dynamic load balancing module starts its working process, store the first upstream configuration information in the auxiliary plugin, and build a working process cluster based on the auxiliary plugin; wherein, each working process forwards the data processing request sent by the client to the reverse proxy server based on the first upstream configuration information in its respective auxiliary plugin; The configuration information update module is used to receive upstream configuration information change requests, update the first upstream configuration information in the auxiliary plugin of the worker process based on the worker process cluster, obtain the second upstream configuration information, and synchronize the second upstream configuration information to the dynamic load balancing module.
10. An electronic device comprising a processor and a memory; characterized in that, The memory stores a computer program adapted to be loaded by the processor and executed as described in any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the dynamic load balancing method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Load balancing configuration method, device and system, equipment and storage medium
CN111277631A
Configuration updating method and device and electronic equipment
CN114785686A