Method, device and electronic equipment for processing long connections

By grouping and managing the load of servers, the problem of wasted long-connection resources in distributed microservice architecture is solved, and reasonable resource allocation and load balancing are achieved.

CN116192925BActive Publication Date: 2026-03-17INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-02
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

In a distributed microservice architecture, when clients and servers communicate via long-lived connections, a large number of these long-lived connections remain idle, leading to a waste of cluster resources.

Method used

Multiple servers are grouped using a preset hash algorithm to generate a shard list. Multiple long-lived connections between the client and the target server are established through the shard list. Combined with hash ring and virtual server management, the shard load is dynamically adjusted to optimize resource allocation.

Benefits of technology

It enables flexible management of long-lived connections, rational allocation of cluster resources, reduces resource waste, and achieves load balancing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116192925B_ABST
    Figure CN116192925B_ABST
Patent Text Reader

Abstract

The application discloses a long connection processing method and device and electronic equipment. The method is applied to the field of financial technology or other fields. The method comprises the following steps: determining a plurality of service ends; adopting a preset hash algorithm to group the plurality of service ends to obtain a fragmentation list; and establishing a plurality of long connections between at least one target service end and a client through the fragmentation list. Through the application, the problem that a large number of long connections are in an idle state when the client and the service end communicate data through the long connection in different time periods in the related art is solved, and a large number of cluster resources are wasted.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of financial technology or other fields, and more specifically, to a method, apparatus and electronic device for processing long connections. Background Technology

[0002] Currently, the mainstream architecture for providing services to customers is gradually shifting from centralized architecture to distributed microservice architecture. This means that customers issue service requests remotely from their client-side devices, and the enterprise responds to these requests across multiple servers, providing the corresponding services to the customer. Simultaneously, the client has the ability to automatically discover servers, meaning it can establish long-lived connections with other servers and communicate with them without needing to know their IP addresses.

[0003] In existing distributed microservice architectures, by default, clients need to establish at least one long-lived connection with each of the multiple servers. As the cluster of multiple servers grows larger, clients need to establish a massive number of long-lived connections with a huge number of other clients for data communication between clients and servers. However, because the frequency of client service requests varies between peak and off-peak periods, a large number of long-lived connections remain idle during off-peak periods, and maintaining a large number of long-lived connections consumes significant cluster resources.

[0004] There is currently no effective solution to the problem that when clients and servers communicate through long-lived connections at different times, a large number of long-lived connections become idle, resulting in a waste of a lot of cluster resources. Summary of the Invention

[0005] The main objective of this application is to provide a method, apparatus, and electronic device for processing long connections, in order to solve the problem in the related art where a large number of long connections are idle when the client and server communicate data through long connections at different time periods, resulting in a waste of a large number of cluster resources.

[0006] To achieve the above objectives, according to one aspect of this application, a method for processing long-lived connections is provided. The method includes: determining a plurality of servers, wherein the plurality of servers are servers that have connection relationships with a client; grouping the plurality of servers using a preset hash algorithm to obtain a shard list, wherein the shard list includes multiple shards, each shard corresponding to at least one server, and wherein the shard list includes information about at least one target server with which the client is to conduct data communication; and establishing multiple long-lived connections between the at least one target server and the client through the shard list, wherein the client conducts data communication with the at least one target server through the multiple long-lived connections.

[0007] Furthermore, the multiple servers are grouped using a preset hash algorithm to obtain a shard list, which includes: mapping the multiple servers to a hash ring using the preset hash algorithm to obtain a mapped hash ring, wherein the partitions in the mapped hash ring correspond one-to-one with the shards in the multiple shards; determining the information of at least one target server from the multiple servers based on the client's request service information; and obtaining the shard list based on the information of the at least one target server and the multiple shards.

[0008] Furthermore, before mapping the plurality of servers to the hash ring using the preset hash algorithm to obtain the mapped hash ring, the method further includes: if the number of the plurality of servers is less than the number of shards of the hash ring, then creating virtual servers, wherein the sum of the number of virtual servers and the number of the plurality of servers is not less than the number of shards of the hash ring; mapping the plurality of servers to the hash ring using the preset hash algorithm to obtain the mapped hash ring includes: mapping the plurality of servers and the created virtual servers to the hash ring using the preset hash algorithm to obtain the mapped hash ring.

[0009] Furthermore, after establishing multiple long connections between the at least one target server and the client through the shard list, the method further includes: processing the multiple shards according to their operating load to obtain adjusted multiple shards; and continuing to maintain the multiple long connections according to the adjusted multiple shards to adjust the cluster resources occupied by the multiple long connections.

[0010] Further, based on the operating load of the multiple shards, the multiple shards are processed to obtain adjusted multiple shards, including: if there is a first shard with an operating load greater than a first preset value, then it is determined whether the current number of shards is less than the maximum number of shards; if the current number of shards is less than the maximum number of shards, then a second value is calculated based on the load of the current shard, wherein the second value represents the number of shards; the first shard is split into shards of the second value to obtain the adjusted multiple shards.

[0011] Further, based on the operating load of the multiple shards, the multiple shards are processed to obtain adjusted multiple shards, including: if there is a second shard with an operating load less than a second preset value, then it is determined whether the number of current shards is greater than the minimum number of shards; if the number of current shards is greater than the minimum number of shards, then the operating load of the second shard and the adjacent shards is calculated to obtain the target load; if the target load is less than the first preset value, then the second shard and the adjacent shards are merged to obtain the adjusted multiple shards.

