Session keeping method and device in load balancing system, equipment and medium
By using ring hash space and shared memory cache technology in the load balancing system, the index value distribution is dynamically adjusted, which solves the session interruption problem caused by server changes, and achieves efficient and stable session retention.
Patent Information
- Application Number
- CN202510987265.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-17
- Publication Date
- 2025-08-15
AI Technical Summary
When the existing load balancing system is maintained, server changes are likely to cause session interruption.
By randomly distributing index values in the ring hash space, using the shared memory cache to record the mapping relationship between the five-tuple and the index value, dynamically adjusting the weight and index value distribution of the upstream server, ensuring that client requests are still routed to the original server when the server changes, and evenly distribute the requests to multiple healthy servers when the target server is abnormal.
It avoids session interrupts caused by server changes, improves system stability and processing capabilities, and ensures continuity and efficient forwarding of client requests.
Smart Images

Figure CN120499188A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of cloud computing, and in particular to a session maintenance method, apparatus, device and medium in a load balancing system. Background Art
[0002] In modern network architectures, load balancing technology is widely used to improve system availability and processing power. However, when it comes to applications that require maintaining user state, such as e-commerce websites or online banking systems, basic load balancing alone is insufficient. In this case, session persistence technology becomes particularly important. Session persistence ensures that consecutive requests from the same user are routed to the same server, maintaining user state information.
[0003] Current session persistence methods are typically database-based, which has the problem of a high probability of session interruption when the server changes. Summary of the Invention
[0004] In view of this, the present invention aims to provide a method, apparatus, device, and medium for maintaining sessions in a load balancing system, which can avoid the problem of excessive pressure on a single server by randomly distributing index values in a circular hash space. The specific solution is as follows:
[0005] In a first aspect, the present application provides a session maintenance method in a load balancing system, comprising:
[0006] Receiving a client request corresponding to a target session sent by a target client, parsing the client request to obtain a five-tuple corresponding to the client request, and querying whether cache data corresponding to the five-tuple exists in a preset shared memory cache;
[0007] If the cached data does not exist in the preset shared memory cache, obtaining a hash value corresponding to the client request based on a target hash algorithm and the five-tuple, and obtaining a first target index value from a preset ring hash space based on the hash value;
[0008] Determining a first target upstream server corresponding to the client request according to the first target index value; wherein the first target index value is data in a preset annular hash space, the preset annular hash space is located in a load balancing node of a preset load balancing system, the index values corresponding to upstream servers with different weights occupy different proportions in the preset annular hash space, and the index values corresponding to the upstream servers are randomly distributed in the preset annular hash space;
[0009] Determine whether there is an abnormality in the first target upstream server. If there is an abnormality in the first target upstream server, search for the second target index value in sequence based on the first target index value, and send the client request to the second target upstream server corresponding to the second target index value that does not have an abnormality, so as to maintain the target session.
[0010] Optionally, the session maintenance method in the load balancing system further includes:
[0011] Monitor the operating status of each upstream server in real time to identify normal servers and abnormal servers among them;
[0012] The abnormal server is removed from the target service range corresponding to the client request, and the operating status of the abnormal server is continuously monitored. If the abnormal status message of the abnormal server is abnormal, the abnormal server is re-included in the target service range.
[0013] Optionally, the session maintenance method in the load balancing system further includes:
[0014] If the cache data corresponding to the five-tuple exists in the preset shared memory cache, the first target index value corresponding to the client request is obtained from the cache data, and the process jumps to the step of determining the first target upstream server corresponding to the client request based on the first target index value.
[0015] Optionally, before obtaining the first target index value from the preset annular hash space based on the hash value, the method further includes:
[0016] Constructing the preset annular hash space, determining the server performance corresponding to each upstream server, and assigning a corresponding target weight to each upstream server according to the server performance;
[0017] A target number of index values corresponding to each of the upstream servers is set according to the target weight, and each index value is randomly mapped to an index position of the preset annular hash space based on the target number.
[0018] Optionally, the session maintenance method in the load balancing system further includes:
[0019] Receiving a historical client request sent by the target client, parsing the historical client request to obtain a historical five-tuple corresponding to the historical client request;
[0020] Obtaining a historical hash value corresponding to the historical client request using the target hash algorithm and the historical five-tuple, and storing the historical five-tuple and the historical hash value in the preset shared memory cache based on a preset storage duration;
[0021] Determine whether the storage time of the historical quintuple and the historical hash value in the preset shared memory cache is greater than the preset storage time; if the storage time of the historical quintuple and the historical hash value in the preset shared memory cache is greater than the preset storage time, delete the historical quintuple and the historical hash value.
[0022] Optionally, the session maintenance method in the load balancing system further includes:
[0023] If there is no abnormality in the first target upstream server corresponding to the first target index value, the client request is directly sent to the first target upstream server, and the first target upstream server is used to maintain the session of the client request.
[0024] In a second aspect, the present application provides a session persistence device in a load balancing system, comprising:
[0025] a data query module, configured to receive a client request corresponding to a target session sent by a target client, parse the client request to obtain a five-tuple corresponding to the client request, and query whether cached data corresponding to the five-tuple exists in a preset shared memory cache;
[0026] an index value acquisition module, configured to obtain, if the cached data does not exist in the preset shared memory cache, a hash value corresponding to the client request based on a target hash algorithm and the five-tuple, and obtain a first target index value from a preset ring hash space based on the hash value;
[0027] A server determination module, configured to determine a first target upstream server corresponding to the client request based on the first target index value; wherein the first target index value is data in a preset annular hash space, the preset annular hash space is located in a load balancing node of a preset load balancing system, the index values corresponding to upstream servers of different weights occupy different proportions in the preset annular hash space, and the index values corresponding to the upstream servers are randomly distributed in the preset annular hash space;
[0028] The first request sending module is used to determine whether there is an abnormality in the first target upstream server. If there is an abnormality in the first target upstream server, the second target index value is searched backward in sequence based on the first target index value, and the client request is sent to the second target upstream server corresponding to the second target index value that does not have an abnormality, so as to maintain the target session.
[0029] Optionally, the session maintaining device in the load balancing system further includes:
[0030] A step jump module is used to obtain the first target index value corresponding to the client request from the cache data if the cache data corresponding to the quintuple exists in the preset shared memory cache, and jump to the step of determining the first target upstream server corresponding to the client request based on the first target index value.
[0031] In a third aspect, the present application provides an electronic device, comprising:
[0032] Memory, used to store computer programs;
[0033] A processor is used to execute the computer program to implement the aforementioned session maintenance method in the load balancing system.
[0034] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the aforementioned session maintenance method in the load balancing system.
[0035] The present application first receives a client request corresponding to a target session sent by a target client, parses the client request to obtain a five-tuple corresponding to the client request, and queries a preset shared memory cache to determine whether cache data corresponding to the five-tuple exists. If the cache data does not exist in the preset shared memory cache, a hash value corresponding to the client request is obtained based on a target hash algorithm and the five-tuple, and a first target index value is obtained from a preset circular hash space based on the hash value. Then, a first target upstream server corresponding to the client request is determined based on the first target index value. The first target index value is data in the preset circular hash space, which is located in a load balancing node of a preset load balancing system. Index values corresponding to upstream servers with different weights occupy different proportions in the preset circular hash space, and index values corresponding to each upstream server are randomly distributed in the preset circular hash space. Finally, it is determined whether the first target upstream server has an abnormality. If the first target upstream server has an abnormality, a second target index value is sequentially searched backward based on the first target index value, and the client request is sent to a second target upstream server corresponding to the second target index value that does not have an abnormality, so as to maintain the target session. It can be seen that this application records the mapping relationship between the five-tuple and the index value through a shared memory cache. When the upstream server is dynamically added or deleted, the cache mechanism ensures that the continuous requests of the same client always read the historical index value, so that the vast majority of sessions are still routed to the original server when the server changes, avoiding the problem of session interruption due to server changes; by randomly distributing the index value in the circular hash space, when the target server is abnormal, the index value is traversed sequentially from the fault index position, so that the requests of the faulty server are evenly distributed to multiple healthy servers, avoiding the problem of migrating the sessions to the same server and causing excessive pressure on a single server. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0037] Figure 1 This is a flow chart of a session maintenance method in a load balancing system disclosed in this application;
[0038] Figure 2 A flow chart of a session maintenance method in a load balancing system disclosed in this application;
[0039] Figure 3This is a flow chart of an index value arrangement method disclosed in this application;
[0040] Figure 4 A structural diagram of a session maintaining device in a load balancing system disclosed in this application;
[0041] Figure 5 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0042] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0043] Current session persistence methods often have the problem of high probability of session interruption when the server changes. To this end, this application provides a session persistence method in a load balancing system, which avoids the problem of excessive pressure on a single server by randomly distributing index values in a circular hash space.
[0044] See also Figure 1 As shown, an embodiment of the present invention discloses a session maintenance method in a load balancing system, comprising:
[0045] Step S11: receiving a client request corresponding to a target session sent by a target client, parsing the client request to obtain a five-tuple corresponding to the client request, and querying whether cache data corresponding to the five-tuple exists in a preset shared memory cache.
[0046] The session persistence method in this embodiment is a method for implementing session persistence in a load balancing system, and needs to be used in conjunction with other load balancing related technologies, such as distributed load balancing technology, health check technology and other common technologies.
[0047] This embodiment achieves efficient and reliable service delivery by distributing client requests to multiple load balancing nodes, ensuring that the load on each node is maintained at a reasonable level. Compared with active-standby load balancing, the performance of distributed load balancing can be significantly improved, and the improvement factor is closely related to the number of load balancing nodes. Session persistence not only needs to be implemented on a single load balancing node, but must also be synchronized between nodes to ensure that requests from the same client can be correctly routed to the same upstream server when distributed to different load balancing nodes, avoiding session interruption problems caused by inconsistencies between nodes. The following will explain in detail how to implement an effective synchronization mechanism between load balancing nodes.
[0048] The main process of the session maintenance method in this embodiment is as follows: Figure 2 As shown in the figure, when a request (i.e., client request) arrives at a node, it is necessary to determine whether the request hits the cache (i.e., the preset shared memory cache), and obtain the hash value corresponding to the request based on the corresponding judgment result. The hash value is used to find the corresponding healthy server from the circular hash space, and the request is forwarded to the healthy server in order to maintain the target session corresponding to the client request.
[0049] The session maintenance method in this embodiment also includes: real-time monitoring of the operating status of each upstream server to determine the normal servers and abnormal servers among the upstream servers; moving the abnormal server out of the target service range corresponding to the client request, and continuously monitoring the operating status of the abnormal server. If the abnormal server sends an abnormal status message, the abnormal server is re-included in the target service range.
[0050] Specifically, health checking technology is a core component of the load balancing system. Its primary function is to monitor the health of upstream servers in real time, ensuring that only healthy upstream servers receive traffic. By implementing health checks, the load balancer can automatically identify and remove abnormal upstream servers. Once these servers return to normal operation, the load balancer promptly reinstates them into service. This process not only improves overall system availability but also enhances system stability. When an upstream server's health check result indicates an abnormality, the session persistence mechanism effectively loses its original purpose. Because the server is no longer able to process client requests, it must be immediately removed from the forwarding pool. In this case, session persistence technology must minimize the impact on client session persistence results during the dynamic addition and removal of upstream servers. Specifically, it must ensure that the majority of existing forwarding results remain stable, preventing session interruptions caused by server changes. This not only helps maintain a continuous user experience but also ensures efficient system operation.
[0051] Step S12: If the cache data does not exist in the preset shared memory cache, a hash value corresponding to the client request is obtained based on a target hash algorithm and the five-tuple, and a first target index value is obtained from a preset ring hash space based on the hash value.
[0052] The session maintenance method in this embodiment also includes: receiving a historical client request sent by the target client, parsing the historical client request to obtain a historical quintuple corresponding to the historical client request; using a target hash algorithm and the historical quintuple to obtain a historical hash value corresponding to the historical client request, and storing the historical quintuple and the historical hash value in a preset shared memory cache based on a preset storage duration; determining whether the storage duration of the historical quintuple and the historical hash value in the preset shared memory cache is greater than the preset storage duration; if the storage duration of the historical quintuple and the historical hash value in the preset shared memory cache is greater than the preset storage duration, deleting the historical quintuple and the historical hash value.
[0053] In this embodiment, if there is cache data corresponding to the five-tuple in the preset shared memory cache, the first target index value corresponding to the client request is obtained from the cache data, and the process jumps to the step of determining the first target upstream server corresponding to the client request based on the first target index value; if there is no hash value corresponding to the client request in the preset shared memory cache, it is necessary to use its corresponding five-tuple for calculation.
[0054] Specifically, a dedicated inter-process shared memory area (the pre-set shared memory cache) is allocated within the load balancing node to cache session persistence information. This information consists of the client request's five-tuple: source IP address (Internet Protocol Address), source port, destination IP address, destination port, protocol number, and details of the upstream server to which the request is forwarded. The data format is designed as "source IP:source port:destination IP:destination port:protocol number:upstream server:expiration time" to ensure information integrity and traceability. Furthermore, to maintain clean and efficient memory, an expiration cleanup mechanism must be introduced to promptly remove expired data.
[0055] Initially, when the first request arrives at a load balancing node, the session information in shared memory is empty. At this point, the node will intelligently calculate which upstream server to forward the request to based on pre-set rules.
[0056] The hash algorithm in this embodiment selects an algorithm with high discreteness and low collision rate, and an algorithm with fast calculation speed will make it more efficient. Therefore, the CRC32 (Cyclic Redundancy Check) algorithm is selected. The key for calculating the hash value is "source IP: source port: destination IP: destination port: protocol number". Assuming that the source IP of the client request data packet is 172.168.10.11, the source port is 52769, the destination IP is 172.168.10.8, the destination port is 8080, and the protocol is TCP (Transmission Control Protocol), then the key is "172.168.10.11:52769:172.168.10.8:8080:6". The code example is as follows:
[0057] public static long crc32(String key)
[0058] {
[0059] CRC32 crc32 = new CRC32();
[0060] byte[] data = key.getBytes();
[0061] crc32.update(data);
[0062] long result = crc32.getValue();
[0063] long index = result % 1024;
[0064] return index;
[0065] }
[0066] The CRC32 algorithm calculates the hash value of "172.168.10.11:52769:172.168.10.8:8080:6" to be 3907580823 (the hash value corresponding to the client request). The modulo 2 raised to the power of 10 equals 919. The packet is then forwarded to the upstream server at index 919 in the hash ring (the first target index) and the information "172.168.10.11:52769:172.168.10.8:8080:6:919:${expire time}" is written to the cache. After a period of this process, the cache within the load balancing node will contain some session persistence information. Subsequent client requests to the load balancing node will first determine whether to perform a hash calculation based on whether the request matches the cache. If so, the upstream server's index is used for a match and the cache expiration time is refreshed.
[0067] It should be noted that a session may have multiple consecutive client requests, and the five-tuples of the client requests corresponding to the same session are also the same. Therefore, if the client request corresponding to a session has previously reached the load balancing node, its corresponding five-tuple and hash value will be stored in the preset shared memory cache. When subsequent client requests corresponding to the same session arrive, there is no need to recalculate the hash value.
[0068] In this embodiment, before obtaining the first target index value from the preset circular hash space based on the hash value, it also includes: constructing a preset circular hash space, determining the server performance corresponding to each upstream server, and assigning corresponding target weights to each upstream server according to the performance of each server; setting the target number of index values corresponding to each upstream server according to the target weight, and randomly mapping each index value to the index position of the preset circular hash space based on the target number.
[0069] That is, this embodiment can adjust the number of corresponding index values in the preset ring hash space according to the weight of the upstream server.
[0070] By opening up shared memory in the load balancing node and caching the five-tuple corresponding to the client session in the shared memory, the client request corresponding to the same session does not need to recalculate the hash value when it subsequently enters the load balancing node, saving the system's computing resources and improving the efficiency of forwarding client requests.
[0071] Step S13: determine the first target upstream server corresponding to the client request based on the first target index value; wherein, the first target index value is data in a preset circular hash space, the preset circular hash space is located in a load balancing node of a preset load balancing system, and the index values corresponding to upstream servers of different weights occupy different proportions in the preset circular hash space, and the index values corresponding to each upstream server are randomly distributed in the preset circular hash space.
[0072] Since each index value corresponds to only one upstream server, the upstream server corresponding to the client request can be found through the above first target index value.
[0073] In addition, the index values corresponding to each upstream server in this embodiment are randomly distributed in the preset annular hash space. Each upstream server corresponds to at least 100 virtual nodes, which are randomly and evenly mapped to the annular space. For example, in the index interval [0-9], we randomly map 10 upstream servers (numbered 1-10) in a random order, such as 4, 2, 5, 8, 10, 1, 3, 7, 6, 9. Similarly, in the interval [10, 19], the mapping order is also random, such as 5, 4, 10, 1, 7, 9, 3, 2, 8, 6.
[0074] Step S14: Determine whether there is an abnormality in the first target upstream server. If there is an abnormality in the first target upstream server, search for the second target index value in sequence based on the first target index value, and send the client request to the second target upstream server corresponding to the second target index value that does not have an abnormality, so as to maintain the target session.
[0075] This embodiment has two scenarios. If the upstream server (i.e., the first target upstream server) is determined to be healthy by the health check, the client request is forwarded to the corresponding upstream server. If the upstream server is determined to be unhealthy by the health check, that is, the upstream server corresponding to index position 919 cannot respond to the request, the client continues to match backward, selecting the upstream server at index position 920, until an upstream server with a normal health check result is selected (i.e., the second target upstream server). Due to the end-to-end nature of the hash ring, if the health check result of the upstream server with index 1023 is abnormal, the client continues to match backward from index position 0 until an upstream server with a normal health check result is selected.
[0076] That is, in this embodiment, if there is no abnormality in the first target upstream server, the client request is directly sent to the first target upstream server, and the first target upstream server is used to maintain the session of the client request.
[0077] It should be noted that when the health check result of an upstream server is abnormal, only the adjacent upstream servers on the hash ring are affected. Because the segments on the hash ring are randomly distributed, the nodes behind the upstream server are random. This can avoid the situation where one upstream server fails and all requests originally handled by upstream server 1 are forwarded to upstream server 2. By randomly assigning index values in the ring hash space, when upstream servers are dynamically added or deleted, it can ensure that most of the original forwarding results remain stable, avoiding session interruptions caused by server changes. Moreover, if an upstream server fails, the requests of the upstream server can be evenly distributed to other upstream servers, making the request distribution more reasonable. By using caching technology to reduce the amount of calculation, the CPU pressure is alleviated.
[0078] It can be seen that this application records the mapping relationship between the five-tuple and the index value through a shared memory cache. When the upstream server is dynamically added or deleted, the cache mechanism ensures that the continuous requests of the same client always read the historical index value, so that the vast majority of sessions are still routed to the original server when the server changes, avoiding the problem of session interruption due to server changes; by randomly distributing the index value in the circular hash space, when the target server is abnormal, the index value is traversed sequentially from the fault index position, so that the requests of the faulty server are evenly distributed to multiple healthy servers, avoiding the problem of migrating the sessions to the same server and causing excessive pressure on a single server.
[0079] Based on the above embodiments, this application describes the overall process of session maintenance in a load balancing system. To make the technical solution in this application more complete, this application will now elaborate on how to arrange the index value of the upstream server in the ring hash space. Figure 3 As shown, an embodiment of the present invention discloses a process for arranging index values, including:
[0080] Step S21: construct a ring hash space, determine the server performance corresponding to each upstream server, and assign a corresponding target weight to each upstream server according to the server performance.
[0081] In this example, we assume that the number of upstream servers is fixed at 10 and will not increase. To achieve efficient and even load distribution, a ring-shaped hash space construction method is adopted. Hash space and virtual node mapping: The hash space is constructed as a ring, with values ranging from 0 to 2 to the power of 10 minus 1.
[0082] In real-world applications, performance often varies between upstream servers. For example, upstream server 1 might be a VM with 4 cores and 8GB of RAM, while upstream server 2 might be a VM with a higher configuration of 8 cores and 16GB of RAM. To address this performance discrepancy, a weighted allocation mechanism is introduced. Specifically, a weight of 1 can be set for upstream server 1, while a weight of 2 can be set for upstream server 2. This way, different upstream servers can be subsequently allocated a corresponding number of virtual nodes based on their weights.
[0083] Step S22: setting a target number of index values corresponding to each upstream server according to the target weight, and randomly mapping each index value to an index position of the preset ring hash space based on the target number.
[0084] In this example, assume that there are still 10 upstream servers in the system, but the first upstream server has a weight of 2 due to its higher performance, while the remaining 9 upstream servers all have a weight of 1. In this case, when mapping on the hash ring, the number of segments needs to be adjusted to reflect this weight difference. Specifically, the number of segments should be changed from 10 to 11.
[0085] Taking the interval [0,10] as an example, the possible mapping indices are 5, 4, 3, 2, 1, 6, 7, 8, 9, 10, and 1. Here, upstream server 1, with a weight of 2, is mapped twice on the hash ring, while the other nine upstream servers are each mapped once. In this way, this embodiment can adjust the mapping ratio based on the number of virtual nodes, thereby finely controlling the number of requests allocated to each upstream server.
[0086] This weighted virtual node mapping strategy makes request distribution more reasonable and balanced. It not only takes into account the performance differences of upstream servers, but also dynamically adjusts the mapping ratio to ensure that high-performance servers can handle more requests, thereby improving the overall system processing capacity and efficiency.
[0087] Furthermore, to ensure consistent results across multiple load balancing nodes, we ensure the mapping order is identical across all nodes. This ensures that even if requests from the same client are forwarded to different load balancing nodes, or if a load balancing node fails, they are still forwarded to the same upstream server, avoiding inconsistent forwarding due to different nodes.
[0088] By randomly mapping and introducing virtual nodes within the segmented interval, we not only address the uneven distribution of upstream servers, but also make the distribution more random and uniform. This design effectively improves the efficiency and accuracy of load balancing, providing clients with a more stable and fast service experience.
[0089] See also Figure 4 As shown, an embodiment of the present invention discloses a session maintaining device in a load balancing system, comprising:
[0090] The data query module 11 is configured to receive a client request corresponding to a target session sent by a target client, parse the client request to obtain a five-tuple corresponding to the client request, and query whether cached data corresponding to the five-tuple exists in a preset shared memory cache;
[0091] An index value acquisition module 12 is configured to obtain a hash value corresponding to the client request based on a target hash algorithm and the five-tuple if the cached data does not exist in the preset shared memory cache, and obtain a first target index value from a preset ring hash space based on the hash value;
[0092] A server determination module 13 is configured to determine a first target upstream server corresponding to the client request based on the first target index value; wherein the first target index value is data in a preset annular hash space, the preset annular hash space is located in a load balancing node of a preset load balancing system, the index values corresponding to upstream servers of different weights occupy different proportions in the preset annular hash space, and the index values corresponding to the upstream servers are randomly distributed in the preset annular hash space;
[0093] The first request sending module 14 is used to determine whether there is an abnormality in the first target upstream server. If there is an abnormality in the first target upstream server, the second target index value is searched backward in sequence based on the first target index value, and the client request is sent to the second target upstream server corresponding to the second target index value and without an abnormality, so as to maintain the target session.
[0094] It can be seen that this application records the mapping relationship between the five-tuple and the index value through a shared memory cache. When the upstream server is dynamically added or deleted, the cache mechanism ensures that the continuous requests of the same client always read the historical index value, so that the vast majority of sessions are still routed to the original server when the server changes, avoiding the problem of session interruption due to server changes; by randomly distributing the index value in the circular hash space, when the target server is abnormal, the index value is traversed sequentially from the fault index position, so that the requests of the faulty server are evenly distributed to multiple healthy servers, avoiding the problem of migrating the sessions to the same server and causing excessive pressure on a single server.
[0095] In some specific embodiments, the session maintaining device in the load balancing system further includes:
[0096] The server monitoring module is used to monitor the operating status of each upstream server in real time to determine the normal servers and abnormal servers among the upstream servers;
[0097] The server control module is used to move the abnormal server out of the target service range corresponding to the client request and monitor the operating status of the abnormal server. If the abnormal status message of the abnormal server is abnormal, the abnormal server will be re-included in the target service range.
[0098] In some specific embodiments, the session maintaining device in the load balancing system further includes:
[0099] A step jump module is used to obtain the first target index value corresponding to the client request from the cache data if the cache data corresponding to the quintuple exists in the preset shared memory cache, and jump to the step of determining the first target upstream server corresponding to the client request based on the first target index value.
[0100] In some specific embodiments, the index value acquisition module 12 further includes:
[0101] a weight assigning unit, configured to construct the preset annular hash space, determine the server performance corresponding to each upstream server, and assign a corresponding target weight to each upstream server according to the server performance;
[0102] An index value mapping unit is used to set a target number of index values corresponding to each upstream server according to the target weight, and randomly map each index value to an index position of the preset ring hash space based on the target number.
[0103] In some specific embodiments, the session maintaining device in the load balancing system further includes:
[0104] A request parsing module, configured to receive a historical client request sent by the target client, and parse the historical client request to obtain a historical five-tuple corresponding to the historical client request;
[0105] A hash value acquisition module, configured to acquire a historical hash value corresponding to the historical client request using the target hash algorithm and the historical five-tuple, and store the historical five-tuple and the historical hash value in the preset shared memory cache based on a preset storage duration;
[0106] A data deletion module is used to determine whether the storage time of the historical quintuple and the historical hash value in the preset shared memory cache is greater than the preset storage time; if the storage time of the historical quintuple and the historical hash value in the preset shared memory cache is greater than the preset storage time, the historical quintuple and the historical hash value are deleted.
[0107] In some specific embodiments, the session maintaining device in the load balancing system further includes:
[0108] The second request sending module is used to directly send the client request to the first target upstream server if there is no abnormality in the first target upstream server corresponding to the first target index value, and use the first target upstream server to maintain the session of the client request.
[0109] Furthermore, the embodiment of the present application also discloses an electronic device, Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram should not be considered as any limitation to the scope of application of the present application.
[0110] Figure 5 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps of the session persistence method in the load balancing system disclosed in any of the aforementioned embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0111] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0112] In addition, the memory 22 as a carrier for resource storage can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon may include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0113] The operating system 221 is used to manage and control the hardware devices on the electronic device 20 and the computer program 222, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program capable of implementing the session persistence method in the load balancing system executed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 may further include a computer program capable of implementing other specific tasks.
[0114] Furthermore, this application also discloses a computer-readable storage medium for storing a computer program; wherein, when executed by a processor, the computer program implements the aforementioned disclosed method for session persistence in a load balancing system. The specific steps of this method can be referred to the corresponding contents disclosed in the aforementioned embodiments and will not be repeated here.
[0115] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.
[0116] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0117] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0118] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0119] The above is a detailed introduction to the technical solution provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the ideas of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A session maintenance method in a load balancing system, characterized in that: include: Receiving a client request corresponding to a target session sent by a target client, parsing the client request to obtain a five-tuple corresponding to the client request, and querying whether cache data corresponding to the five-tuple exists in a preset shared memory cache; If the cached data does not exist in the preset shared memory cache, obtaining a hash value corresponding to the client request based on a target hash algorithm and the five-tuple, and obtaining a first target index value from a preset ring hash space based on the hash value; Determining a first target upstream server corresponding to the client request according to the first target index value; wherein the first target index value is data in a preset annular hash space, the preset annular hash space is located in a load balancing node of a preset load balancing system, the index values corresponding to upstream servers with different weights occupy different proportions in the preset annular hash space, and the index values corresponding to the upstream servers are randomly distributed in the preset annular hash space; Determine whether there is an abnormality in the first target upstream server. If there is an abnormality in the first target upstream server, search for the second target index value in sequence based on the first target index value, and send the client request to the second target upstream server corresponding to the second target index value that does not have an abnormality, so as to maintain the target session.
2. The session maintenance method in a load balancing system according to claim 1, characterized in that: Also includes: Monitor the operating status of each upstream server in real time to identify normal servers and abnormal servers among them; The abnormal server is removed from the target service range corresponding to the client request, and the operating status of the abnormal server is continuously monitored. If the abnormal status message of the abnormal server is abnormal, the abnormal server is re-included in the target service range.
3. The session maintenance method in a load balancing system according to claim 1, characterized in that: Also includes: If the cache data corresponding to the five-tuple exists in the preset shared memory cache, the first target index value corresponding to the client request is obtained from the cache data, and the process jumps to the step of determining the first target upstream server corresponding to the client request based on the first target index value.
4. The session maintenance method in a load balancing system according to claim 1, characterized in that: Before obtaining the first target index value from the preset annular hash space based on the hash value, the method further includes: Constructing the preset annular hash space, determining the server performance corresponding to each upstream server, and assigning a corresponding target weight to each upstream server according to the server performance; A target number of index values corresponding to each of the upstream servers is set according to the target weight, and each index value is randomly mapped to an index position of the preset annular hash space based on the target number.
5. The session maintaining method in a load balancing system according to claim 1, wherein: Also includes: Receiving a historical client request sent by the target client, parsing the historical client request to obtain a historical five-tuple corresponding to the historical client request; Obtaining a historical hash value corresponding to the historical client request using the target hash algorithm and the historical five-tuple, and storing the historical five-tuple and the historical hash value in the preset shared memory cache based on a preset storage duration; Determine whether the storage time of the historical quintuple and the historical hash value in the preset shared memory cache is greater than the preset storage time; if the storage time of the historical quintuple and the historical hash value in the preset shared memory cache is greater than the preset storage time, delete the historical quintuple and the historical hash value.
6. The session maintaining method in a load balancing system according to any one of claims 1 to 5, characterized in that: Also includes: If there is no abnormality in the first target upstream server corresponding to the first target index value, the client request is directly sent to the first target upstream server, and the first target upstream server is used to maintain the session of the client request.
7. A session maintaining device in a load balancing system, characterized in that: include: a data query module, configured to receive a client request corresponding to a target session sent by a target client, parse the client request to obtain a five-tuple corresponding to the client request, and query whether cached data corresponding to the five-tuple exists in a preset shared memory cache; an index value acquisition module, configured to obtain, if the cached data does not exist in the preset shared memory cache, a hash value corresponding to the client request based on a target hash algorithm and the five-tuple, and obtain a first target index value from a preset ring hash space based on the hash value; A server determination module, configured to determine a first target upstream server corresponding to the client request based on the first target index value; wherein the first target index value is data in a preset annular hash space, the preset annular hash space is located in a load balancing node of a preset load balancing system, the index values corresponding to upstream servers of different weights occupy different proportions in the preset annular hash space, and the index values corresponding to the upstream servers are randomly distributed in the preset annular hash space; The first request sending module is used to determine whether there is an abnormality in the first target upstream server. If there is an abnormality in the first target upstream server, the second target index value is searched backward in sequence based on the first target index value, and the client request is sent to the second target upstream server corresponding to the second target index value that does not have an abnormality, so as to maintain the target session.
8. The session maintaining device in the load balancing system according to claim 7, characterized in that: Also includes: A step jump module is used to obtain the first target index value corresponding to the client request from the cache data if the cache data corresponding to the quintuple exists in the preset shared memory cache, and jump to the step of determining the first target upstream server corresponding to the client request based on the first target index value.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the session maintenance method in the load balancing system according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that Used to store a computer program, which, when executed by a processor, implements the session maintenance method in a load balancing system according to any one of claims 1 to 6.