Access control method, server and client
By sending an offline notification to the client from the server, including the node identifier, the problem of load imbalance in long-connection business scenarios is solved, and the rational allocation of server resources and stability improvement are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-12
- Publication Date
- 2026-04-10
AI Technical Summary
Existing server load balancing solutions cannot effectively solve the load balancing problem in long-term translation and long-connection business scenarios, resulting in uneven node load and insufficient resource utilization after restart.
The server determines whether preset conditions are met, such as an error or an impending restart, and sends an offline notification to the client, including the node identifier. After disconnecting, the client reconnects and uses the node identifier to select load balancing rules to re-establish the connection.
This avoids load imbalance, improves the overall performance and stability of the server, and ensures the reasonable allocation and utilization of resources.
Smart Images

Figure CN115396444B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to an access control method, a server and a client. BACKGROUND
[0002] Load balancing refers to balancing the load (work tasks) and distributing the load to multiple nodes for execution, thereby cooperatively completing the work tasks, expanding the bandwidth of servers and network devices, strengthening the network data processing capability, increasing the throughput, and improving the availability and flexibility of the network.
[0003] Conventional server load balancing schemes mainly perform load balancing operations on short links, and these load balancing schemes cannot solve the load balancing problem in the long connection business scenario of long-time translation. After restarting or redeploying the service, the original long connection requests under the node will be transferred to other nodes. The other nodes already have many long connection requests, and the transferred long connection requests will cause high load. The load of the restarted node is very low and needs a long time to balance, resulting in insufficient utilization of server resources. SUMMARY
[0004] The present application provides an access control method, a server and a client, and the technical solutions adopted by the embodiments of the present application are as follows:
[0005] An access control method applied to a server, comprising:
[0006] determining whether the server meets a preset condition;
[0007] if the server meets the preset condition, sending a logout notification to a client; wherein the client and a first node of the server establish a first connection, and the client and the first node can transmit data multiple times through the first connection; the logout notification comprises a node identifier of the first node, and the node identifier is used for reestablishing the first connection between the client and the first node after the first connection is disconnected.
[0008] In some embodiments, the sending of the logout notification to the client in the case where the server meets the preset condition comprises:
[0009] sending the logout notification to the client through a process running on the server in the case where the server meets the preset condition.
[0010] In some embodiments, the sending of the logout notification to the client in the case where the server meets the preset condition comprises:
[0011] In a case where it is determined that the service end is abnormal, one or more processes running on the first node are abnormal, the first node is down, or the first node is about to restart, the offline notification is sent to the client.
[0012] In some embodiments, the method further comprises:
[0013] receiving a first access request sent by the client; wherein the first access request contains the node identifier;
[0014] controlling the first node and the client to re-establish the first connection based on the first access request.
[0015] In some embodiments, the receiving the first access request sent by the client comprises:
[0016] receiving the first access request sent by the client based on first address information; wherein the first address information contains second address information and the node identifier, the second address information is used for the client to send a second access request, and the second access request is used to request the service end to select a node based on a load balancing rule to build a connection with the client.
[0017] In some embodiments, the method further comprises:
[0018] receiving a second access request sent by the client, wherein the second access request does not contain the node identifier;
[0019] selecting a node from a plurality of nodes of the service end to build a connection with the client based on a load balancing rule.
[0020] In some embodiments, the selecting a node from a plurality of nodes of the service end to build a connection with the client based on a load balancing rule comprises:
[0021] determining the system idle rate of a plurality of nodes;
[0022] selecting a node with the largest system idle rate from a plurality of nodes to build a connection with the client.
[0023] An access control method applied to a client, comprising:
[0024] obtaining an offline notification sent by a service end; wherein a first connection is established between the client and a first node of the service end, and the client and the first node can transmit data multiple times through the first connection; and the offline notification contains a node identifier of the first node;
[0025] After the first connection is disconnected, a first access request containing the node identifier is sent to the server to request the first connection to be re-established with the first node.
[0026] A server comprises:
[0027] A first determining module is configured to determine whether the server meets a preset condition.
[0028] A first sending module is configured to send an offline notification to a client when the server meets the preset condition, wherein the client and a first node of the server have established a first connection, and the client and the first node can transmit data multiple times through the first connection; the offline notification contains a node identifier of the first node, and the node identifier is used to re-establish the first connection between the client and the first node after the first connection is disconnected.
[0029] A client comprises:
[0030] A second receiving module is configured to obtain an offline notification sent by a server, wherein the client and a first node of the server have established a first connection, and the client and the first node can transmit data multiple times through the first connection; the offline notification contains a node identifier of the first node.
[0031] A second sending module is configured to send a first access request containing the node identifier to the server to request the first connection to be re-established with the first node after the first connection is disconnected.
[0032] The access control method of the embodiments of the present application determines whether the first connection between the client and the first node has been disconnected or will be disconnected by determining whether the server meets a preset condition, and if the server meets the preset condition, it indicates that the first connection between the client and the first node has been disconnected or will be disconnected, and an offline notification containing the node identifier of the first node is sent to the client. If the client needs to establish the first connection with the server within a preset time, an access request is sent to the server based on the node identifier, and the server can re-establish the first connection between the client and the first node based on the node identifier. In this way, the phenomenon of uneven load distribution of each node of the server caused by the load of the first node being distributed to other nodes can be avoided, which is beneficial to improving the overall performance and stability of the server. BRIEF DESCRIPTION OF DRAWINGS
[0033] Figure 1 A flowchart of the access control method of the first embodiment of the present application;
[0034] Figure 2Flow chart of the access control method of the second embodiment of the present application;
[0035] Figure 3 Flow chart of step S220 of the access control method of the second embodiment of the present application;
[0036] Figure 4 Flow chart of the access control method of the third embodiment of the present application;
[0037] Figure 5 Structural block diagram of the server of the fourth embodiment of the present application;
[0038] Figure 6 Structural block diagram of the client of the fifth embodiment of the present application. DETAILED DESCRIPTION
[0039] Various aspects and features of the present application are described herein with reference to the drawings.
[0040] It is to be understood that various alterations, modifications and improvements can be made to the embodiments of the present application herein disclosed. Accordingly, it is intended to encompass all such alterations, modifications and improvements as fall within the scope and spirit of the present application.
[0041] The accompanying drawings incorporated in and forming a part of the specification, illustrate embodiments of the present application and, together with the general description of the application given above, and the detailed description of the embodiments given below, serve to explain the principles of the present application.
[0042] These and other characteristics, features and advantages of the present application will become apparent from the following detailed description, taken in conjunction with the accompanying drawings, which illustrate, by way of non-limiting examples, the principles of the application.
[0043] It is also to be understood that even though a number of specific embodiments of the present application have been described herein, these are not the only possible embodiments of the present application. Numerous modifications could be made by those skilled in the art, some of which have been discussed already. None of the foregoing embodiments are intended to limit the present application to only those embodiments. The scope of the present application is to be determined by the following claims.
[0044] The above and other aspects, features and advantages of the present application will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings, in which:
[0045] The specific embodiments of the application will be described with reference to the drawings; however, it is to be understood that the application is merely an example of the application and can be implemented in various ways. Well-known and / or repeated functions and structures are not described in detail to avoid unnecessary or redundant details that would obscure the application. Therefore, the specific structural and functional details of the application described herein are not intended to be limiting, but are merely to be used as a basis for the claims and a representative basis for teaching one skilled in the art to variously employ the application in virtually any appropriate detailed structure.
[0046] The specification can use phrases such as "in one embodiment", "in another embodiment", "in yet another embodiment", or "in other embodiments", which can refer to one or more of the same or different embodiments according to the application.
[0047] The first embodiment of the application provides an access control method, which is applied to a service end. The service end can be hardware or software. When the service end is hardware, it can be implemented as a distributed server cluster composed of multiple servers, or as a single server. When the service end is software, it can be implemented as multiple software or software modules (for example, used to provide distributed services), or as a single software or software module, which is not specifically limited here.
[0048] Figure 1 The flowchart of the access control method of the first embodiment of the application is shown in Figure 1 The access control method of the embodiment of the application can specifically include the following steps.
[0049] S110, determining whether the service end meets a preset condition.
[0050] Optionally, the service end can be provided with multiple nodes, which are actually service nodes used to provide services to clients. After obtaining an access request, the service end usually distributes the access request to each node to respond to the client access request through the node. The node can be formed by a physical device, or by a virtual device such as a virtual machine or a container. If the client and the node need to transmit data multiple times within a short time, a first connection, i.e., a long connection, can be established between the client and the node.
[0051] Optionally, the first node can be any one of the multiple nodes. If the first connection is established between the first node and the client, the client and the first node can transmit data based on the first connection. The preset condition can be used to represent that the first connection between the client and the first node has been disconnected or is about to be disconnected. In specific implementation, the preset condition can include one or more conditions. In the case of triggering any one condition, it can be considered that the service end meets the preset condition.
[0052] Optionally, it can be determined whether the server has an exception, and if it is determined that the server has an exception, it can be determined that the server meets the preset condition. For example, it can be determined whether the hardware of the server has an exception, whether the software of the server has an exception, whether the network connection of the server has an exception, and the like. For another example, in the case that the server itself is provided with a monitoring system for monitoring the running state, it is determined whether the monitoring system issues an abnormal alarm, and in the case that the monitoring system issues an abnormal alarm, it is determined that the server is about to have an exception or has already had an exception, and it is determined that the server meets the preset condition.
[0053] It should be noted that the exception of the server can include a sudden abnormal behavior, and can also include a non-sudden abnormal behavior such as a regular operation and maintenance operation, system update, and the like. For example, based on an operation and maintenance plan or an administrator instruction, it can be determined that the server is about to perform a system update and can cause the first connection to be disconnected, and then it can be determined that the server is about to have an exception, and further it is determined that the server meets the preset condition.
[0054] Optionally, it can also be determined whether the first node has an exception. Optionally, it can be determined that one or more of the following behaviors exist: one or more processes running on the first node are abnormal, the first node is down, and the first node is about to restart, and if one or more of the above behaviors exist, it can be determined that the first node has an exception, and it is determined that the server meets the preset condition. For example, if it is determined that one or more processes related to the first connection in the first node are running abnormally, it can be determined that the server meets the preset condition. For another example, through a monitoring system, it is determined that the first node has a running failure and is down, and then it can be determined that the server meets the preset condition. For another example, based on an administrator instruction or an operation and maintenance plan, it is determined that the first node needs to perform a system update and needs to be restarted, which will cause the first connection to be disconnected, and then it can be determined that the server meets the preset condition.
[0055] S120, if the server meets the preset condition, sending an offline notification to the client.
[0056] Optionally, the offline notification includes a node identifier of the first node, and the node identifier is used for the client to reestablish the first connection with the first node after the first connection is disconnected. Optionally, the offline notification can be used to instruct the client to send an access request to the server based on the node identifier if the first connection needs to be reestablished with the server within a preset time, so that the server reestablishes the first connection between the client and the first node based on the node identifier.
[0057] Optionally, the node identifier can be used to uniquely identify the identity of the first node. The node identifier can include various information capable of uniquely identifying the first node, such as a node number, address information, device code, etc. For example, the node code of the first node can be "a001", and "a001" can be sent to the client as the node identifier in the case where it is determined that the server meets the preset condition.
[0058] The access control method of the embodiments of the present application determines whether the first connection between the client and the first node has been disconnected or is about to be disconnected by determining whether the server meets the preset condition. If the server meets the preset condition, it indicates that the first connection between the client and the first node has been disconnected or is about to be disconnected, and a logout notification including the node identifier of the first node is sent to the client. If the client needs to establish a first connection with the server within a preset time, an access request is sent to the server based on the node identifier, and the server can reestablish the first connection between the client and the first node based on the node identifier. In this way, it can be avoided that the load of the first node is distributed to other nodes, resulting in the phenomenon of uneven load distribution of each node of the server, which is beneficial to improve the overall performance and stability of the server.
[0059] In some embodiments, step 120, in the case where the server meets the preset condition, a logout notification is sent to the client, which can specifically include the following steps.
[0060] In the case where the server meets the preset condition, a process running on the server sends a logout notification to the client.
[0061] Optionally, a daemon process can be run on the server to monitor the overall running state of the server or the running state of one or more nodes. In the case where the preset condition is not triggered, the daemon process is usually in a background running state. In the case where the server meets the preset condition, the daemon process can send a logout notification to the client. In this way, the access control method of the embodiments of the present application can be implemented while minimizing the impact on the normal operation of the server.
[0062] Optionally, the process can run on, for example, a load balancing module of the server, or on each node. For example, a daemon process can be run on the load balancing module to monitor each node. Alternatively, a daemon process can be run on each node when it is started, so as to monitor the running state of the node itself through the daemon process of the node itself.
[0063] In some embodiments, the method further includes the following steps.
[0064] S130, receiving the first access request sent by the client; wherein the first access request contains the node identifier.
[0065] S140, based on the first access request, controlling the first node and the client to reestablish the first connection.
[0066] Optionally, the offline notification can be used to instruct the client to switch the access mode from the regular access mode to the offline reconnection mode, and keep the offline reconnection mode for a preset time. In the regular access mode, the client can send an access request without containing the node identifier, and the server selects a node to respond to the access request of the client based on a preset rule upon receiving the access request. In the offline reconnection mode, if the client needs the server to establish the first connection, the client sends a first access request containing the node identifier to the server. Upon receiving the first access request, the server calls the corresponding first node based on the node identifier, and controls the first node and the client to reestablish the first connection. This provides a feasible implementation for the client and the first node to reestablish the long connection, so that the client can successfully reestablish the long connection with the originally connected first node after the long connection is disconnected, avoiding the load on the first node being distributed to other nodes, and further avoiding the phenomenon of load imbalance of the server.
[0067] In some embodiments, the step S130 of receiving the first access request sent by the client can include the following steps.
[0068] The first access request sent by the client based on the first address information is received; wherein the first address information contains the second address information and the node identifier, the second address information is used for the client to send a second access request, and the second access request is used to request the server to select a node to build a connection with the client based on a load balancing rule.
[0069] Optionally, in the regular access mode, the client can send a second access request to the server based on the second address information to request the server to provide services. Upon receiving the second access request, the server selects a node from multiple nodes of the server to establish a connection with the client based on a load balancing rule. The second address information can include, for example, a URL address, an IP address, a port number, and other address information that can uniquely identify the server and the service type.
[0070] Optionally, in the offline reconnection mode, the client can form the first address information based on the second address information and the node identifier. For example, the node identifier can be added in front of, in the middle of, or behind the URL address to form the first address information. Based on the first address information, the first access request can be sent to the server. For example, the second address information can be "https: / / www.abcd.com / event", the node identifier can be "a001", and the first address information can be "https: / / www.abcd.com / event / a001". This method does not need to modify the protocol, is simple to operate, and is easy to implement.
[0071] In some embodiments, the method can further include the following steps.
[0072] S150, receiving the second access request sent by the client, wherein the second access request does not contain the node identifier.
[0073] S160, based on the load balancing rule, selecting a node from the plurality of nodes of the server to build a connection with the client.
[0074] Optionally, in the normal state, the client can be configured in the normal access mode. When the client accesses the server for the first time, the client can send a second access request containing no node identifier to the server based on the second address information. For example, the client can directly access the server based on the URL address "https: / / www.abcd.com / event". Alternatively, after the client switches to the offline reconnection mode, if the client does not access the server within a preset time or does not request the server to pre-establish a long connection, the client can automatically switch the access mode back to the normal access mode. Then, if the client requests to access the server, the client can send a second access request to the server based on the second address information.
[0075] Optionally, after receiving the second access request, if the server does not identify the node identifier in the second access request, the server can select a node from the plurality of nodes based on the load balancing rule to build a connection with the client. For example, the server can be provided with a load balancing module, which can be used for load distribution. After receiving the access request, the server detects whether the access request contains a node identifier in a preset format through the load balancing module. If the access request contains the node identifier, the server controls the corresponding node to re-build a connection with the client based on the node identifier. If the access request does not contain the node identifier, the server re-selects a node from the plurality of nodes based on the load balancing rule to respond to the access request of the client and provide services for the client.
[0076] In some embodiments, the step S160 of selecting a node from the plurality of nodes of the service end to establish a connection with the client based on the load balancing rule can comprise the following steps.
[0077] S161, determining system idle rates of the plurality of nodes.
[0078] S162, selecting a node with the largest system idle rate from the plurality of nodes to establish a connection with the client.
[0079] Optionally, the system idle rate is used to represent idle processing capacity of the node. The system idle rate can comprise an idle usage rate of a processor or an idle rate of a memory. The system idle rate can also comprise a ratio of a difference between a connection upper limit value of the node and a current connection number of the node to the connection upper limit value of the node. Alternatively, the system idle rate can also comprise a ratio of a difference between a process upper limit value of the node and a current process number of the node to the process upper limit value of the node.
[0080] Optionally, the load balancing module can detect the system idle rate of each node. For example, the load balancing module can periodically poll each node. For another example, when the load balancing module assigns an access request to each node, the load balancing module can record the connection number of each node and determine the system idle rate of each node based on the connection number.
[0081] Optionally, even after the system idle rate of each node has been determined, the load balancing module can still select a node with the largest system idle rate from the plurality of nodes to establish a connection with the client, so as to achieve load balancing of the service end. For example, the load balancing module can sort the nodes based on the system idle rate from large to small, and select one or more nodes in front of the sorted nodes to establish a connection with the client. In this way, better load balancing effect can be achieved.
[0082] The second embodiment of the present application further provides an access control method, which is applied to a client. The client can be hardware or software. When the client is hardware, it can be various electronic devices capable of establishing a long connection with a service end, including but not limited to a smart phone, a tablet computer, a desktop computer, and the like. When the client is software, it can be installed in the above-mentioned electronic devices. The client can be implemented as a plurality of software or software modules, or a single software or software module, which is not limited here.
[0083] Figure 2 FIG. 2 is a flowchart of the access control method according to the second embodiment of the present application. As shown in FIG. 2, the access control method according to the second embodiment of the present application can comprise the following steps. Figure 2
[0084] S210, obtaining offline notification sent by a server. A first connection is established between the client and a first node of the server, and the client and the first node can transmit data multiple times through the first connection. The offline notification includes a node identifier of the first node.
[0085] Optionally, the server can set multiple nodes, and a node is actually a service node for providing services to the client. After obtaining an access request, the server usually distributes the access request to each node to respond to the access request of the client through the node. The node can be formed by a physical device or by a virtual device such as a virtual machine or a container. If the client and the node need to transmit data multiple times in a short time, a first connection, that is, a long connection, can be established between the client and the node. The first node can be any one of the multiple nodes, and if the first connection is established between the first node and the client, the client and the first node can transmit data multiple times based on the first connection.
[0086] Optionally, the server can send offline notification to the client when it is determined that the server meets a preset condition. The preset condition can be used to represent that the first connection between the client and the first node has been disconnected or will be disconnected. Optionally, the offline notification can be used to instruct the client to send an access request to the server based on the node identifier if the first connection needs to be re-established with the server within a preset time, so that the server re-establishes the first connection between the client and the first node based on the node identifier.
[0087] Optionally, the node identifier can be used to uniquely identify the identity of the first node. The node identifier can include various information capable of uniquely identifying the first node, such as node number, address information, device code, etc. For example, the node code of the first node can be "a001", and "a001" can be sent to the client as the node identifier when it is determined that the server meets the preset condition.
[0088] S220, after the first connection is disconnected, sending a first access request including the node identifier to the server to request re-establishment of the first connection with the first node.
[0089] Optionally, the client obtains offline notification, and if the first connection needs to be re-established with the server within a preset time, the client can send a first access request to the server based on the node identifier in the offline notification. The first access request can include the node identifier to inform the server of the identity of the node that establishes the first connection with the client before the first connection is disconnected.
[0090] Optionally, the server receives the first access request, and if it is identified that the node identifier is contained in the first access request, the corresponding first node is called based on the node identifier, and the first node is controlled to reestablish the first connection with the client.
[0091] The access control method of the embodiment of the application, the client can establish a first connection with a first node in the server, if the first connection has been disconnected or is about to be disconnected, the client can obtain the offline notification sent by the server, and the offline notification contains the node identifier of the first node. After the first connection is disconnected, if the client needs to reestablish the first connection with the server, the first access request containing the node identifier can be sent to the server, so that the server can control the first node to reestablish the first connection with the client based on the node identifier. In this way, the phenomenon of load imbalance of each node of the server caused by the load of the first node being distributed to other nodes can be avoided, and the overall performance and stability of the server are improved.
[0092] Cooperation Figure 3 As shown in some embodiments, the step S220 of sending the first access request containing the node identifier to the server to request to reestablish the first connection with the first node can include the following steps.
[0093] Based on the offline notification, the state information of the client itself is modified to switch the access mode of the client to an offline reconnection mode.
[0094] In the offline reconnection mode, the first access request is sent to the server based on the node identifier to request to reestablish the first connection with the first node.
[0095] Optionally, the offline notification can be used to indicate that the client switches the access mode from the regular access mode to the offline reconnection mode, and the offline reconnection mode is maintained for a preset time. In the regular access mode, the client can send an access request without containing the node identifier, and the server selects a node to respond to the access request of the client based on a preset rule upon receiving the access request. In the offline reconnection mode, if the client needs the server to establish the first connection, the first access request containing the node identifier is sent to the server. The server receives the first access request, and if it is identified that the node identifier is contained in the first access request, the corresponding first node is called based on the node identifier, and the first node is controlled to reestablish the first connection with the client. A feasible implementation is provided for the client and the first node to reestablish the long connection, so that after the long connection is disconnected, the client can successfully reestablish the long connection with the original first node, the load on the first node is avoided to be distributed to other nodes, and the phenomenon of load imbalance of the server is avoided.
[0096] Cooperation Figure 3In some embodiments, in the offline reconnection mode, sending a first access request to the server based on the node identifier to request the first node after restart to rebuild a long connection can include the following steps.
[0097] In the offline reconnection mode, determining whether the first connection needs to be rebuilt with the server.
[0098] If yes, sending a first access request to the server based on the node identifier to request the first node to rebuild the first connection.
[0099] Optionally, the client can determine whether the first connection needs to be rebuilt with the server based on the current operation. For example, based on the current business type of the client, it is determined whether the data needs to be interacted with the server based on the long connection. If yes, it is determined that the first connection needs to be rebuilt with the server. If no, it is determined that the first connection does not need to be rebuilt with the server.
[0100] Optionally, the client can also determine whether the first access request has been sent to the server after receiving the offline notification based on the historical record. If yes, it is determined that the first access request does not need to be repeatedly sent to the server. If no, it is determined that the first connection needs to be rebuilt with the server and the first access request needs to be sent to the server.
[0101] In some embodiments, step S220, sending a first access request containing the node identifier to the server to request the first node to rebuild the first connection can include the following steps.
[0102] Generating first address information based on the node identifier and second address information; wherein the second address information is used to send a second access request, and the second access request is used to request the server to select a node based on a load balancing rule to build a connection with the client.
[0103] Based on the first address information, sending the first access request containing the node identifier to the server.
[0104] Optionally, in the normal access mode, the client can send a second access request to the server based on the second address information to request the server to provide services. When the server receives the second access request, it selects a node from multiple nodes of the server to establish a connection with the client based on a load balancing rule. The second address information can include, for example, a URL address, an IP address, a port number, and other address information that can uniquely identify the server and the service type.
[0105] Optionally, in the offline-reconnection mode, the client can form the first address information based on the second address information and the node identifier. For example, the node identifier can be added in front of, in the middle of, or behind the URL address to form the first address information. Based on the first address information, the first access request can be sent to the server. For example, the second address information can be "https: / / www.abcd.com / event", the node identifier can be "a001", and the first address information can be "https: / / www.abcd.com / event / a001". This method does not need to modify the protocol, is simple to operate, and is easy to implement.
[0106] In some embodiments, the method can further include the following steps.
[0107] S230, in the case that the client and the first node after the restart rebuild the long connection, or after a preset time after the offline notification is obtained, the state information of the client itself is modified to switch the access mode of the client to the regular access mode.
[0108] In the regular access mode, the client can send a second access request that does not contain a node identifier to the server, and the second access request is used to request the server to select a node based on a load balancing rule to build a connection with the client.
[0109] Optionally, in the regular state, the client can be configured to be in the regular access mode. When the client accesses the server for the first time, the client can send a second access request that does not contain a node identifier to the server based on the second address information. For example, the client can directly access the server based on the URL address "https: / / www.abcd.com / event". Alternatively, after the client switches to the offline-reconnection mode, if the client does not access the server or does not request the server to pre-establish a long connection within a preset time, the client can automatically switch the access mode back to the regular access mode. Subsequently, if the client requests to access the server, the client can send a second access request to the server based on the second address information.
[0110] Optionally, after receiving the second access request, if the node identifier is not identified in the second access request, the server can select a node from the plurality of nodes to build a connection with the client based on a load balancing rule. For example, the server can be provided with a load balancing module, which can be used for load distribution. After receiving the access request, the server detects whether the access request contains a node identifier in a preset format through the load balancing module. If the access request contains the node identifier, the corresponding node is controlled to rebuild a connection with the client based on the node identifier. If the access request does not contain the node identifier, a node is reselected from the plurality of nodes based on a load balancing rule to respond to the access request of the client and provide services for the client.
[0111] Referring to Figure 4 The third embodiment of the application further provides an access control method applied to a client and a server. The access control method of the third embodiment of the application can specifically include the following steps.
[0112] S301, the client sends a second access request to the server based on the second address information, wherein the second access request does not contain node information for identifying a node of the server.
[0113] Optionally, the client can have two access modes, i.e., a regular access mode and an offline reconnection mode, and the client can be in the regular access mode by default. In the regular access mode, the client can send a second access request not containing a node identifier to the server based on the second address information, and the second access request is used to request the server to select a node to build a connection with the client based on a load balancing rule. For example, the client can directly access the server based on the URL address "https: / / www.abcd.com / event".
[0114] S302, the server selects a first node from the plurality of nodes to build a first connection with the client based on a load balancing rule. The client and the first node can transmit data through the first connection multiple times.
[0115] Optionally, after receiving the second access request, if the node identifier is not identified in the second access request, the server can select a node from the plurality of nodes to build a connection with the client based on a load balancing rule. For example, the server can be provided with a load balancing module, which can be used for load distribution. After receiving the access request, the server detects whether the access request contains a node identifier in a preset format through the load balancing module. If the access request contains the node identifier, the corresponding node is controlled to rebuild a connection with the client based on the node identifier. If the access request does not contain the node identifier, a node is reselected from the plurality of nodes based on a load balancing rule to respond to the access request of the client and provide services for the client.
[0116] In S303, the server determines whether the server satisfies a preset condition.
[0117] Optionally, the preset condition can be used to represent that the first connection between the client and the first node has been disconnected or is about to be disconnected. In a specific implementation, the preset condition can include one or more conditions. In a case where any one of the conditions is triggered, it can be considered that the server satisfies the preset condition.
[0118] Optionally, it can be determined whether the server has an exception. If it is determined that the server has an exception, it can be determined that the server satisfies the preset condition. For example, it can be determined whether the hardware of the server has an exception, whether the software of the server has an exception, whether the network connection of the server has an exception, and the like. For another example, in a case where the server is provided with a monitoring system, it is determined whether the monitoring system issues an exception alarm. In a case where the monitoring system issues the exception alarm, it can be determined that the server is about to have an exception or has an exception, and it is determined that the server satisfies the preset condition.
[0119] It should be noted that the exception of the server can include a sudden abnormal behavior, and can also include a non-sudden abnormal behavior such as a regular operation and maintenance operation, system update, and the like. For example, based on an operation and maintenance plan or an administrator instruction, it can be determined that the server is about to perform system update and can cause the first connection to be disconnected, it can be determined that the server is about to have an exception, and it is determined that the server satisfies the preset condition.
[0120] Optionally, it is determined whether the first node is abnormal. Optionally, it is determined whether one or more of the following behaviors exist: one or more processes running on the first node are abnormal, the first node is down, and the first node is about to restart. If one or more of the above behaviors exist, it is determined that the first node is abnormal, and it is determined that the server satisfies the preset condition. For example, if it is determined that one or more processes related to the first connection in the first node are abnormal, it is determined that the server satisfies the preset condition. For another example, if it is determined by the monitoring system that the first node has a running failure and is down, it is determined that the server satisfies the preset condition. For another example, based on an administrator instruction or an operation and maintenance plan, it is determined that the first node needs to be updated and needs to be restarted, which will cause the first connection to be disconnected, and it is determined that the server satisfies the preset condition.
[0121] S304, if the server determines that it satisfies the preset condition, sending a logout notification to the client; wherein the logout notification comprises a node identifier of the first node.
[0122] Optionally, the logout notification comprises the node identifier of the first node, and the node identifier is used for the client to reestablish the first connection with the first node after the first connection is disconnected. Optionally, the logout notification can be used to instruct the client to send an access request to the server based on the node identifier if the first connection needs to be reestablished with the server within a preset time, so that the server reestablishes the first connection between the client and the first node based on the node identifier.
[0123] Optionally, the node identifier can be used to uniquely identify the identity of the first node. The node identifier can comprise various information capable of uniquely identifying the first node, such as a node number, address information, a device code, etc. For example, the node code of the first node can be "a001", and "a001" can be sent to the client as the node identifier in the case where it is determined that the server satisfies the preset condition.
[0124] S305, the client modifies its own state information based on the logout notification, so as to switch the access mode of the client to an offline reconnection mode.
[0125] Optionally, the logout notification can be used to instruct the client to switch the access mode from a regular access mode to an offline reconnection mode, and to keep the offline reconnection mode within a preset time. In the regular access mode, the client can send an access request without the node identifier, and the server selects a node to respond to the access request of the client based on a preset rule in the case where the access request is received. In the offline reconnection mode, the client sends a first access request containing the node identifier to the server if the first connection needs to be established.
[0126] S306, the client sends a first access request to the server based on the node identifier in the offline reconnection mode, to request the first node to reestablish the first connection.
[0127] Optionally, the client in the offline reconnection mode can determine whether it needs to reestablish the first connection with the server. If yes, the client sends a first access request to the server based on the node identifier, to request the first node to reestablish the first connection. For example, the client can determine whether it needs to reestablish the first connection with the server based on the current operation. For example, the client can determine whether it needs to interact with the server based on the long connection based on the current service type of the client. If yes, it is determined that the client needs to reestablish the first connection with the server, and if no, it is determined that the client does not need to reestablish the first connection with the server. For another example, the client can also determine whether it has sent a first access request to the server after receiving the offline notification based on the historical record. If yes, it is determined that the client does not need to repeatedly send a first access request to the server, and if no, it is determined that the client needs to reestablish the first connection with the server and send a first access request to the server.
[0128] S307, the server controls the first node to reestablish the first connection with the client based on the first access request.
[0129] Optionally, the server receives the first access request, and if it identifies that the first access request contains the node identifier, it calls the corresponding first node based on the node identifier and controls the first node to reestablish the first connection with the client.
[0130] S308, in the case that the client and the restarted first node reestablish the long connection, or after a preset time after obtaining the offline notification, the client modifies its own state information to switch the access mode of the client to the normal access mode.
[0131] The access control method of the embodiments of the application can be used to establish a first connection between the client and the first node of the server. If the first connection has been disconnected or is about to be disconnected, the client can obtain the offline notification sent by the server, and the offline notification contains the node identifier of the first node. After the first connection is disconnected, if the client needs to reestablish the first connection with the server, it can send a first access request containing the node identifier to the server, so that the server can control the first node to reestablish the first connection with the client based on the node identifier. In this way, it can avoid the phenomenon of uneven load distribution of the nodes of the server caused by the load of the first node being distributed to other nodes, and it is beneficial to improve the overall performance and stability of the server.
[0132] Reference Figure 5As shown, the fourth embodiment of the present application provides a server, comprising:
[0133] A first determining module 401 is configured to determine whether the server meets a preset condition.
[0134] A first sending module 402 is configured to send an offline notification to a client when the server meets the preset condition, wherein the client and a first node of the server establish a first connection, and the client and the first node can transmit data multiple times through the first connection; the offline notification contains a node identifier of the first node, and the node identifier is used for the client and the first node to reestablish the first connection after the first connection is disconnected.
[0135] In some embodiments, the first sending module 402 is specifically configured to:
[0136] send the offline notification to the client through a process running on the server when the server meets the preset condition.
[0137] In some embodiments, the first sending module 402 is specifically configured to:
[0138] send the offline notification to the client when it is determined that the server is abnormal, one or more processes running on the first node are abnormal, the first node is down, or the first node is about to restart.
[0139] In some embodiments, the server further comprises:
[0140] A first receiving module is configured to receive a first access request sent by the client, wherein the first access request contains the node identifier.
[0141] A load balancing module is configured to control the first node and the client to reestablish the first connection based on the first access request.
[0142] In some embodiments, the first receiving module is specifically configured to:
[0143] receive the first access request sent by the client based on first address information, wherein the first address information contains second address information and the node identifier, and the second address information is used for the client to send a second access request, and the second access request is used to request the server to select a node based on a load balancing rule to build a connection with the client.
[0144] In some embodiments, the server further comprises:
[0145] The first receiving module is configured to receive a second access request sent by the client, wherein the second access request does not contain the node identifier;
[0146] The load balancing module is configured to select a node from the plurality of nodes of the server based on a load balancing rule to construct a connection with the client.
[0147] In some embodiments, the load balancing module is specifically configured to:
[0148] determine system idle rates of the plurality of nodes;
[0149] select a node with the largest system idle rate from the plurality of nodes to construct a connection with the client.
[0150] Referring to Figure 6 The fifth embodiment of the present application provides a client, which comprises:
[0151] The second receiving module 501 is configured to obtain an offline notification sent by a server; wherein a first connection is established between the client and a first node of the server, and the client and the first node can transmit data multiple times through the first connection; and the offline notification contains a node identifier of the first node.
[0152] The second sending module 502 is configured to send a first access request containing the node identifier to the server to request to reestablish the first connection with the first node after the first connection is disconnected.
[0153] In some embodiments, the second sending module 502 is specifically configured to:
[0154] based on the offline notification, modify state information of the client itself to switch an access mode of the client to an offline reconnection mode;
[0155] In the offline reconnection mode, send a first access request to the server based on the node identifier to request to reestablish the first connection with the first node.
[0156] In some embodiments, the second sending module 502 is specifically configured to:
[0157] In the offline reconnection mode, determine whether it is necessary to reestablish the first connection with the server;
[0158] If yes, send a first access request to the server based on the node identifier to request to reestablish the first connection with the first node.
[0159] In some embodiments, the second sending module 502 is specifically configured to:
[0160] generate first address information based on the node identifier and second address information; wherein the second address information is used for sending a second access request, and the second access request is used for requesting the server to select a node based on a load balancing rule to construct a connection with the client;
[0161] send the first access request containing the node identifier to the server based on the first address information.
[0162] In some embodiments, the second sending module 502 is further configured to:
[0163] In a case where the client and the first node after restart re-construct a long connection, or after a preset time of obtaining the offline notification, modify the state information of the client itself to switch the access mode of the client to a regular access mode.
[0164] The above embodiments are only exemplary embodiments of the present application, and are not used to limit the present application, and the protection scope of the present application is defined by the claims. Those skilled in the art can make various modifications or equivalent replacements to the present application within the spirit and protection scope of the present application, and such modifications or equivalent replacements are also regarded as falling within the protection scope of the present application.
Claims
1. An access control method applied to a server, comprising: determining whether the server meets a preset condition; if the server meets the preset condition, sending a logout notification to a client; wherein the client and a first node of the server establish a first connection, and the client and the first node can transmit data multiple times through the first connection; the logout notification comprises a node identifier of the first node, which is used for the client and the first node to reestablish the first connection after the first connection is disconnected; the logout notification is used to instruct the client to switch from a normal access mode to a logout reconnection mode; in the normal access mode, the client sends an access request without a node identifier, which is used for the server to select a node to respond to the access request of the client based on a preset rule when the access request is received; in the logout reconnection mode, the client sends an access request containing a node identifier, which is used for the server to reestablish the first connection based on the node identifier when the access request is received.
2. The access control method of claim 1, wherein the server sends a logout notification to the client when the server meets the preset condition, comprising: the server sends a logout notification to the client through a process running on the server when the server meets the preset condition.
3. The access control method of claim 1, wherein the server sends a logout notification to the client when the server meets the preset condition, comprising: the server sends the logout notification to the client when the server is determined to be abnormal, one or more processes running on the first node are determined to be abnormal, the first node is determined to be down, or the first node is determined to be about to restart.
4. The access control method of claim 1, further comprising: receiving a first access request sent by the client; wherein the first access request contains the node identifier; based on the first access request, controlling the first node and the client to reestablish the first connection.
5. The access control method of claim 4, wherein the server receives a first access request sent by the client, comprising: the server receives the first access request sent by the client based on first address information; wherein the first address information contains second address information and the node identifier, and the second address information is used for the client to send a second access request, which is used to request the server to select a node based on a load balancing rule to build a connection with the client.
6. The access control method of claim 1, further comprising: receiving a second access request sent by the client, wherein the second access request does not contain the node identifier; based on a load balancing rule, selecting a node from a plurality of nodes of the server to build a connection with the client.
7. The access control method of claim 6, wherein the server selects a node from a plurality of nodes of the server to build a connection with the client based on a load balancing rule, comprising: determining the system idle rate of the plurality of nodes; Selecting a node with the largest system idle rate from the plurality of nodes to build a connection with the client.
8. An access control method applied to a client, comprising: obtaining offline notification sent by a server; wherein a first connection is established between the client and a first node of the server, and the client and the first node can transmit data multiple times through the first connection; the offline notification contains a node identifier of the first node; after the first connection is disconnected, sending a first access request containing the node identifier to the server to request reestablishing the first connection with the first node; the offline notification is used to indicate the client to switch from a regular access mode to an offline reconnection mode; in the regular access mode, the client sends an access request without containing a node identifier, which is used for the server to select a node to respond to the access request of the client based on a preset rule when receiving the access request; in the offline reconnection mode, the client sends an access request containing a node identifier, which is used for the server to reestablish the first connection based on the node identifier when receiving the access request.
9. A server, comprising: a first determination module configured to determine whether the server meets a preset condition; a first sending module configured to send offline notification to a client when the server meets the preset condition; wherein a first connection is established between the client and a first node of the server, and the client and the first node can transmit data multiple times through the first connection; the offline notification contains a node identifier of the first node, which is used for the client to reestablish the first connection with the first node after the first connection is disconnected; the offline notification is used to indicate the client to switch from a regular access mode to an offline reconnection mode; in the regular access mode, the client sends an access request without containing a node identifier, which is used for the server to select a node to respond to the access request of the client based on a preset rule when receiving the access request; in the offline reconnection mode, the client sends an access request containing a node identifier, which is used for the server to reestablish the first connection based on the node identifier when receiving the access request.
10. A client, comprising: a second receiving module configured to obtain offline notification sent by a server; wherein a first connection is established between the client and a first node of the server, and the client and the first node can transmit data multiple times through the first connection; the offline notification contains a node identifier of the first node; a second sending module configured to send a first access request containing the node identifier to the server to request reestablishing the first connection with the first node after the first connection is disconnected; the offline notification is used to indicate the client to switch from a regular access mode to an offline reconnection mode; in the regular access mode, the client sends an access request without containing a node identifier, which is used for the server to select a node to respond to the access request of the client based on a preset rule when receiving the access request; The client sends an access request containing a node identifier in an offline reconnection mode, so that the server reestablishes the first connection based on the node identifier upon receiving the access request.
Citation Information
Patent Citations
Remote procedure call load balancing method and device and data processing system
CN112350973A
Data transmission method and system
CN113055499A
IP address management method and system in load balancing service, and controller
CN114745358A