[0012] Furthermore, before processing the multiple shards based on their operating load to obtain the adjusted multiple shards, the method further includes: determining an optimal sharding strategy based on the overall operating load of the multiple shards; and splitting or merging the multiple shards according to the optimal sharding strategy to obtain the adjusted multiple shards.

[0013] Furthermore, maintaining the multiple long connections based on the adjusted multiple shards, and adjusting the cluster resources occupied by the multiple long connections, includes: re-determining at least one target server to be used for data communication at preset intervals; adjusting the shard list based on the at least one target server to obtain an updated shard list; and adjusting the long connections in the multiple shards through the updated shard list so that the client can communicate with the at least one target server.

[0014] To achieve the above objectives, according to another aspect of this application, a long-connection processing apparatus is provided. The apparatus includes: a first determining unit, configured to determine a plurality of servers, wherein the plurality of servers are servers that have a connection relationship with a client; a grouping unit, configured to group the plurality of servers using a preset hash algorithm to obtain a sharding list, wherein the sharding list includes a plurality of shards, each shard corresponding to at least one server, and wherein the sharding list includes information about at least one target server with which the client is to conduct data communication; and a connecting unit, configured to establish multiple long connections between the at least one target server and the client through the sharding list, wherein the client conducts data communication with the at least one target server through the multiple long connections.

[0015] Further, the grouping unit includes: a first calculation subunit, used to map the plurality of servers to a hash ring using the preset hash algorithm to obtain a mapped hash ring, wherein the partitions in the mapped hash ring correspond one-to-one with the shards in the plurality of shards; a first determination subunit, used to determine the information of at least one target server from the plurality of servers based on the client's request service information; and an acquisition subunit, used to obtain the shard list based on the information of the at least one target server and the plurality of shards.

[0016] Furthermore, the grouping unit further includes: a creation subunit, used to create virtual servers if the number of the multiple servers is less than the number of shards of the hash ring before mapping the multiple servers to the hash ring using the preset hash algorithm to obtain the mapped hash ring, wherein the sum of the number of virtual servers and the number of the multiple servers is not less than the number of shards of the hash ring; the first calculation subunit further includes: a first calculation module, used to map the multiple servers and the created virtual servers to the hash ring using the preset hash algorithm to obtain the mapped hash ring.

[0017] Furthermore, the apparatus includes: a first processing unit, configured to, after establishing multiple long connections between the at least one target server and the client through the sharding list, process the multiple shards according to their operating load to obtain adjusted multiple shards; and a maintenance unit, configured to continue maintaining the multiple long connections according to the adjusted multiple shards to adjust the cluster resources occupied by the multiple long connections.

[0018] Further, the first processing unit includes: a first judgment subunit, configured to determine whether the number of current shards is less than the maximum number of shards if there is a first shard with a running load greater than a first preset value; a second calculation subunit, configured to calculate a second value based on the load of the current shard if the number of current shards is less than the maximum number of shards, wherein the second value represents the number of shards; and a first processing subunit, configured to split the first shard into shards of the second value to obtain the adjusted multiple shards.

[0019] Further, the first processing unit includes: a second judgment subunit, configured to determine whether the number of current shards is greater than the minimum number of shards if there is a second shard with a running load less than a second preset value; a third calculation subunit, configured to calculate the running load of the second shard and its adjacent shards after merging if the number of current shards is greater than the minimum number of shards, to obtain a target load; and a second processing subunit, configured to merge the second shard and its adjacent shards if the target load is less than the first preset value, to obtain the adjusted multiple shards.

[0020] Furthermore, the apparatus further includes: a second determining unit, configured to determine an optimal sharding strategy based on the overall operating load of the multiple shards before processing the multiple shards according to their operating load to obtain adjusted multiple shards; and a second processing unit, configured to split or merge the multiple shards according to the optimal sharding strategy to obtain the adjusted multiple shards.

[0021] Furthermore, the maintenance unit includes: a second determining subunit, configured to re-determine at least one target server to be used for data communication at preset intervals; a third processing subunit, configured to adjust the shard list according to the at least one target server to obtain an updated shard list; and a fourth processing subunit, configured to adjust the long connections in the plurality of shards through the updated shard list so that the client can perform data communication with the at least one target server.

[0022] To achieve the above objectives, according to one aspect of this application, an electronic device is provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the long connection processing method described in any of the above.

[0023] This application employs the following steps: identifying multiple servers, wherein the multiple servers are those that have connections with the client; grouping the multiple servers using a preset hash algorithm to obtain a shard list, wherein the shard list includes multiple shards, each shard corresponding to at least one server, and wherein the shard list includes information about at least one target server with which the client will conduct data communication; establishing multiple long connections between the at least one target server and the client using the shard list, wherein the client conducts data communication with the at least one target server through the multiple long connections. This solves the problem in related technologies where, when the client and server conduct data communication through long connections at different time periods, a large number of long connections are idle, resulting in a significant waste of cluster resources. By grouping multiple servers and identifying the servers to be connected within multiple shards, enabling the client to conduct data communication with the servers to be connected, the effect of flexibly managing multiple long connections through sharding is achieved, resulting in the rational allocation of cluster resources and further achieving load balancing among multiple shards. Attached Figure Description

[0024] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0025] Figure 1 This is a flowchart of a long connection processing method provided in Embodiment 1 of this application;

