CN116743836A - Long connection communication link establishment method and device, electronic equipment and storage medium - Google Patents

Long connection communication link establishment method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN116743836A
CN116743836A CN202310840637.0A CN202310840637A CN116743836A CN 116743836 A CN116743836 A CN 116743836A CN 202310840637 A CN202310840637 A CN 202310840637A CN 116743836 A CN116743836 A CN 116743836A
Authority
CN
China
Prior art keywords
long
instance
connection
long connection
communication link
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310840637.0A
Other languages
Chinese (zh)
Inventor
丁琴
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Life Insurance Company of China Ltd
Original Assignee
Ping An Life Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Life Insurance Company of China Ltd filed Critical Ping An Life Insurance Company of China Ltd
Priority to CN202310840637.0A priority Critical patent/CN116743836A/en
Publication of CN116743836A publication Critical patent/CN116743836A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/143Termination or inactivation of sessions, e.g. event-controlled end of session
    • H04L67/145Termination or inactivation of sessions, e.g. event-controlled end of session avoiding end of session, e.g. keep-alive, heartbeats, resumption message or wake-up for inactive or interrupted session

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Health & Medical Sciences (AREA)
  • Cardiology (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application provides a method and a device for establishing a long connection communication link, electronic equipment and a storage medium thereof, which belong to the field of financial science and technology, wherein the long connection is used for connecting a client and an instance running on a server side by creating a plurality of long connections, the instance of the long connection is inquired for each long connection to obtain an instance address, the long connection is classified according to the instance address to obtain a plurality of first groups, wherein the long connection of each first group can be connected with the same instance, the relation data between the long connection and the instance is obtained according to the first number of the long connection in the first group and a first preset threshold value, and the long connection communication link of the instance is established according to the relation data, so that the request distributed to each instance of the server side is balanced, and overload of the server is avoided.

Description

Long connection communication link establishment method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of financial science and technology, and in particular, to a method and apparatus for establishing a long connection communication link, an electronic device, and a storage medium.
Background
With the continuous development of internet banking users and businesses, banking systems need to face massive and high-intensity business data calculation, a single background server often cannot meet the requirements, and the background server must be added to improve the calculation capability of the server.
Taking a transaction system in a bank system as an example, a user sends a transaction request to a background server through a client, and the number of the clients is large, so that thousands of transaction requests received by the background server at the same time can be generated, and the data transaction has high requirement on real-time performance, which brings great pressure to the parallel processing capacity of the background server. To relieve the stress of the background servers, transaction requests are processed by multiple background servers. How to balance and distribute the traffic among a plurality of background servers and realize the load balance among a plurality of background servers becomes a problem to be solved urgently.
Disclosure of Invention
The embodiment of the application mainly aims to provide a method and a device for establishing a long-connection communication link, electronic equipment and a storage medium, aiming at balancing requests distributed to a server and avoiding overload of the server.
To achieve the above object, a first aspect of an embodiment of the present application provides a long-connection communication link establishment method, including:
creating a plurality of long connections; the long connection is used for connecting the client and the instance running on the server;
For each long connection, inquiring the instance of the long connection to obtain the instance address;
classifying the long connection according to the instance address to obtain a plurality of first groups, wherein the long connection of each first group can be connected with the same instance;
obtaining relation data between the long connection and the instance according to the first quantity of the long connection in the first group and a first preset threshold value;
and establishing a long connection communication link of the instance according to the relation data.
In some embodiments, the classifying the long connection according to the instance address, to obtain a plurality of first packets, includes:
comparing the instance addresses of a plurality of the long connections;
and dividing the long connection with the same instance address into a group to obtain a plurality of first packets.
In some embodiments, the obtaining the relationship data between the long connection and the instance according to the first number of the long connection in the first packet and a first preset threshold value includes:
if the first number is greater than the first preset threshold, eliminating the long connection in the first group until the first number is equal to the first preset threshold, and establishing a corresponding relation between the long connection and the instance to obtain the relation data;
If the first number is smaller than the first preset threshold, continuing to create long connections until the first number is equal to the first preset threshold, and building a corresponding relation between the long connections and the examples to obtain the relation data;
and if the first quantity is equal to the first preset threshold value, establishing a corresponding relation between the long connection and the instance to obtain the relation data.
In some embodiments, after the obtaining the relationship data between the long connection and the instance according to the first number of the long connection in the first packet and the first preset threshold, the long connection communication link establishment method further includes:
taking the long connection as an initial long connection, and storing the initial long connection into a preset connection pool;
inquiring the instance of the initial long connection for each initial long connection in the connection pool at preset updating time to obtain a first instance address;
classifying the initial long connection according to the first instance address to obtain a plurality of second groups, wherein the initial long connection of each second group can be connected with the same instance;
and updating the connection pool according to the second number of the initial long connection and a second preset threshold value in the second group.
In some embodiments, the updating the connection pool according to the second number of the initial long connections in the second packet and a second preset threshold includes:
if the second number is greater than the second preset threshold, rejecting the initial long connection from the second packet to update the connection pool;
and if the second number is smaller than the second preset threshold value, continuing to create the initial long connection so as to update the connection pool.
In some embodiments, after the establishing the long-connection communication link of the instance according to the relationship data, the long-connection communication link establishment method further comprises:
creating a plurality of short connections; the short connection is used for connecting the client and the instance;
querying the instance of the short connection for each short connection to obtain a second instance address;
and detecting survival of the instance according to the second instance address.
In some embodiments, after the establishing the long-connection communication link of the instance according to the relationship data, the long-connection communication link establishment method further comprises:
acquiring an access request;
the access request is sent to the instance over the long connection communication link.
To achieve the above object, a second aspect of the embodiments of the present application proposes a long-connection communication link establishment apparatus including:
a creation module for creating a plurality of long connections; the long connection is used for connecting the client and the instance running on the server;
a query module for querying, for each of the long connections, an instance address of the instance on the long connection;
the classification module is used for classifying the long connection according to the instance address to obtain a plurality of first groups, wherein the long connection of each first group can be connected with the same instance;
the judging module is used for obtaining the relation data between the long connection and the instance according to the first quantity of the long connection in the first group and a first preset threshold value;
and the communication link establishment module is used for establishing a long connection communication link of the instance according to the relation data.
To achieve the above object, a third aspect of the embodiments of the present application provides an electronic device, which includes a memory and a processor, where the memory stores a computer program, and the processor executes the computer program to implement the long connection communication link establishment method described in the first aspect.
To achieve the above object, a fourth aspect of the embodiments of the present application proposes a computer-readable storage medium storing a computer program which, when executed by a processor, implements the long connection communication link establishment method according to the above first aspect.
The long connection communication link establishment method, the long connection communication link establishment device, the electronic equipment and the computer readable storage medium provided by the application are characterized in that a plurality of long connections are established, for each long connection, an instance of the long connection is inquired to obtain an instance address, the long connection is classified according to the instance address to obtain a plurality of first groups, and the long connection connected to the same instance can be divided into one group. According to the first quantity of long connections in the first group and a first preset threshold value, the relation data between the long connections and the examples is obtained, the quantity of the long connections of one example connection can be adjusted according to the first quantity and the first threshold value, so that the quantity of the long connections distributed to each example is absolutely balanced, a long connection communication link of the example is established according to the relation data, the request distributed to each example of a server side is balanced, and overload of the server is avoided.
Drawings
Fig. 1 is a flowchart of a method for establishing a long connection communication link according to an embodiment of the present application;
fig. 2 is a flowchart of step S130 in fig. 1;
fig. 3 is a flowchart of step S140 in fig. 1;
fig. 4 is another flowchart of a method for establishing a long connection communication link according to an embodiment of the present application;
fig. 5 is a flowchart of step S440 in fig. 4;
fig. 6 is another flowchart of a method for establishing a long connection communication link according to an embodiment of the present application;
fig. 7 is another flowchart of a method for establishing a long connection communication link according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a long-connection communication link establishment apparatus according to an embodiment of the present application;
fig. 9 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present application.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
It should be noted that although functional block division is performed in a device diagram and a logic sequence is shown in a flowchart, in some cases, the steps shown or described may be performed in a different order than the block division in the device, or in the flowchart. The terms first, second and the like in the description and in the claims and in the above-described figures, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the application only and is not intended to be limiting of the application.
First, several nouns involved in the present application are parsed:
examples: in a computer language, a class is called an instance after instantiation, where the class is static, does not occupy process memory, and has dynamic memory. An instance is a specific object that needs to be determined from context. In a database, an instance is a collection of programs, such as in an oracle database, an instance is a database program that supports the database running; in cloud service, an instance of a cloud server is an independent computing unit formed by virtual cloud computing resources, namely, the instance of the cloud server is a complete server capable of achieving functions of building websites, deploying applications, testing codes and the like.
Short connection: when two communication parties have data interaction, a connection is established, and after the data transmission is finished, the connection is disconnected, namely, each connection only completes the transmission of one service.
Long connection: a plurality of data packets may be continuously transmitted over one connection, and if no data packet is transmitted during connection hold, both parties of communication are required to transmit a link detection packet. Long connections are often used in situations where frequent, point-to-point communications are operated and the number of connections cannot be excessive.
Transmission control protocol (Transmission Control Protocol, TCP): is a connection-oriented, reliable, byte stream based transport layer communication protocol.
Internetworking protocol (Internet Protocol, IP): is a network layer protocol in the TCP/IP architecture.
IP address (Internet Protocol Address): the internet protocol address is a unified address format provided by the IP protocol, and it allocates a logical address to each network and each host on the internet, so as to mask the difference of physical addresses.
With the continuous development of internet banking users and businesses, banking systems need to face massive and high-intensity business data calculation, a single background server often cannot meet the requirements, and the background server must be added to improve the calculation capability of the server.
Taking a transaction system in a bank system as an example, when a user uses a financial card such as a bank card and a credit card to conduct consumption transaction, a client reads financial card information and sends a transaction request containing the financial card information and the transaction information to a background server, and the number of the clients is large, so that thousands of transaction requests received by the background server at the same time can be received, and the data transaction has high requirement on real-time performance, which brings great pressure to the parallel processing capacity of the background server. To relieve the stress of the background servers, transaction requests are processed by multiple background servers. How to balance and distribute the traffic among a plurality of background servers and realize the load balance among a plurality of background servers becomes a problem to be solved urgently.
In the related art, a communication connection between a background server and a client is established by means of a short connection or a long connection. For short-connection applications, when a client uses a connection, a new connection can be created by directly calling a load balancer, and the control right of the connection is in the load balancer. For services with end-to-end and higher performance requirements, such as transaction systems, long connections can eliminate more operations of establishing and disconnecting connections, saving system resources and response time. When the long connection is applied to a banking system, a client needs to maintain a connection pool of the client to ensure that the connection used each time is an existing connection, and a new connection cannot be created by calling a load balancer each time, so that the control right of the connection is preposed from the load balancer to the client. At present, in the balancing algorithm of the load balancer, the minimum connection number algorithm can maximally ensure the long connection allocation balancing, but because the control right of the connection is at the client, the load balancer cannot control the connection state of the long connection, and cannot ensure that the long connection allocated to the server is absolutely balanced, so that the server is overloaded.
Based on this, the embodiment of the application provides a long-connection communication link establishment method, a long-connection communication link establishment device, an electronic device and a computer readable storage medium, aiming at equalizing the request distributed to the server side and avoiding overload of the server side.
The method for establishing a long connection communication link, the apparatus for establishing a long connection communication link, the electronic device, and the computer readable storage medium provided in the embodiments of the present application are specifically described by the following embodiments, and the method for establishing a long connection communication link in the embodiments of the present application is first described.
The embodiment of the application provides a method for establishing a long-connection communication link, which relates to the field of financial science and technology. The method for establishing the long-connection communication link can be applied to the terminal, the server side and software running in the terminal or the server side. In some embodiments, the terminal may be a smart phone, tablet, notebook, desktop, etc.; the server side can be configured as an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, and a cloud server for providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, basic cloud computing services such as big data and artificial intelligent platforms and the like; the software may be an application or the like that implements the long-connection communication link establishment method, but is not limited to the above form.
The application is operational with numerous general purpose or special purpose computer system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
Fig. 1 is an optional flowchart of a method for establishing a long connection communication link according to an embodiment of the present application, which is applied to a client, and the method in fig. 1 may include, but is not limited to, steps S110 to S150.
Step S110, creating a plurality of long connections; the long connection is used for connecting the client and the instance running on the server;
step S120, inquiring the instance of the long connection for each long connection to obtain an instance address;
step S130, classifying the long connection according to the instance address to obtain a plurality of first groups, wherein the long connection of each first group can be connected with the same instance;
step S140, obtaining the relation data between the long connection and the instance according to the first quantity of the long connection in the first group and a first preset threshold value;
step S150, establishing a long connection communication link of the instance according to the relation data.
The steps S110 to S150 illustrated in the embodiment of the present application classify long connections by instance address, and can divide long connections connected to the same instance into a group. According to the first quantity of long connections in the first group and a first preset threshold value, the relation data between the long connections and the examples are obtained, the quantity of the long connections of one example connection can be adjusted according to the first quantity and the first threshold value, so that the quantity of the long connections distributed to each example is absolutely balanced, a long connection communication link of the example is established according to the relation data, the requests distributed to each example of a server side are absolutely balanced, overload of the server is avoided, and the service performance of the server for a large number of requests is improved.
In step S110 of some embodiments, in a transaction system of a bank, a user uses a financial card such as a bank card, a credit card, or a digital wallet to perform transaction consumption, a client reads card information or digital wallet information, sends a transaction request including the card information and the transaction information, and a transaction request including the wallet information and the transaction information to a server in a long connection transmission manner, where the card information may be a card number and a password of the financial card, the wallet information may be a type, an account number and a password of the digital wallet, the transaction information may be a transaction amount, a transaction object, and the like, and the client may be an online banking application, a card reader, a cash register, or the like. The server receives the transaction request, processes the transaction request and returns the transaction result to the client. By ensuring load balancing at the server side, real-time transactions are ensured.
When a request is transmitted, a client creates a plurality of long connections, wherein the long connections are TCP connection channels, are virtual connections and are used for connecting the client and an instance running on a server, the channels are abstractions of TCP connection, each channel maps one TCP connection, and the instance can be a server node in a server cluster or a micro-service or an application program of the server.
In step S120 of some embodiments, the client and the server have network devices such as a gateway, a network proxy, and a load balancer, which make the IP address of each instance of the server invisible to the client, so the IP address acquisition interface needs to be called to acquire the IP address of the instance. For each long connection, the client calls an IP address acquisition interface to acquire an IP address from the server, and the server returns the IP address of the instance to the client to acquire the instance address. It should be noted that, the heartbeat packet may also be sent to the server by the timing request IP address acquisition interface to keep the long connection alive.
Referring to fig. 2, in some embodiments, step S130 may include, but is not limited to, steps S210 to S220:
step S210, comparing a plurality of long connection instance addresses;
in step S220, the long connections with the same instance address are divided into a group, resulting in a plurality of first packets.
In step S210 of some embodiments, when classifying long connections, the long connections are classified according to instance addresses by comparing instance addresses of a plurality of long connections created by the client.
In step S220 of some embodiments, since a certain number of long connections are created, there may be a plurality of long connections connected to the same instance, and the addresses of the instances of the long connections are the same, which indicates that the long connections are connected to the same instance, and the long connections connected to the same instance are divided into a group, so as to obtain a first packet, where the first packet includes at least one long connection.
In the steps S210 to S220, the number of connections of an instance can be obtained by dividing the long connections connected to the same instance into a group, so that the long connections are distributed to the instance according to the number of connections, and the long connections are distributed in absolute balance between the client and the server, and the balance between the client and the server directly reaches the balanced state, so that the balance effect is not affected by intermediate links such as a load equalizer, a network proxy and the like.
Referring to fig. 3, in some embodiments, step S140 may include, but is not limited to, one of steps S310, 320, and S330:
step S310, if the first number is greater than a first preset threshold, eliminating long connections in the first group until the first number is equal to the first preset threshold, and establishing a corresponding relation between the long connections and the examples to obtain relation data;
step S320, if the first number is smaller than the first preset threshold, continuing to create long connection until the first number is equal to the first preset threshold, and establishing a corresponding relation between the long connection and the instance to obtain relation data;
step S330, if the first number is equal to the first preset threshold, a corresponding relationship between the long connection and the instance is established, and relationship data is obtained.
In step S310 of some embodiments, when long connection allocation is unbalanced in a certain period of time, service performance of an instance is reduced. Specifically, the number of long connections in the first packet is detected to obtain a first number, a first preset threshold is determined, the first preset threshold is the number of the long connections designated in the first packet, if the first number is larger than the first preset threshold, it is indicated that the number of the long connections in the first packet exceeds the designated number, and the long connections exceeding the designated number are released. When the first number is equal to a first preset threshold, a corresponding relation is established between the long connection channels and the examples, and relation data is obtained, wherein the relation data is used for representing the mapping relation between the long connection of the client and the examples of the server. It will be appreciated that the number of first packets is equal to the number of server-side instances.
In step S320 of some embodiments, when the first number is less than the first preset threshold, which indicates that the number of long connections in the first packet does not reach the specified number, the long connections continue to be created, and all existing long connections are regrouped according to the instance address of the long connection, so as to update the first packet until the first number of long connections in the first packet is equal to the first preset threshold.
In step S330 of some embodiments, if the first number is equal to the first preset threshold, it is indicated that the number of long connections in the first packet reaches the specified number, and the corresponding relationship between the long connection and the instance is directly established without creating or releasing the long connection, so as to obtain the relationship data.
Through the steps S310 to S330, the number of long connections in each first packet reaches the designated number of the long connections of the first packet, so as to limit the number of long connections that can be connected by one instance, realize load balancing of the server, and avoid overload of the server.
Referring to fig. 4, in some embodiments, after step S140, the long connection communication link establishment method may include, but is not limited to, steps S410 to S440:
step S410, taking the long connection as an initial long connection, and storing the initial long connection into a preset connection pool;
step S420, inquiring an instance of the initial long connection for each initial long connection in the connection pool at a preset updating time to obtain a first instance address;
step S430, classifying the initial long connection according to the first instance address to obtain a plurality of second packets, wherein the initial long connection of each second packet can connect the same instance;
Step S440, updating the connection pool according to the second number of the initial long connection in the second group and the second preset threshold.
In step S410 of some embodiments, to facilitate maintenance of the long connection, the long connection is taken as an initial long connection, and the initial long connection is stored into a preset connection pool.
In step S420 of some embodiments, the long connection period may be released by other load balancers without being used, and the server may also have capacity expansion, capacity shrinkage, IP address change, etc. in the instance, so that it is necessary to detect at regular time to update the connection pool, and ensure that the connection pool is always in a state of balanced allocation. And in preset updating time, all initial long connections in the connection pool are polled, and an IP address acquisition interface is called to acquire an example IP address to which each initial long connection is connected, so that a first example address of an example corresponding to the initial long connection is obtained.
In step S430 of some embodiments, the initial long connection with the same first instance address is divided into a group, resulting in a plurality of second packets. It will be appreciated that the number of second packets is equal to the number of server-side instances.
In step S440 of some embodiments, the second number is an actual number of initial long connections in the second packet, the second preset threshold is a specified number of initial long connections in the second packet, and the initial long connections are recreated or released according to the second number and the second preset threshold to update the connection pool. Specifically, if the second number is greater than a second preset threshold, the initial long connection is removed from the second packet to update the connection pool, if the second number is less than the second preset threshold, the initial long connection is continuously created to update the connection pool, and if the second number is equal to the second preset threshold, the number of the initial long connection in the current connection pool is maintained, and the connection pool is not updated. It will be appreciated that the sum of the actual number of initial long connections in each second packet is equal to the total number of initial long connections in the connection pool.
In the above steps S410 to S440, by periodically updating the connection pool, when the initial long connection is released due to long-time non-use, the IP address of the server side instance changes, etc., the initial long connection of the connection pool can be kept in a state of balanced allocation, and the long connection can be kept in a connected state by the periodic polling, so that the resource consumption caused by frequent connection creation can be reduced to the maximum extent.
Referring to fig. 5, in some embodiments, step S440 may include, but is not limited to, including step S510 or step S520:
step S510, if the second number is larger than the second preset threshold, the initial long connection is removed from the second group so as to update the connection pool;
step S520, if the second number is smaller than the second preset threshold, the initial long connection is continuously created to update the connection pool.
In step S510 of some embodiments, if the second number is greater than the second preset threshold, which indicates that the actual number of the initial long connections in the second packet exceeds the specified number, the number of the initial long connections of the same instance is excessive, and in order to ensure load balancing of the instance, the initial long connections are removed from the second packet to update the connection pool until the second number is equal to the second preset threshold.
In step S520 of some embodiments, if the second number is smaller than the second preset threshold, which indicates that the actual number of the initial long connections in the second packet does not exceed the specified number, the initial long connections are continuously created in the connection pool, and the initial long connections are classified according to the first instance addresses of the initial long connections, so as to update the second packet, until the actual number of the initial long connections in the second packet is equal to the second preset threshold, and the update of the connection pool is completed.
Through the steps S510 to S520, the actual number of the initial long connections in the second packet can be equal to the second preset threshold, so as to ensure that the same instance of connection has a specified number of initial long connections, so as to realize load balancing.
In step S150 of some embodiments, the client includes a built-in load balancer, the built-in load balancer selects an initial long connection from the connection pool, and automatically creates a TCP connection chain from the client to the intermediate network device to the server according to the relationship data, so as to obtain a long connection communication link from the client to the instance, where all the long connection communication links support TCP connection. In the long connection state, the long connection communication link may be maintained for a period of time until the devices such as the operating system or the load balancer clear the idle long connection.
In some embodiments, the intermediate network device may allocate a long connection to an instance with the smallest number of connections, and implement load balancing together with the long connection communication link establishment method according to the embodiments of the present application.
Referring to fig. 6, in some embodiments, after step S150, the long connection communication link establishment method may include, but is not limited to, steps S610 to S630:
step S610, creating a plurality of short connections; the short connection is used for connecting the client and the instance;
step S620, inquiring the instance of the short connection to obtain a second instance address for each short connection;
in step S630, the instance is subjected to survival detection according to the second instance address.
In step S610 of some embodiments, in order to discover newly added and dropped service instances in time, the client creates multiple short connections at regular time.
In step S620 of some embodiments, for each short connection, an IP address acquisition interface is invoked to query the instance to which the short connection is connected, resulting in a second instance address.
In step S630 of some embodiments, a heartbeat packet is sent to the server-side instance corresponding to the second instance address, and after the server-side instance receives the heartbeat packet, the server-side instance returns a response to the client, and the client can receive the response, which indicates that the server-side instance is in a surviving state. If the client does not receive the response within a period of time, in order to avoid that the client does not receive the response due to packet loss caused by network reasons, the heartbeat packet is continuously sent to the server side instance until the sending times reach a threshold value, the client does not receive the response, and the server side instance is indicated to be offline.
Through the steps S610 to S630, the newly added and offline instance can be found in time, so that the request is prevented from being sent to the offline instance, and the request cannot be responded in time. By sending the request to the newly added instance, the request can be responded quickly, meanwhile, the burden of other instances is reduced, and the service performance of the server side is improved.
Referring to fig. 7, in some embodiments, after step S150, the long connection communication link establishment method may further include, but is not limited to, steps S710 to S720:
step S710, obtaining an access request;
in step S720, the access request is sent to the instance over the long connection communication link.
In step S710 of some embodiments, the client includes a service function module, and the user performs an operation on the service function module, triggers a corresponding operation event, and obtains an access request to request data from an instance of the server. The service function module can be a transfer module, a user inputs a transfer account number, a transaction password and a transaction amount on the service function module, clicks a transfer button, triggers a transfer transaction event and obtains a transfer transaction request. The service function module can also be a balance inquiry module, and a user inputs an account number and a password on the service function module, clicks an inquiry button, triggers a transaction inquiry event and obtains a transaction inquiry request.
In step S720 of some embodiments, different instances of the access request are continuously sent to the server through the long-connection communication link, so as to improve the service performance of the server, and the server returns the required data to the server. For example, the transfer transaction request is sent to a server side instance corresponding to the long connection through the long connection communication link, the instance processes the transfer transaction request, virtual resources corresponding to the transaction amount are deducted from the account of the transfer party, virtual resources corresponding to the transaction amount are added to the account of the collection party, a transaction result is obtained, and transaction information such as the transaction date, the collection party, the transaction amount and the like is returned to the client side. For example, the transaction inquiry request is sent to the server side instance corresponding to the long connection through the long connection communication link, the instance processes the transaction inquiry request, checks the account balance, and returns the account balance to the client side.
Through the steps S710 to S720, the access requests distributed to different instances can be absolutely balanced, the access requests such as transaction inquiry and transfer of the client can be timely satisfied, and the service performance of the server for responding to a large number of access requests is improved.
The method for establishing the long connection communication link comprises the following steps: creating a plurality of long connections, polling each long connection, calling an IP address acquisition interface to inquire an instance of each long connection to obtain an instance address, dividing the long connections with the same instance address into a group to obtain a plurality of first groups, detecting the number of the long connections in each first group to obtain a first number, subtracting the first number from a first preset threshold to obtain a first difference value if the first number is larger than the first preset threshold, removing the first preset number of long connections from the first group, and enabling the first preset number to be equal to the first difference value; if the first number is smaller than a first preset threshold, continuing to create long connections, acquiring instance addresses of all the long connections, reclassifying the long connections according to the instance addresses until the first number of the long connections in the first group is equal to the first preset threshold, establishing a corresponding relation between the long connections and the instances, obtaining relation data, selecting the long connections as target long connections through a built-in load equalizer, establishing a long connection communication link from the target long connections to the target instances according to the relation data, acquiring access requests, and sending the access requests to the instances through the long connection communication link. The client initiates the connection flow so that the number of long connections initially allocated to the instance is absolutely balanced.
The long connection period is not used and can be released by the load equalizer of the intermediate link, and the example of the server side is also likely to have expansion and contraction capacity, IP address change and the like, so that the connection pool needs to be updated regularly.
Taking the long connection as an initial long connection, storing the initial long connection into a connection pool, polling each initial long connection in the connection pool, calling an IP address acquisition interface to inquire an instance of each initial long connection to obtain an instance address, dividing the initial long connection with the same instance address into a group to obtain a plurality of second groups, detecting the number of the initial long connection in each second group to obtain a second number, subtracting the second number from a second preset threshold value if the second number is larger than the second preset threshold value to obtain a second difference value, and removing the second preset number of initial long connections from the second group, wherein the second preset number is equal to the second difference value; if the second number is smaller than the second preset threshold, continuing to create the initial long connection, acquiring the instance addresses of all the initial long connections, and reclassifying the initial long connection according to the instance addresses until the second number of the long connections in the second packet is equal to the second preset threshold.
The method for establishing the long-connection communication link in the embodiment of the application is not limited in development language, network protocol and universality, and can solve the problem of load balancing as long as the long-connection communication link can be established by using the method for establishing the long-connection communication link in the embodiment of the application as long as the whole link supports long connection, and ensures that the long connection is distributed in absolute balance between a client and a server without changing the existing architecture, and the balance effect is not influenced by various load balancing and network agents. By keeping long connections with regular polling, resource consumption due to frequent creation of connections can be minimized. The method for establishing the long-connection communication link can also be combined with a minimum connection number scheme to realize load balancing.
Referring to fig. 8, an embodiment of the present application further provides a long-connection communication link establishment apparatus, which is applied to a client and can implement the long-connection communication link establishment method, where the long-connection communication link establishment apparatus includes:
a creation module 810 for creating a plurality of long connections; the long connection is used for connecting the client and the instance running on the server;
a query module 820, configured to query, for each long connection, an instance of the long connection, to obtain an instance address;
a classification module 830, configured to classify the long connection according to the instance address, to obtain a plurality of first packets, where the long connection of each first packet can connect to the same instance;
a judging module 840, configured to obtain relationship data between the long connection and the instance according to the first number of the long connection in the first packet and the first preset threshold;
the communication link establishment module 850 is configured to establish a long-connection communication link of the instance according to the relationship data.
In some embodiments, classification module 830 includes:
a comparison unit for comparing a plurality of long connection instance addresses;
and the dividing unit is used for dividing the long connection with the same instance address into a group to obtain a plurality of first groups.
In some embodiments, the determination module 840 includes:
The first judging unit is used for eliminating the long connection in the first group if the first number is larger than a first preset threshold value until the first number is equal to the first preset threshold value, and establishing a corresponding relation between the long connection and the instance to obtain relation data;
the second judging unit is used for continuously establishing long connection if the first number is smaller than a first preset threshold value until the first number is equal to the first preset threshold value, and establishing a corresponding relation between the long connection and the instance to obtain relation data;
and the third judging unit is used for establishing the corresponding relation between the long connection and the instance to obtain the relation data if the first quantity is equal to a first preset threshold value.
In some embodiments, the long connection communication link establishment apparatus further comprises:
the storage module is used for taking the long connection as an initial long connection and storing the initial long connection into a preset connection pool;
the first computing module is used for inquiring the instance of the initial long connection for each initial long connection in the connection pool at preset updating time to obtain a first instance address;
the second computing module is used for classifying the initial long connection according to the first instance address to obtain a plurality of second groups, wherein the initial long connection of each second group can be connected with the same instance;
And the updating module is used for updating the connection pool according to the second number of the initial long connections in the second packet and a second preset threshold value.
In some embodiments, the update module includes:
a first updating unit, configured to, if the second number is greater than a second preset threshold, reject the initial long connection from the second packet, so as to update the connection pool;
and the second updating unit is used for continuously creating the initial long connection to update the connection pool if the second number is smaller than a second preset threshold value.
In some embodiments, the long connection communication link establishment apparatus further comprises:
a third computing module for creating a plurality of short connections; the short connection is used for connecting the client and the instance;
a fourth calculation module, configured to query, for each short connection, an instance of the short connection, to obtain a second instance address;
and the survival detection module is used for carrying out survival detection on the instance according to the second instance address.
In some embodiments, the long connection communication link establishment apparatus further comprises:
the request acquisition module is used for acquiring the access request;
and the sending module is used for sending the access request to the instance through the long connection communication link.
The specific implementation of the long-connection communication link establishment device is basically the same as the specific embodiment of the long-connection communication link establishment method described above, and will not be described herein.
The embodiment of the application also provides electronic equipment, which comprises a memory and a processor, wherein the memory stores a computer program, and the processor realizes the long connection communication link establishment method when executing the computer program. The electronic equipment can be any intelligent terminal including a tablet personal computer, a vehicle-mounted computer and the like.
Referring to fig. 9, fig. 9 illustrates a hardware structure of an electronic device according to another embodiment, the electronic device includes:
the processor 910 may be implemented by a general-purpose CPU (central processing unit), a microprocessor, an application-specific integrated circuit (ApplicationSpecificIntegratedCircuit, ASIC), or one or more integrated circuits, etc. for executing related programs to implement the technical solutions provided by the embodiments of the present application;
memory 920 may be implemented in the form of read-only memory (ReadOnlyMemory, ROM), static storage, dynamic storage, or random access memory (RandomAccessMemory, RAM). Memory 920 may store an operating system and other application programs, and when the technical solutions provided in the embodiments of the present disclosure are implemented in software or firmware, relevant program codes are stored in memory 920 and invoked by processor 910 to perform the long connection communication link establishment method of the embodiments of the present disclosure;
An input/output interface 930 for inputting and outputting information;
the communication interface 940 is configured to implement communication interaction between the device and other devices, and may implement communication in a wired manner (e.g., USB, network cable, etc.), or may implement communication in a wireless manner (e.g., mobile network, WIFI, bluetooth, etc.);
a bus 950 for transferring information between components of the device (e.g., processor 910, memory 920, input/output interface 930, and communication interface 940);
wherein processor 910, memory 920, input/output interface 930, and communication interface 940 implement communication connections among each other within the device via a bus 950.
The embodiment of the application also provides a computer readable storage medium, which stores a computer program, and the computer program realizes the long connection communication link establishment method when being executed by a processor.
The memory, as a non-transitory computer readable storage medium, may be used to store non-transitory software programs as well as non-transitory computer executable programs. In addition, the memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, the memory optionally includes memory remotely located relative to the processor, the remote memory being connectable to the processor through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The long connection communication link establishment method, the long connection communication link establishment device, the electronic equipment and the computer readable storage medium provided by the embodiment of the application classify the long connection through the instance address, and can divide the long connection connected to the same instance into a group. According to the first quantity of long connections in the first group and a first preset threshold value, the relation data between the long connections and the examples is obtained, the quantity of the long connections of one example connection can be adjusted according to the first quantity and the first threshold value, so that the quantity of the long connections distributed to each example is absolutely balanced, a long connection communication link of the example is established according to the relation data, the request distributed to each example of a server side is absolutely balanced, and overload of the server is avoided.
The embodiments described in the embodiments of the present application are for more clearly describing the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application, and those skilled in the art can know that, with the evolution of technology and the appearance of new application scenarios, the technical solutions provided by the embodiments of the present application are equally applicable to similar technical problems.
It will be appreciated by persons skilled in the art that the embodiments of the application are not limited by the illustrations, and that more or fewer steps than those shown may be included, or certain steps may be combined, or different steps may be included.
The above described apparatus embodiments are merely illustrative, wherein the units illustrated as separate components may or may not be physically separate, i.e. may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
Those of ordinary skill in the art will appreciate that all or some of the steps of the methods, systems, functional modules/units in the devices disclosed above may be implemented as software, firmware, hardware, and suitable combinations thereof.
The terms "first," "second," "third," "fourth," and the like in the description of the application and in the above figures, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be understood that in the present application, "at least one (item)" means one or more, and "a plurality" means two or more. "and/or" for describing the association relationship of the association object, the representation may have three relationships, for example, "a and/or B" may represent: only a, only B and both a and B are present, wherein a, B may be singular or plural. The character "/" generally indicates that the context-dependent object is an "or" relationship. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s). For example, at least one (one) of a, b or c may represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", wherein a, b, c may be single or plural.
In the several embodiments provided by the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the above-described division of units is merely a logical function division, and there may be another division manner in actual implementation, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described above as separate components may or may not be physically separate, and components shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a storage medium, including multiple instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method of the various embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing a program.
The preferred embodiments of the present application have been described above with reference to the accompanying drawings, and are not thereby limiting the scope of the claims of the embodiments of the present application. Any modifications, equivalent substitutions and improvements made by those skilled in the art without departing from the scope and spirit of the embodiments of the present application shall fall within the scope of the claims of the embodiments of the present application.