[0026] Figure 2 This is a schematic diagram of an optional long-connection processing method provided in Embodiment 1 of this application. Figure 1 ;

[0027] Figure 3 This is a schematic diagram of an optional long-connection processing method provided in Embodiment 1 of this application. Figure 2 ;

[0028] Figure 4 This is a schematic diagram of a long-connection processing device according to Embodiment 2 of this application;

[0029] Figure 5 This is a schematic diagram of a long-connection processing electronic device provided according to Embodiment 5 of this application. Detailed Implementation

[0030] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0031] It should be noted that the processing method, apparatus, processor, and electronic device specified in this disclosure can be used in the financial technology field to improve the utilization of cluster resources when conducting data communication through long connections, and can also be used in any field other than the financial technology field. The application field of the processing method, apparatus, processor, and electronic device of this disclosure is not limited.

[0032] It should be noted that the user information (including but not limited to user device information, user personal information, user requested data, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, requested data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0033] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0034] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0035] Example 1

[0036] The present invention will now be described in conjunction with preferred implementation steps. Figure 1 This is a flowchart of a long-connection processing method provided in Embodiment 1 of this application, as follows: Figure 1 As shown, the method includes the following steps:

[0037] Step S101: Identify multiple servers, wherein the multiple servers are servers that have a connection relationship with the client.

[0038] In this first embodiment, the client is the service consumer, and correspondingly, the server is the service provider, offering services to the client. In existing distributed microservice architectures, the server provides services to the client through a long-lived connection, and the client typically has the ability to automatically discover the server's address.

[0039] Step S102: Using a preset hash algorithm, multiple servers are grouped to obtain a shard list. The shard list includes multiple shards, each shard corresponding to at least one server. The shard list also includes information about at least one target server with which the client will communicate data.

[0040] In existing technologies, when a server provides services to a client, the client is required by default to establish a persistent connection with each server in the cluster, and the server provides services to the client through these persistent connections. However, the frequency of service requests from clients varies, with peak and off-peak periods. If the client and server are constantly maintaining persistent connections, idle persistent connections will consume a large amount of cluster resources during off-peak periods, resulting in a waste of cluster resources.

[0041] To better utilize cluster resources, in this first embodiment, multiple servers are grouped to obtain a shard list, and then multiple servers are processed according to the shard list, thus saving cluster resources. Each shard contains a group of servers, and the shard list records information about the servers that actually need to establish connections with the client.

[0042] For example, in a cluster with one client and ten servers, the traditional approach would establish ten long-lived connections between the client and the ten servers. However, in this embodiment, the ten servers are divided into three groups, with each shard containing one group of servers. Then, based on the actual requests from the client, the number of servers to be connected is determined to be five. Finally, the five servers to be connected are selected from the three shards, and their shard information is stored in a shard list.

[0043] Step S103: Establish multiple long connections between at least one target server and the client using the sharding list, wherein the client communicates with at least one target server through the multiple long connections.

[0044] After grouping multiple servers into shard lists, a long-lived connection is established between the client and the server to be connected through the server in the shard list, so that the server can provide the corresponding service to the client.

[0045] In summary, the long-connection processing method provided in Embodiment 1 of this application identifies multiple servers, which are servers that have connections with the client; uses a preset hash algorithm to group the multiple servers to obtain a shard list, where each shard corresponds to at least one server, and includes information about at least one target server with which the client will communicate; and establishes multiple long connections between at least one target server and the client through the shard list. The client then communicates with at least one target server through these multiple long connections. This solves the problem in related technologies where a large number of long connections are idle when the client and server communicate through them at different times, resulting in a significant waste of cluster resources. By grouping multiple servers and identifying the servers to be connected within multiple shards, the method enables the client to communicate with the servers to be connected, achieving flexible management of multiple long connections through sharding, rational allocation of cluster resources, and load balancing among multiple shards.

[0046] Optionally, in the long connection processing method provided in Embodiment 1 of this application, the method of grouping multiple servers into a shard list using a preset hash algorithm includes: mapping multiple servers into a hash ring using the preset hash algorithm to obtain a mapped hash ring, wherein the partitions in the mapped hash ring correspond one-to-one with the shards in the multiple shards; determining the information of at least one target server from the multiple servers based on the client's request service information; and obtaining a shard list based on the information of at least one target server and the multiple shards.

[0047] For example, Figure 2 This is a diagram illustrating the process of grouping multiple servers, such as... Figure 2 As shown, there are 2 clients in the cluster (e.g. Figure 2 Client 1 and Client 2) and 7 servers (such as Figure 2 The seven servers (servers 1, 2, 3, 4, 5, 6, and 7) are first distributed across six partitions of a consistent hash ring using a non-encrypted hash function. Each partition of the hash ring corresponds to a shard: shard 1 contains {server 1}, shard 2 contains {server 2}, shard 3 contains {server 3}, shard 4 contains {server 4}, shard 5 contains {server 5}, and shard 6 contains {server 6 and server 7}. It should be noted that the non-encrypted hash function in this embodiment can be replaced with other hash algorithms depending on the actual situation. Furthermore, this embodiment uses a consistent hash ring to ensure that when data changes across multiple partitions in the hash ring, only a small amount of data migration is required. Then, based on the actual service requests from clients 1 and 2 at the current time, it is determined that client 1 requires services from {servers 1, 3, and 5}, and client 2 requires services from {servers 2, 4, and 6}. Server 7 does not require service. Finally, the connection information of server 1, server 2, server 3, server 4, server 5, server 6 and server 7, along with the sharding information of each server, are written into the sharding list to obtain the sharding list.

[0048] By grouping multiple servers, the servers to be connected are determined based on the actual request situation. This avoids the waste of a large number of cluster resources caused by maintaining idle connections. Furthermore, writing the relevant information of the servers to be connected into the sharding list is beneficial for the unified management and allocation of resources for long connections established between clients and servers in the future, thereby achieving the effect of rationally utilizing and allocating cluster resources and reducing the waste of cluster resources.

[0049] Optionally, in the long connection processing method provided in Embodiment 1 of this application, before mapping multiple servers to a hash ring using a preset hash algorithm to obtain the mapped hash ring, the method further includes: if the number of multiple servers is less than the number of shards of the hash ring, then creating virtual servers, wherein the sum of the number of virtual servers and the number of multiple servers is not less than the number of shards of the hash ring; mapping multiple servers to a hash ring using a preset hash algorithm to obtain the mapped hash ring includes: mapping multiple servers and the created virtual servers to a hash ring using a preset hash algorithm to obtain the mapped hash ring.

[0050] For example, if there are only 3 servers in the cluster, mapping these 3 servers to the 6 partitions of the hash ring will result in data skew, meaning that a large amount of data computation is concentrated in some partitions or servers. Therefore, in this first embodiment, it is necessary to create 3 virtual servers and use a preset hash function to map the 3 servers and 3 virtual servers to the 6 partitions of the hash ring, resulting in the mapped hash ring.

[0051] By creating virtual servers when the number of servers is small, and mapping the original servers and virtual servers to the hash ring, data skew is avoided, thus achieving the effect of balancing cluster resources and reducing cluster resource waste.

[0052] Optionally, in the long connection processing method provided in Embodiment 1 of this application, after establishing at least one target server and multiple long connections with the client through the sharding list, the method further includes: processing the multiple shards according to their operating load to obtain adjusted multiple shards; and continuing to maintain multiple long connections according to the adjusted multiple shards to adjust the cluster resources occupied by the multiple long connections.

[0053] For example, a cluster may have three shards providing services to clients: Shard 1 includes {Server 1, Server 2}, Shard 2 includes {Server 3, Server 4}, and Shard 3 includes {Server 5, Server 6}. During one period, Shard 1 operates at full load, requiring processing to alleviate its high load pressure. During another period, Shards 2 and 3 have lower loads, requiring processing to conserve cluster resources for use by the other shards.

[0054] By processing multiple shards, flexible control over the shards is achieved, resulting in the rational allocation of cluster resources and further reducing cluster resource waste.

[0055] Optionally, in the long connection processing method provided in Embodiment 1 of this application, processing multiple shards based on their operating load to obtain adjusted multiple shards includes: if there is a first shard with an operating load greater than a first preset value, determining whether the current number of shards is less than the maximum number of shards; if the current number of shards is less than the maximum number of shards, calculating a second value based on the load of the current shards, where the second value represents the number of shards; splitting the first shard into shards of the second value to obtain adjusted multiple shards.

[0056] In this first embodiment, when a first shard has a high operating load, it needs to be split into multiple shards to obtain more computing resources to process service requests. Here, the first preset value represents the load threshold for a single shard to operate at a high load, and the maximum number of shards represents the maximum number of shards that can exist simultaneously in the cluster. When splitting shards, the content to be migrated from the original shard needs to be migrated to the new shard. Furthermore, this first embodiment employs a consistent hashing ring, which ensures that only a small amount of data needs to be migrated during data migration.

[0057] For example, during a certain period, the load on shard 1 of the three shards in the cluster exceeds a first preset value, and the number of shards (3) is less than the maximum number of shards. Therefore, shard 1 needs to be split to obtain more cluster resources. Then, based on the current load of the three shards, it is calculated that splitting shard 1 into two shards will satisfy the service request. Furthermore, after splitting shard 1 into two shards, the number of shards (4) in the cluster is less than the maximum number of shards. Therefore, it is determined that splitting shard 1 into two shards can satisfy the service request for the current period. Finally, shard 1 is split into shard 1 and shard 4, resulting in four adjusted shards. During the splitting process, data in shard 4 needs to be migrated from shard 1 to shard 4.

[0058] By splitting the shard with high operating load into multiple shards and verifying the number of shards in the cluster, load balancing among multiple shards is ensured, achieving the effect of reasonable allocation of cluster resources and further reducing cluster resource waste.

[0059] Optionally, in the long connection processing method provided in Embodiment 1 of this application, processing multiple shards based on their operating load to obtain adjusted multiple shards includes: if there is a second shard with an operating load less than a second preset value, then determining whether the current number of shards is greater than the minimum number of shards; if the current number of shards is greater than the minimum number of shards, then calculating the operating load of the second shard and its adjacent shards to obtain the target load; if the target load is less than a first preset value, then merging the second shard with its adjacent shards to obtain the adjusted multiple shards.

[0060] In this first embodiment, when a second shard with a low operating load exists, it needs to be merged with adjacent shards to save more cluster resources for other shards. Here, the second preset value represents the load threshold for a single shard to operate at a low load, and the minimum number of shards represents the minimum number of shards in the cluster required to ensure normal system operation. Furthermore, before merging the second shard with adjacent shards to obtain a new shard, it is necessary to verify whether the operating load of the new shard is less than the first preset value, i.e., to verify whether the operating load of the new shard is relatively high. If the operating load of the new shard is less than the first preset value, then the second shard continues to be merged with adjacent shards, and the content from the original shard is migrated to the new shard; if the operating load of the new shard is greater than or equal to the first preset value, then the second shard is merged with other adjacent shards to ensure that the operating load of the new shard is lower than the first preset value. Simultaneously, this first embodiment employs a consistent hashing ring to ensure that only a small amount of data needs to be migrated during data migration.

[0061] For example, during a certain period, the operating load of shard 2 in the cluster is less than the second preset value, and the number of shards (3) is greater than the minimum number of shards. Therefore, shard 2 needs to be merged with other shards to save cluster resources. Then, based on the operating loads of shard 2 and shard 1, the operating load of shard 4 (after merging shard 2 and shard 1) is calculated. If the operating load of shard 4 is greater than the first preset value, the operating load of shard 5 (after merging shard 2 and shard 3) is calculated. If the operating load of shard 5 is less than the first preset value, shard 2 and shard 3 are merged to obtain shard 5. Finally, the adjusted two shards are obtained from shard 1 and shard 5. Additionally, if the operating load of shard 5 is still greater than the first preset value, shard 2 will not be merged with adjacent shards for the time being.

[0062] By merging shards with lower operating loads with adjacent shards and verifying the operating load of the merged new shards, load balancing among multiple shards is ensured, achieving the effect of reasonable allocation of cluster resources and further reducing cluster resource waste.

[0063] Optionally, in the long connection processing method provided in Embodiment 1 of this application, before processing the multiple shards according to their operating load to obtain the adjusted multiple shards, the method further includes: determining the optimal sharding strategy based on the overall operating load of the multiple shards; and splitting or merging the multiple shards according to the optimal sharding strategy to obtain the adjusted multiple shards.

[0064] In this first embodiment, to more rationally adjust the number of shards and their management strategies, it is necessary to calculate the overall operational load of the shards to obtain the optimal sharding strategy. Specifically, Figure 3 This is a schematic diagram illustrating the process of maintaining long-lived connections across multiple shards based on sharded load balancing. For example... Figure 3 As shown, firstly, servers in multiple shards upload their runtime load through an interface, and the cluster monitors the runtime load of these servers. Then, it generates a management strategy for long-lived connections by performing real-time calculations on the runtime load information, and adjusts the adaptive regulator based on client request volume and downstream server load. Next, the cluster generates an optimal sharding strategy based on the long-lived connection management strategy and the adaptive regulator. Finally, based on the optimal sharding strategy, the connection management module splits or maintains multiple shards to ensure the normal operation of long-lived connections within each shard.

[0065] By formulating the optimal sharding strategy based on the load of multiple servers and the actual service requests, the operating load of multiple shards can be reasonably adjusted according to the actual service requests of the clients, ensuring load balancing among multiple shards and achieving the effect of reasonable allocation of cluster resources, further reducing the waste of cluster resources.

[0066] Optionally, in the long connection processing method provided in Embodiment 1 of this application, maintaining multiple long connections based on the adjusted multiple shards to adjust the cluster resources occupied by the multiple long connections includes: re-determining at least one target server to be used for data communication at preset intervals; adjusting the shard list based on at least one target server to obtain an updated shard list; and adjusting the long connections in the multiple shards through the updated shard list so that the client can communicate with at least one target server.

[0067] To provide services to clients based on their actual service request frequency, in this embodiment, the number of target servers for data communication needs to be recalculated periodically. Then, based on the number of target servers, the number of shards and the number of servers requiring long-lived connections within each shard are adjusted in a timely manner, resulting in an updated shard list. Finally, long-lived connections within the shards are adjusted based on the updated shard list. An adaptive algorithm can be used to calculate the number of shards to achieve optimal load balancing among them. Figure 3 As shown in the adaptive regulator, the adaptive regulator calculates the operating load of multiple servers using an adaptive algorithm.

[0068] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0069] Example 2

[0070] This application's second embodiment also provides a long-connection processing apparatus. It should be noted that the long-connection processing apparatus of this application's second embodiment can be used to execute the long-connection processing method provided in this application's first embodiment. The long-connection processing apparatus provided in this application's second embodiment will be described below.

[0071] Figure 4 This is a schematic diagram of a long-connection processing device according to Embodiment 2 of this application. Figure 4 As shown, the device includes: a first determining unit 401, a grouping unit 402, and a connecting unit 403.

[0072] Specifically, the first determining unit 401 is used to determine multiple servers, wherein the multiple servers are servers that have a connection relationship with the client.

[0073] Grouping unit 402 is used to group multiple servers using a preset hash algorithm to obtain a shard list, wherein the shard list includes multiple shards, each shard corresponding to at least one server, and the shard list includes information about at least one target server with which the client is to conduct data communication.

[0074] The connection unit 403 is used to establish multiple long connections between at least one target server and the client through a sharding list, wherein the client communicates with at least one target server through the multiple long connections.

[0075] The long-connection processing apparatus provided in Embodiment 2 of this application determines multiple servers through a first determining unit 401, wherein the multiple servers are servers that have a connection relationship with the client; a grouping unit 402 uses a preset hash algorithm to group the multiple servers to obtain a shard list, wherein the shard list includes multiple shards, each shard corresponding to at least one server, and the shard list includes information on at least one target server with which the client is to conduct data communication; a connection unit 403 establishes multiple long connections between at least one target server and the client through the shard list, wherein the client conducts data communication with at least one target server through multiple long connections, thereby solving the problem in related technologies where a large number of long connections are idle when the client and server conduct data communication through long connections at different time periods, resulting in a large amount of wasted cluster resources. By grouping multiple servers and determining the server to be connected in multiple shards, the client can conduct data communication with the server to be connected, achieving the effect of flexibly managing multiple long connections through sharding, achieving the effect of reasonably allocating cluster resources, and further achieving the effect of load balancing among multiple shards.

[0076] Optionally, in the long connection processing apparatus provided in Embodiment 2 of this application, the aforementioned grouping unit 402 includes: a first calculation subunit, configured to map the plurality of servers to a hash ring using the preset hash algorithm to obtain a mapped hash ring, wherein the partitions in the mapped hash ring correspond one-to-one with the shards in the plurality of shards; a first determining subunit, configured to determine the information of at least one target server from the plurality of servers based on the client's request service information; and an obtaining subunit, configured to obtain the shard list based on the information of the at least one target server and the plurality of shards.

[0077] Optionally, in the long connection processing apparatus provided in Embodiment 2 of this application, the grouping unit 402 further includes: a creation subunit, configured to create virtual servers if the number of the multiple servers is less than the number of shards of the hash ring before mapping the multiple servers to the hash ring using the preset hash algorithm to obtain the mapped hash ring, wherein the sum of the number of virtual servers and the number of the multiple servers is not less than the number of shards of the hash ring; the first calculation subunit further includes: a first calculation module, configured to map the multiple servers and the created virtual servers to the hash ring using the preset hash algorithm to obtain the mapped hash ring.

[0078] Optionally, in the long connection processing apparatus provided in Embodiment 2 of this application, the apparatus includes: a first processing unit, configured to, after establishing multiple long connections between the at least one target server and the client through the sharding list, process the multiple shards according to the operating load of the multiple shards to obtain adjusted multiple shards; and a maintenance unit, configured to continue maintaining the multiple long connections according to the adjusted multiple shards to adjust the cluster resources occupied by the multiple long connections.

[0079] Optionally, in the long-connection processing device provided in Embodiment 2 of this application, the first processing unit includes: a first judgment subunit, configured to determine whether the number of current shards is less than the maximum number of shards if there is a first shard with a running load greater than a first preset value; a second calculation subunit, configured to calculate a second value based on the load of the current shard if the number of current shards is less than the maximum number of shards, wherein the second value represents the number of shards; and a first processing subunit, configured to split the first shard into shards of the second value to obtain the adjusted multiple shards.

[0080] Optionally, in the long-connection processing device provided in Embodiment 2 of this application, the first processing unit includes: a second judgment subunit, configured to determine whether the number of current shards is greater than the minimum number of shards if there is a second shard with a running load less than a second preset value; a third calculation subunit, configured to calculate the running load of the second shard and the adjacent shard after merging if the number of current shards is greater than the minimum number of shards, to obtain the target load; and a second processing subunit, configured to merge the second shard and the adjacent shard if the target load is less than the first preset value, to obtain the adjusted multiple shards.

[0081] Optionally, in the long connection processing apparatus provided in Embodiment 2 of this application, the apparatus further includes: a second determining unit, configured to determine an optimal sharding strategy based on the overall operating load of the multiple shards before processing the multiple shards according to their operating load to obtain adjusted multiple shards; and a second processing unit, configured to split or merge the multiple shards according to the optimal sharding strategy to obtain the adjusted multiple shards.

[0082] Optionally, in the long connection processing apparatus provided in Embodiment 2 of this application, the maintenance unit includes: a second determining subunit, configured to re-determine at least one target server to be used for data communication at preset intervals; a third processing subunit, configured to adjust the shard list according to the at least one target server to obtain an updated shard list; and a fourth processing subunit, configured to adjust the long connections in the plurality of shards through the updated shard list so that the client can perform data communication with the at least one target server.

[0083] The long connection processing device includes a processor and a memory. The first determining unit 401, the grouping unit 402, and the connecting unit 403 mentioned above are all stored in the memory as program units. The processor executes the program units stored in the memory to realize the corresponding functions.

[0084] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can improve the utilization of cluster resources.

[0085] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0086] Embodiment 3 of the present invention provides a computer-readable storage medium storing a program thereon, which, when executed by a processor, implements a method for processing long connections.

[0087] Embodiment 4 of the present invention provides a processor for running a program, wherein the program executes a long-connection processing method during runtime.

[0088] like Figure 5 As shown, Embodiment 5 of the present invention provides an electronic device, the device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: determining multiple servers, wherein the multiple servers are servers that have a connection relationship with the client; using a preset hash algorithm to group the multiple servers to obtain a shard list, wherein the shard list includes multiple shards, each shard corresponding to at least one server, wherein the shard list includes information on at least one target server with which the client is to conduct data communication; and establishing multiple long connections between at least one target server and the client through the shard list, wherein the client conducts data communication with at least one target server through the multiple long connections.

[0089] When the processor executes the program, it also performs the following steps: using a preset hash algorithm to group multiple servers and obtain a shard list, including: mapping multiple servers to a hash ring using the preset hash algorithm to obtain a mapped hash ring, wherein the partitions in the mapped hash ring correspond one-to-one with the shards in the multiple shards; determining the information of at least one target server from the multiple servers based on the client's request service information; and obtaining a shard list based on the information of at least one target server and the multiple shards.

[0090] When the processor executes the program, it also performs the following steps: Before mapping multiple servers to a hash ring using a preset hash algorithm to obtain the mapped hash ring, the above method further includes: if the number of multiple servers is less than the number of shards of the hash ring, then creating virtual servers, wherein the sum of the number of virtual servers and the number of multiple servers is not less than the number of shards of the hash ring; mapping multiple servers to a hash ring using a preset hash algorithm to obtain the mapped hash ring includes: mapping multiple servers and the created virtual servers to the hash ring using a preset hash algorithm to obtain the mapped hash ring.

[0091] When the processor executes the program, it also performs the following steps: After establishing at least one target server and multiple long connections with the client through the shard list, the above method further includes: processing the multiple shards according to the running load of the multiple shards to obtain the adjusted multiple shards; and continuing to maintain the multiple long connections according to the adjusted multiple shards to adjust the cluster resources occupied by the multiple long connections.

[0092] When the processor executes the program, it also performs the following steps: based on the operating load of multiple shards, it processes multiple shards to obtain adjusted multiple shards, including: if there is a first shard with an operating load greater than a first preset value, it determines whether the number of current shards is less than the maximum number of shards; if the number of current shards is less than the maximum number of shards, it calculates a second value based on the load of the current shards, where the second value represents the number of shards; and it splits the first shard into shards of the second value to obtain adjusted multiple shards.

[0093] When the processor executes the program, it also performs the following steps: based on the operating load of multiple slices, it processes multiple slices to obtain adjusted multiple slices, including: if there is a second slice with an operating load less than a second preset value, it determines whether the number of current slices is greater than the minimum number of slices; if the number of current slices is greater than the minimum number of slices, it calculates the operating load of the second slice and its adjacent slices to obtain the target load; if the target load is less than a first preset value, it merges the second slice with its adjacent slices to obtain adjusted multiple slices.

[0094] When the processor executes the program, it also performs the following steps: Before processing the multiple slices based on their operating load to obtain the adjusted multiple slices, the above method further includes: determining the optimal sharding strategy based on the overall operating load of the multiple slices; splitting or merging the multiple slices based on the optimal sharding strategy to obtain the adjusted multiple slices.

[0095] When the processor executes the program, it also performs the following steps: maintaining multiple long connections based on the adjusted multiple shards, in order to adjust the cluster resources occupied by the multiple long connections, including: re-determining at least one target server to be used for data communication at preset intervals; adjusting the shard list based on at least one target server to obtain an updated shard list; and adjusting the long connections in the multiple shards through the updated shard list so that the client can communicate with at least one target server.

[0096] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.

[0097] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: determining multiple servers, wherein the multiple servers are servers that have a connection relationship with a client; using a preset hash algorithm to group the multiple servers to obtain a shard list, wherein the shard list includes multiple shards, each shard corresponding to at least one server, wherein the shard list includes information on at least one target server with which the client is to conduct data communication; and establishing multiple long connections between at least one target server and the client through the shard list, wherein the client conducts data communication with at least one target server through the multiple long connections.

[0098] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: using a preset hash algorithm to group multiple servers to obtain a shard list, including: mapping multiple servers to a hash ring using the preset hash algorithm to obtain a mapped hash ring, wherein the partitions in the mapped hash ring correspond one-to-one with the shards in the multiple shards; determining the information of at least one target server from the multiple servers based on the client's request service information; and obtaining a shard list based on the information of at least one target server and the multiple shards.

[0099] When executed on a data processing device, it is also suitable to execute an initialization program with the following method steps: before mapping multiple servers to a hash ring using a preset hash algorithm to obtain the mapped hash ring, the above method further includes: if the number of multiple servers is less than the number of shards of the hash ring, then creating virtual servers, wherein the sum of the number of virtual servers and the number of multiple servers is not less than the number of shards of the hash ring; mapping multiple servers to a hash ring using a preset hash algorithm to obtain the mapped hash ring includes: mapping multiple servers and the created virtual servers to the hash ring using a preset hash algorithm to obtain the mapped hash ring.

[0100] When executed on a data processing device, it is also suitable to execute an initialization procedure with the following steps: after establishing at least one target server and multiple long connections with the client through a shard list, the above method further includes: processing the multiple shards according to their operating load to obtain adjusted multiple shards; and continuing to maintain multiple long connections based on the adjusted multiple shards to adjust the cluster resources occupied by the multiple long connections.

[0101] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: processing multiple shards based on their operating load to obtain adjusted shards, including: if there is a first shard with an operating load greater than a first preset value, determining whether the current number of shards is less than the maximum number of shards; if the current number of shards is less than the maximum number of shards, calculating a second value based on the current shard load, where the second value represents the number of shards; splitting the first shard into shards of the second value to obtain adjusted shards.

[0102] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: processing multiple shards based on their operating load to obtain adjusted shards, including: if there is a second shard with an operating load less than a second preset value, determining whether the current number of shards is greater than the minimum number of shards; if the current number of shards is greater than the minimum number of shards, calculating the operating load of the second shard and its adjacent shards to obtain the target load; if the target load is less than a first preset value, merging the second shard with its adjacent shards to obtain adjusted shards.

[0103] When executed on a data processing device, it is also suitable to execute an initialization procedure with the following steps: before processing multiple shards based on their operating load to obtain adjusted shards, the above method further includes: determining the optimal sharding strategy based on the overall operating load of the multiple shards; splitting or merging the multiple shards based on the optimal sharding strategy to obtain adjusted shards.