Claims (10)

1. A method for establishing a long connection communication link, the method being applied to a client, the method comprising:
creating a plurality of long connections; the long connection is used for connecting the client and the instance running on the server;
for each long connection, inquiring the instance of the long connection to obtain the instance address;
classifying the long connection according to the instance address to obtain a plurality of first groups, wherein the long connection of each first group can be connected with the same instance;
obtaining relation data between the long connection and the instance according to the first quantity of the long connection in the first group and a first preset threshold value;
and establishing a long connection communication link of the instance according to the relation data.
2. The method for establishing a long connection communication link according to claim 1, wherein said classifying the long connection according to the instance address to obtain a plurality of first packets comprises:
Comparing the instance addresses of a plurality of the long connections;
and dividing the long connection with the same instance address into a group to obtain a plurality of first packets.
3. The method for establishing a long connection communication link according to claim 1, wherein the obtaining the relationship data between the long connection and the instance according to the first number of the long connection in the first packet and a first preset threshold value includes:
if the first number is greater than the first preset threshold, eliminating the long connection in the first group until the first number is equal to the first preset threshold, and establishing a corresponding relation between the long connection and the instance to obtain the relation data;
if the first number is smaller than the first preset threshold, continuing to create long connections until the first number is equal to the first preset threshold, and building a corresponding relation between the long connections and the examples to obtain the relation data;
and if the first quantity is equal to the first preset threshold value, establishing a corresponding relation between the long connection and the instance to obtain the relation data.
4. The long-connection communication link establishment method according to claim 1, wherein after said obtaining the relationship data between the long connection and the instance from the first number of the long connection in the first packet and a first preset threshold value, the long-connection communication link establishment method further comprises:
Taking the long connection as an initial long connection, and storing the initial long connection into a preset connection pool;
inquiring the instance of the initial long connection for each initial long connection in the connection pool at preset updating time to obtain a first instance address;
classifying the initial long connection according to the first instance address to obtain a plurality of second groups, wherein the initial long connection of each second group can be connected with the same instance;
and updating the connection pool according to the second number of the initial long connection and a second preset threshold value in the second group.
5. The method of long connection communication link establishment according to claim 4, wherein said updating said connection pool based on a second number of said initial long connections in said second packet and a second preset threshold comprises:
if the second number is greater than the second preset threshold, rejecting the initial long connection from the second packet to update the connection pool;
and if the second number is smaller than the second preset threshold value, continuing to create the initial long connection so as to update the connection pool.
6. The long-connection communication link establishment method according to any one of claims 1 to 5, characterized in that, after the long-connection communication link of the instance is established according to the relationship data, the long-connection communication link establishment method further comprises:
Creating a plurality of short connections; the short connection is used for connecting the client and the instance;
querying the instance of the short connection for each short connection to obtain a second instance address;
and detecting survival of the instance according to the second instance address.
7. The long-connection communication link establishment method according to any one of claims 1 to 5, characterized in that, after the long-connection communication link of the instance is established according to the relationship data, the long-connection communication link establishment method further comprises:
acquiring an access request;
the access request is sent to the instance over the long connection communication link.
8. A long connection communication link establishment apparatus for use with a client, said apparatus comprising:
a creation module for creating a plurality of long connections; the long connection is used for connecting the client and the instance running on the server;
the query module is used for querying the instance of the long connection for each long connection to obtain the instance address;
the classification module is used for classifying the long connection according to the instance address to obtain a plurality of first groups, wherein the long connection of each first group can be connected with the same instance;
The judging module is used for obtaining the relation data between the long connection and the instance according to the first quantity of the long connection in the first group and a first preset threshold value;
and the communication link establishment module is used for establishing a long connection communication link of the instance according to the relation data.
9. An electronic device, characterized in that the electronic device comprises a memory storing a computer program and a processor implementing the long connection communication link establishment method according to any one of claims 1 to 7 when the computer program is executed by the processor.
10. A computer readable storage medium storing a computer program, characterized in that the computer program, when executed by a processor, implements the long connection communication link establishment method of any one of claims 1 to 7.
CN202310840637.0A 2023-07-07 2023-07-07 Long connection communication link establishment method and device, electronic equipment and storage medium Pending CN116743836A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310840637.0A CN116743836A (en) 2023-07-07 2023-07-07 Long connection communication link establishment method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310840637.0A CN116743836A (en) 2023-07-07 2023-07-07 Long connection communication link establishment method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116743836A true CN116743836A (en) 2023-09-12