[0104] When executed on a data processing device, it is also suitable to execute an initialization program with the following method steps: maintaining multiple long connections based on the adjusted multiple shards, in order to adjust the cluster resources occupied by the multiple long connections, including: re-determining at least one target server to be used for data communication at preset intervals; adjusting the shard list based on at least one target server to obtain an updated shard list; and adjusting the long connections in the multiple shards through the updated shard list so that the client can communicate with at least one target server.

[0105] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0106] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0107] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0108] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0109] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0110] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0111] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0112] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0113] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0114] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A method for processing long connections, characterized by, The method comprises the following steps: determining a plurality of service ends, wherein the plurality of service ends are service ends having a connection relationship with a client; grouping the plurality of service ends using a preset hash algorithm to obtain a shard list, wherein the shard list includes a plurality of shards, each shard corresponding to at least one service end, and the shard list includes information of at least one target service end to be communicated with the client; establishing a plurality of long connections between the at least one target service end and the client through the shard list, wherein the client communicates data with the at least one target service end through the plurality of long connections; after establishing the plurality of long connections between the at least one target service end and the client through the shard list, the method further comprises: processing the plurality of shards according to their running loads to obtain adjusted plurality of shards; continuing to maintain the plurality of long connections according to the adjusted plurality of shards to adjust the cluster resources occupied by the plurality of long connections; wherein, before processing the plurality of shards according to their running loads to obtain adjusted plurality of shards, the method further comprises: determining an optimal shard strategy through the overall running load of the plurality of shards; splitting or merging the plurality of shards according to the optimal shard strategy to obtain the adjusted plurality of shards.

2. The method of claim 1, wherein, grouping the plurality of service ends using a preset hash algorithm to obtain a shard list comprises: mapping the plurality of service ends into a hash ring through the preset hash algorithm to obtain a mapped hash ring, wherein the partitions in the mapped hash ring correspond one-to-one to the shards in the plurality of shards; determining the information of the at least one target service end from the plurality of service ends according to the request service information of the client; obtaining the shard list according to the information of the at least one target service end and the plurality of shards.

3. The method of claim 2, wherein, before mapping the plurality of service ends into a hash ring through the preset hash algorithm to obtain a mapped hash ring, the method further comprises: if the number of the plurality of service ends is less than the number of shards of the hash ring, creating virtual service ends, wherein the sum of the number of the virtual service ends and the number of the plurality of service ends is not less than the number of shards of the hash ring; mapping the plurality of service ends and the created virtual service ends into a hash ring through the preset hash algorithm to obtain a mapped hash ring. processing the plurality of shards according to their running loads to obtain adjusted plurality of shards comprises:

4. The method of claim 1, wherein, if there is a first shard with a running load greater than a first preset value, determining whether the current number of shards is less than a maximum number of shards; if the current number of shards is less than the maximum number of shards, calculating a second value according to the load condition of the current shard, wherein the second value represents the number of shards; splitting the first shard into shards of the second value to obtain the adjusted plurality of shards. ​ 5. The method of claim 4, wherein, The multiple shards are processed according to the running loads of the multiple shards to obtain adjusted multiple shards, including: If there is a second shard with a running load less than a second preset value, it is determined whether the number of current shards is greater than a minimum shard number; If the number of current shards is greater than the minimum shard number, a running load after the second shard and an adjacent shard are merged is calculated to obtain a target load; If the target load is less than the first preset value, the second shard and the adjacent shard are merged to obtain the adjusted multiple shards.

6. The method of claim 1, wherein, The multiple long connections are continuously maintained according to the adjusted multiple shards to adjust cluster resources occupied by the multiple long connections, including: At least one target server to be used for data communication is re-determined at a preset time interval; The shard list is adjusted according to the at least one target server to obtain an updated shard list; Long connections in the multiple shards are adjusted through the updated shard list, so that the client and the at least one target server perform data communication.

7. A long connection processing apparatus characterized by comprising: Including: A first determination unit is configured to determine multiple servers, wherein the multiple servers are servers in a connection relationship with a client; A grouping unit is configured to group the multiple servers by using a preset hash algorithm to obtain a shard list, wherein the shard list includes multiple shards, each shard corresponds to at least one server, and the shard list includes information of at least one target server to be used for data communication by the client; A connection unit is configured to establish multiple long connections between the at least one target server and the client through the shard list, wherein the client performs data communication with the at least one target server through the multiple long connections; The device further includes a first processing unit configured to process the multiple shards according to the running loads of the multiple shards to obtain adjusted multiple shards after the multiple long connections between the at least one target server and the client are established through the shard list; and a maintenance unit configured to continuously maintain the multiple long connections according to the adjusted multiple shards to adjust cluster resources occupied by the multiple long connections. The device further includes a second determination unit configured to determine an optimal shard strategy through an overall running load of the multiple shards before the multiple shards are processed according to the running loads of the multiple shards to obtain adjusted multiple shards; and a second processing unit configured to split or merge the multiple shards according to the optimal shard strategy to obtain the adjusted multiple shards.

8. An electronic device, comprising: One or more processors and a memory are included, the memory is used to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the long connection processing method in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Service instance access method and device and electronic equipment

    CN111262907A

  • Long connection establishment method and device, target equipment and storage medium

    CN115665225A