Family

ID=87904524

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310840637.0A Pending CN116743836A (en) 2023-07-07 2023-07-07 Long connection communication link establishment method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116743836A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117294534A (en) * 2023-11-24 2023-12-26 湖南快乐阳光互动娱乐传媒有限公司 Network agent identification method, device and system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117294534A (en) * 2023-11-24 2023-12-26 湖南快乐阳光互动娱乐传媒有限公司 Network agent identification method, device and system
CN117294534B (en) * 2023-11-24 2024-01-30 湖南快乐阳光互动娱乐传媒有限公司 Network agent identification method, device and system

Similar Documents

Publication Publication Date Title
CN109327509B (en) Low-coupling distributed streaming computing system of master/slave architecture
WO2020177533A1 (en) Electronic invoice identifier allocation method, and electronic ticket generating method, device and system
CN109618002B (en) Micro-service gateway optimization method, device and storage medium
US10367852B2 (en) Multiplexed demand signaled distributed messaging
US10659371B1 (en) Managing throttling limits in a distributed system
JP4616159B2 (en) Cluster system, load balancer, node transfer method, and node transfer program
CN110311983B (en) Service request processing method, device and system, electronic equipment and storage medium
CN103220354A (en) Method for achieving load balancing of server cluster
CN114024972B (en) Long connection communication method, system, device, equipment and storage medium
CN105721552B (en) A kind of method and DNS system for realizing dynamic load leveling based on DNS
US20040098499A1 (en) Load balancing system
CN109951537A (en) A kind of load balance distribution method towards block chain
CN112953982B (en) Service processing method, service configuration method and related device
CN116743836A (en) Long connection communication link establishment method and device, electronic equipment and storage medium
CN112468589A (en) Data distribution method and device, computer equipment and storage medium
CN114172966A (en) Service calling method and device and service processing method and device under unitized architecture
CN103347087A (en) Structuring P2P and UDDI service registering and searching method and system
CN114268667B (en) Data forwarding method, device, computer equipment and storage medium
CN113259415A (en) Network message processing method and device and network server
CN111711675B (en) Solution for concurrent message transmission in local area network
CN111427703A (en) Industrial data real-time display method and system
CN111858585A (en) Block chain strategy processing device, computer readable storage medium and terminal equipment
CN112799849B (en) Data processing method, device, equipment and storage medium
CN108696598B (en) Method and device for transparently transmitting message received by stateless service through long connection under micro-service architecture
CN106230657A (en) A kind of data push method and supplying system thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination