Method and device for disconnecting server and client, electronic equipment and storage medium

By detecting the client's disconnection data on the server's worker thread and daemon thread, calculating the disconnection rate and setting the disconnection delay time, the problem of traffic peaks in the server's abnormality is solved, and the stable operation of the server and the client's reconnection is achieved. Flowability.

CN119094589APending Publication Date: 2024-12-06TOPSEE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411083519.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-08
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

The existing technology cannot effectively control the disconnection rate between the server and the client, resulting in traffic peaks occurring in abnormal situations and making it difficult to resume normal operation.

Method used

By setting worker threads and daemon threads on the server, detect the disconnection data of the target client, calculate the disconnection rate, determine the disconnection status, and set the disconnection delay time of each client according to the status to control the disconnection rate and avoid traffic Flood peak.

Benefits of technology

Effectively control the disconnection rate, avoid server instability caused by excessive disconnection rate, ensure stable operation of the server, and reduce the cost and complexity of client reconnection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119094589A_ABST
    Figure CN119094589A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a disconnection method and device of a server and a client, electronic equipment and a storage medium, and belongs to the technical field of computer networks and communication. The method is applied to a server side and comprises the steps that a working thread and a daemon thread corresponding to the server side are determined, and the daemon thread is used for detecting disconnection data of a plurality of target client sides connected with the server side; receiving a target disconnection signal based on the working thread, wherein the target disconnection signal is used for indicating disconnection between at least one target client and the server; obtaining target disconnection rates of the plurality of target clients based on the target disconnection signal and the daemon thread; determining a disconnection state of the server based on the target disconnection rate; and determining disconnection delay time of each target client based on the disconnection state, so that the target client is disconnected with the server after the corresponding disconnection delay time. According to the embodiment of the invention, the disconnection rate of the server and the client can be controlled, and the flow flood peak when the server is abnormal can be effectively avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer networks and communication technologies, and in particular to a method and device for disconnecting a server from a client, an electronic device, and a storage medium. Background Art

[0002] A persistent connection is a network communication mechanism that enables continuous communication by establishing a persistent connection between the server and the client. This persistent connection architecture usually establishes connections between a limited number of servers and a large number of clients. However, when a server disconnects all clients at the same time due to an exception, all clients may try to reconnect at the same time, generating a huge amount of traffic in a short period of time, i.e., a traffic peak. Since the server cannot respond in time due to the traffic peak, it is difficult for the server to quickly return to normal.

[0003] In order to solve the problem of traffic peaks during reconnection, the existing technology usually adopts a server-side current limiting method, that is, the server is only allowed to establish connections with a certain number of clients, and clients exceeding the number limit will be refused to establish connections; or a random delay is introduced when the client reconnects, that is, after the client is disconnected from the server, the client will send a reconnection request to the server after a random delay time calculated according to the random number seed information and the random function. However, the former cannot prevent traffic peaks and will also reduce the availability of some clients; and the latter relies on the random seed information sent by the server, thereby reducing the connection efficiency. Therefore, how to adopt a method of disconnecting the server and the client that can control the disconnection rate and effectively avoid traffic peaks when the server is abnormal has become a technical problem that needs to be solved urgently. Summary of the invention

[0004] The main purpose of the embodiments of the present application is to propose a method and device for disconnecting a server from a client, an electronic device and a storage medium, which can control the disconnection rate between the server and the client and effectively avoid traffic peaks when the server is abnormal.

[0005] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a method for disconnecting a server from a client, the method being applied to the server, and the method comprising:

[0006] Determine a working thread and a daemon thread corresponding to the server, wherein the daemon thread is used to detect disconnection data of multiple target clients connected to the server;

[0007] Receiving a target disconnection signal based on the working thread, the target disconnection signal is used to indicate that at least one of the target clients is disconnected from the server;

[0008] Acquire a target disconnection rate of the plurality of target clients based on the target disconnection signal and the daemon thread, wherein the target disconnection rate is used to represent the number of the target clients disconnected from the server within a first preset unit time;

[0009] Determining a disconnection state of the server based on the target disconnection rate;

[0010] The disconnection delay time of each target client is determined based on the disconnection state, so that the target client is disconnected from the server after the corresponding disconnection delay time.

[0011] In some embodiments, determining the disconnection state of the server based on the target disconnection rate includes:

[0012] Acquire a target rate group based on a second preset unit time, the target rate group including a first target disconnection sub-rate and at least one second target disconnection sub-rate that are acquired continuously, wherein an acquisition time corresponding to the first target disconnection sub-rate is earlier than an acquisition time corresponding to the second target disconnection sub-rate;

[0013] Performing status detection on the server based on the first target disconnection sub-rate to obtain a first disconnection sub-status;

[0014] When the first disconnection sub-state is an unstable disconnection state, performing state detection on the server based on at least one of the second target disconnection sub-rates to obtain a second disconnection sub-state;

[0015] The disconnection state of the server is determined based on the second disconnection sub-state.

[0016] In some embodiments, the performing status detection on the server based on the first target disconnection sub-rate to obtain the first disconnection sub-state includes:

[0017] When the first target disconnection sub-rate is greater than a preset safety rate threshold, determining that the first disconnection sub-state is the unstable disconnection state; or,

[0018] When the first target disconnection sub-rate is less than or equal to the preset safety rate threshold, it is determined that the first disconnection sub-state is a stable disconnection state.

[0019] In some embodiments, determining the disconnection state of the server based on the second disconnection sub-state includes:

[0020] When the second disconnection sub-state is an unstable disconnection state, determining that the disconnection state of the server is an unstable disconnection state; or,

[0021] When the second disconnection sub-state is a stable disconnection state, it is determined that the disconnection state of the server is a stable disconnection state.

[0022] In some embodiments, determining the disconnection delay time of each of the target clients based on the disconnection state includes:

[0023] When the disconnection state is an unstable disconnection state, a first connection set and a second connection set are constructed based on the target client, the first connection set includes a first candidate client, and the first candidate client is used to represent the target client whose corresponding target disconnection rate is greater than the preset safety rate threshold; the second connection set includes a second candidate client, and the second candidate client is used to represent the target client whose corresponding target disconnection rate is less than or equal to the preset safety rate threshold;

[0024] Determine a disconnection delay time corresponding to the second candidate client based on the first preset time;

[0025] Client selection is performed on the first candidate clients in the first connection set to obtain a first client group, where the first client group includes a first number of the first candidate clients, and a disconnection delay time corresponding to the first client group is determined based on a preset time interval.

[0026] In some embodiments, determining the disconnection delay time corresponding to the first client group based on a preset time interval includes:

[0027] Select a random delay time from a preset time interval;

[0028] The random delay time is used as the disconnection delay time corresponding to the first client group.

[0029] In some embodiments, receiving a target disconnect signal based on the working thread includes:

[0030] Receiving a disconnection request from the target client based on the working thread, generating the target disconnection signal according to the disconnection request; or,

[0031] The working thread receives a disconnection instruction from the server, and generates the target disconnection signal according to the disconnection instruction.

[0032] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a disconnection device between a server and a client, which is applied to the server, and the device includes:

[0033] A detection module, used to determine a working thread and a daemon thread corresponding to the server, wherein the daemon thread is used to detect disconnection data of multiple target clients connected to the server;

[0034] A receiving module, configured to receive a target disconnection signal based on the working thread, wherein the target disconnection signal is used to indicate that at least one of the target clients is disconnected from the server;

[0035] an acquisition module, configured to acquire a target disconnection rate of the plurality of target clients based on the target disconnection signal and the daemon thread, wherein the target disconnection rate is used to represent the number of the target clients disconnected from the server within a first preset unit time;

[0036] A determination module, configured to determine a disconnection state of the server based on the target disconnection rate;

[0037] A delay module is used to determine a disconnection delay time of each target client based on the disconnection state, so that the target client is disconnected from the server after the corresponding disconnection delay time.

[0038] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.

[0039] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.

[0040] The present application proposes a method and device for disconnecting a server from a client, an electronic device, and a storage medium. The method determines a working thread and a daemon thread corresponding to the server, and the daemon thread is responsible for detecting the disconnection data of multiple target clients connected to the server, so that the server can perceive the abnormal disconnection of the target client in time, and take corresponding measures. Specifically, when the working thread receives a target disconnection signal indicating that at least one target client is disconnected from the server, the target disconnection rate of multiple target clients is obtained based on the target disconnection signal and the daemon thread, that is, the number of target clients disconnected from the server within the first preset unit time. Further, according to the target disconnection rate, the disconnection state of the server can be determined, and then measures can be taken for the abnormal disconnection of the target client. Further, the server determines the disconnection delay time of each target client based on the disconnection state, so that the target client is disconnected from the server after the disconnection delay time. Therefore, the present application can effectively control the disconnection rate by determining the disconnection delay time of each target client, avoid the instability of the server caused by the excessively high disconnection rate, and thus ensure the stable operation of the server. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 It is a flow chart of a method for disconnecting a server and a client provided in an embodiment of the present application;

[0042] Figure 2 yes Figure 1 Flow chart of step S104 in FIG.

[0043] Figure 3 yes Figure 1 Flow chart of step S105 in FIG.

[0044] Figure 4 yes Figure 3 Flow chart of step S303 in FIG.

[0045] Figure 5 This is another flow chart of the method for disconnecting a server and a client provided in an embodiment of the present application;

[0046] Figure 6 It is a structural schematic diagram of a disconnection device between a server and a client provided in an embodiment of the present application;

[0047] Figure 7 It is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0049] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0051] First, some nouns involved in this application are analyzed:

[0052] Server: A computer system used to provide resources, data, or services. Servers usually run on servers and are responsible for processing client requests, executing tasks, and returning results. Servers can be database servers, file servers, mail servers, web servers, etc. Servers can provide different types of services. Servers usually have high processing power, storage capacity, and network connectivity to meet the needs of a large number of clients.

[0053] Client: A computer system or device used to request server resources or services. Clients can be personal computers, mobile devices, smart TVs, etc. Clients complete user operations and needs by sending requests to the server and receiving data or services returned by the server. Client software can be a browser, application, or other user interface. The client allows users to interact with the server.

[0054] On the Internet, a long-connection architecture is often used between the server and the client to achieve long-term, efficient and stable communication. This long-connection architecture usually establishes connections between a small number of servers and a large number of clients. However, when the server is abnormal or unstable, the conventional disconnection method is to immediately disconnect all connections, and the client actively initiates a reconnection request to quickly restore communication. But if the server disconnects from all clients at the same time, the client will initiate a reconnection request at the same time, resulting in a surge in traffic and a peak traffic, which will cause the server to be unstable for a long time and difficult to recover.

[0055] In the related technical solutions, Solution 1 proposes a strategy for limiting the flow of the server: by controlling the number of clients that the server allows to establish a connection at one time, so as to avoid the client connection occupying resources. Although this method can protect the availability of some clients, it cannot fundamentally control the peak of traffic, and may cause some clients to be unable to connect during the flow limiting process. Solution 2 proposes a strategy for random delayed reconnection: after the client disconnects from the server, the delay time of reconnection is calculated according to the random number seed and the random function, and then a reconnection request is initiated after the delay time. This method can prevent the client from initiating reconnection requests at the same time, but there are some limitations: first, it is a passive protection measure that relies on the random seed sent by the server, which prolongs the connection link and increases the connection cost; second, in actual applications, the widespread popularity of clients (such as monitoring equipment, smart home devices, etc.) may make it impossible for some clients to initiate a reconnection request after the delay time as expected. Therefore, how to adopt a method for disconnecting the server and the client that can control the disconnection rate and effectively avoid the traffic peak when the server is abnormal has become a technical problem that needs to be solved urgently.

[0056] Based on this, the embodiments of the present application provide a method and device for disconnecting a server and a client, an electronic device and a storage medium, aiming to effectively control the disconnection rate, avoid server instability caused by an excessively high disconnection rate, and ensure stable operation of the server.

[0057] The disconnection method between the server and the client provided in the embodiment of the present application can be applied to the server. In some embodiments, the server can be configured as an independent physical server, or as a server cluster or distributed system composed of multiple physical servers, or as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms, but is not limited to the above forms.

[0058] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0059] Figure 1 is an optional flow chart of a method for disconnecting a server and a client provided in an embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S105.

[0060] Step S101, determining a working thread and a daemon thread corresponding to the server, wherein the daemon thread is used to detect disconnection data of multiple target clients connected to the server;

[0061] Step S102, receiving a target disconnection signal based on the working thread, where the target disconnection signal is used to indicate that at least one target client is disconnected from the server;

[0062] Step S103, obtaining a target disconnection rate of multiple target clients based on the target disconnection signal and the daemon thread, where the target disconnection rate is used to represent the number of target clients disconnected from the server within a first preset unit time;

[0063] Step S104, determining the disconnection status of the server based on the target disconnection rate;

[0064] Step S105 , determining a disconnection delay time of each target client based on the disconnection state, so that the target client is disconnected from the server after the corresponding disconnection delay time.

[0065] In the steps S101 to S105 shown in the embodiment of the present application, by determining the working thread and the daemon thread corresponding to the server, the daemon thread is responsible for detecting the disconnection data of multiple target clients connected to the server, so that the server can perceive the abnormal disconnection of the target client in time, and take corresponding measures. Specifically, when the working thread receives a target disconnection signal indicating that at least one target client is disconnected from the server, the target disconnection rate of multiple target clients is obtained based on the target disconnection signal and the daemon thread, that is, the number of target clients disconnected from the server within the first preset unit time. Further, according to the target disconnection rate, the disconnection state of the server can be determined, and then measures can be taken for the abnormal disconnection of the target client. Further, the server determines the disconnection delay time of each target client based on the disconnection state, so that the target client is disconnected from the server after the disconnection delay time. Therefore, the present application can effectively control the disconnection rate by determining the disconnection delay time of each target client, avoid the instability of the server caused by the excessively high disconnection rate, and thus ensure the stable operation of the server.

[0066] In step S101 of some embodiments, the server may be a core node of a long connection communication architecture, responsible for establishing and maintaining long connections with a large number of clients. A working thread is a thread used by the server to process client requests. A working thread may be a thread for the server to process conventional services such as client connection establishment, data transmission, disconnection, and communication. After the long connection is established, the server assigns the connection to a working thread for processing. The working thread is responsible for subsequent communications, including receiving data, processing requests, sending responses, etc. The working thread can ensure that the server can respond to the client's request in a timely manner and maintain the normal operation of the business. A daemon thread is a thread running in the background, usually used to perform some auxiliary or service tasks, such as for monitoring the disconnection processing of the server and the client. Multiple target clients may be massive clients that establish long connections with the server. Disconnection data may be data on which target clients among the multiple target clients connected to the server are to be disconnected from the server. Determining the working thread and daemon thread corresponding to the server may be starting a working thread and a daemon thread respectively when the server is started. Among them, the life cycle of the working thread and the life cycle of the daemon thread are consistent with the life cycle of the server.

[0067] It should be noted that each server can manage the life cycle of multiple target client connections, and the worker thread and the daemon thread can control the multiple target client connections by managing the server.

[0068] In step S102 of some embodiments, the target disconnection signal may be a signal indicating that at least one target client is disconnected from the server. Because the long connection is processed by the working thread, the working thread can receive the target disconnection signal. It should be noted that in a computer network, the long connection established between the server and the client is usually a persistent communication connection, which allows data to be continuously transmitted between the server and the client without frequent establishment and disconnection. The long connection will not be automatically disconnected after each data transmission, but will remain open until one party explicitly closes the connection. In a long connection, both the server and the client can perceive the state of each other. The disconnection of the long connection is divided into two cases: the server actively disconnects and the client actively disconnects. The server actively disconnects: If the server decides to close the connection, the server will directly send a disconnection instruction to the client, and the working thread can receive the target disconnection signal. The client actively disconnects: Similarly, if the client decides to close the connection, the server will usually receive a corresponding disconnection request, thereby perceiving the client's disconnection operation, and the working thread can receive the target disconnection signal. In some cases, such as network anomalies, the server may not receive the client's disconnection notification. At this time, the server needs to rely on other mechanisms, such as the heartbeat mechanism, to determine whether the client is still connected.

[0069] In some embodiments, the method of determining the target disconnection signal in step S102 may be any of the following:

[0070] Method 1: Based on the working thread, a disconnection request from the target client is received, and a target disconnection signal is generated according to the disconnection request;

[0071] Method 2: Based on the worker thread receiving the disconnection instruction from the server, a target disconnection signal is generated according to the disconnection instruction.

[0072] For method 1, the disconnect request may be a request sent by the target client to the server when the target client decides to close the persistent connection with the server, and the target disconnect signal may be a signal generated by the working thread according to the disconnect request of the target client to disconnect the server from the client.

[0073] For method 2, the disconnect instruction can be an instruction sent by the server to the working thread when the server decides to close the long connection with the target client, and the target disconnect signal can be a signal generated by the working thread according to the disconnect instruction of the server to disconnect the server and the client.

[0074] It should be noted that when the working thread receives a target disconnection signal, it sends the target disconnection signal to the daemon thread, so that the daemon thread obtains disconnection data of multiple target clients connected to the server.

[0075] In step S103 of some embodiments, the target disconnection rate may be the number of target clients disconnected from the server within a first preset unit time. The first preset unit time may be a pre-set unit time, such as 1s. The daemon thread may obtain the target disconnection rate according to the target disconnection signal. Specifically, a rate calculator is configured in the daemon thread for real-time monitoring of the target disconnection rate of the target client, and a safe disconnection rate is set to 1000 / s (the safe disconnection rate may be adjusted and configured according to the actual business), and the current server load is evaluated by setting the safe disconnection rate (such as 1000 / s). When the daemon thread receives the target disconnection signal, the daemon thread may start the rate calculator to obtain the target disconnection rate. When the target disconnection rate does not exceed the safe disconnection rate, the aforementioned conventional disconnection method will be adopted, and the server will terminate the connection with the target client in real time to ensure that it can quickly respond to and process the disconnection request; when the target disconnection rate exceeds the safe disconnection rate, the daemon thread may take corresponding measures, such as adjusting resource allocation, optimizing connection strategy or triggering a disconnection protection mechanism, to avoid server overload caused by a large number of client reconnections.

[0076] It should be noted that the rate calculator can be implemented using a counter and a timer task. The counter is a counting device, which can be physical or virtual, and is used to record the number of times the server disconnects from the target client. The timer task is executed periodically at the frequency of the first preset unit time, and its purpose is to obtain the value of the current counter, that is, the number of target clients disconnected from the server in the first preset unit time. When the first preset unit time is 1s, the rate calculator can calculate the number of target clients disconnected in the last second, that is, the target disconnection rate. Specifically, when the long connection between the server and the target client has a disconnection operation, the working thread will call the disconnection operation entry for processing. The long connection of the target client will enter a disconnection operation entry, in which the value of the counter will be automatically updated and increased by 1 for each disconnection of a target client. Then, the total value of the current counter is obtained by the timer task every second, and the target disconnection rate of the last second can be obtained. After the target disconnection rate of the last second is obtained, it is stored. Then reset the current counter, and the target disconnection rate of each second can be obtained by looping in this way.

[0077] In step S104 of some embodiments, the disconnection state of the server may include the server being in a stable disconnection state and the server being in an unstable disconnection state. When the three target disconnection rates obtained continuously all exceed the safe disconnection rate, the server is in an unstable disconnection state. When the server is in a stable disconnection state, the server can terminate the long connection with the target client in real time, and no traffic peak will be caused at this time; when the server is in an unstable disconnection state, the server will cause a traffic peak when reconnecting after disconnecting the long connection with the target client in real time.

[0078] See also Figure 2 In some embodiments, step S104 may include but is not limited to steps S201 to S204:

[0079] Step S201, acquiring a target rate group based on a second preset unit time, the target rate group including a first target disconnection sub-rate and at least one second target disconnection sub-rate that are acquired continuously, and the acquisition time corresponding to the first target disconnection sub-rate is earlier than the acquisition time corresponding to the second target disconnection sub-rate;

[0080] Step S202, performing status detection on the server based on the first target disconnection sub-rate to obtain a first disconnection sub-state;

[0081] Step S203: When the first disconnection sub-state is an unstable disconnection state, a state detection is performed on the server based on at least one second target disconnection sub-rate to obtain a second disconnection sub-state;

[0082] Step S204: determine the disconnection state of the server based on the second disconnection sub-state.

[0083] In step S201 of some embodiments, the second preset unit time may be a preset unit time for calculating a target disconnection rate, such as 3s. The second preset unit time may be the same as the first preset unit time, or may be different. The first target disconnection sub-rate is the target disconnection rate within the first second preset unit time, and the second target disconnection sub-rate is the target disconnection rate within the second second preset unit time. When the second preset unit time is 3s, the daemon thread obtains three target disconnection rates based on intervals of every 3 seconds to form a target rate group. The first target disconnection sub-rate is the target disconnection rate within the first 3s from the start of acquisition, and at least one second target disconnection sub-rate is the target disconnection rate within the second 3s and the target disconnection rate within the third 3s.

[0084] In step S202 of some embodiments, the first disconnection sub-state may include the server being in a stable disconnection state and the server being in an unstable disconnection state. The state detection may be to judge the state of the server based on the first target disconnection sub-rate and a preset safety rate threshold to determine whether the server is in a stable disconnection state or an unstable disconnection state.

[0085] In some embodiments, the process of determining the first disconnection sub-state in step S202 may include the following two situations:

[0086] Case 1: when the first target disconnection sub-rate is greater than the preset safety rate threshold, the first disconnection sub-state is determined to be an unstable disconnection state; or,

[0087] Case 2: When the first target disconnection sub-rate is less than or equal to the preset safety rate threshold, the first disconnection sub-state is determined to be a stable disconnection state.

[0088] For case 1, the preset safety rate threshold may be a safety disconnection rate preset by the daemon thread. When the second preset unit time is 1s, the preset safety rate threshold is 1000 / s, and the first target disconnection sub-rate is 1500 / s, the first disconnection sub-state is an unstable disconnection state.

[0089] For situation 2, when the second preset unit time is 1s, the preset safety rate threshold is 1000 pieces / s, and the first target disconnection sub-rate is 500 pieces / s, the first disconnection sub-state is a stable disconnection state.

[0090] It should be noted that when the first disconnection sub-state is a stable disconnection state, the server can terminate the long connection with the target client in real time, and no traffic peak will be caused at this time; when the first disconnection sub-state is an unstable disconnection state, the daemon thread will record an exception and push an alarm log to the server to prompt the server that the number of disconnections of the target client is too large at this time, and reconnection may cause a traffic peak.

[0091] In step S203 of some embodiments, the second disconnection sub-state may include the server being in a stable disconnection state and the server being in an unstable disconnection state. The state detection may be to judge the state of the server based on the second target disconnection sub-rate and the preset safety rate threshold to determine whether the server is in a stable disconnection state or an unstable disconnection state. When the second target disconnection sub-rate is greater than the preset safety rate threshold, the second disconnection sub-state is determined to be an unstable disconnection state; or, when the second target disconnection sub-rate is less than or equal to the preset safety rate threshold, the second disconnection sub-state is determined to be a stable disconnection state, at which time the server can terminate the long connection with the target client in real time without causing a traffic peak.

[0092] In step S204 of some embodiments, based on the second disconnection sub-state, it is determined whether the server is in a stable disconnection state or an unstable disconnection state.

[0093] In some embodiments, determining the disconnection status of the server in step S204 may include the following two situations:

[0094] Scenario 1: When the second disconnection sub-state is an unstable disconnection state, it is determined that the disconnection state of the server is an unstable disconnection state; or,

[0095] In case 2, when the second disconnection sub-state is a stable disconnection state, it is determined that the disconnection state of the server is a stable disconnection state.

[0096] For situation 1, when the number of the second target disconnection sub-rates is 2 and the corresponding second disconnection sub-states are all unstable disconnection states, it is determined that the disconnection state of the server is an unstable disconnection state.

[0097] For situation two, when the number of second target disconnection sub-rates is 2, and the corresponding second disconnection sub-states are a stable disconnection state and an unstable disconnection state, the disconnection state of the server is determined to be a stable disconnection state; or, when the corresponding second disconnection sub-states are all stable disconnection states, the disconnection state of the server is determined to be a stable disconnection state.

[0098] The present application determines whether the server is in an unstable disconnected state by continuously acquiring a first target disconnected sub-rate and at least one second target disconnected sub-rate: when the first disconnected sub-state is an unstable disconnected state, and at least one second disconnected sub-state is an unstable disconnected state, the disconnected state of the server is an unstable disconnected state. Through multiple state detections, the present application improves the accuracy of the judgment of the server's disconnected state and avoids possible misjudgments caused by single detection. And when the first disconnected sub-state is an unstable disconnected state, the daemon thread will record an exception so that the server can be warned in advance to take preventive measures and reduce the potential risk of abnormal server interruptions.

[0099] In step S105 of some embodiments, the disconnection delay time may be a delay time for disconnecting the target client from the server. When the server is in a stable disconnection state, the disconnection delay time is 0s, and the server can terminate the long connection with the target client in real time, and no traffic peak will be caused at this time.

[0100] See also Figure 3 In some embodiments, step S105 includes but is not limited to steps S301 to S303:

[0101] Step S301: when the disconnection state is an unstable disconnection state, a first connection set and a second connection set are constructed based on the target client, the first connection set includes a first candidate client, and the first candidate client is used to represent a target client whose corresponding target disconnection rate is greater than a preset safety rate threshold; the second connection set includes a second candidate client, and the second candidate client is used to represent a target client whose corresponding target disconnection rate is less than or equal to the preset safety rate threshold;

[0102] Step S302, determining a disconnection delay time corresponding to the second candidate client based on the first preset time;

[0103] Step S303: performing client selection on the first candidate clients in the first connection set to obtain a first client group, the first client group including a first number of first candidate clients, and determining a disconnection delay time corresponding to the first client group based on a preset time interval.

[0104] In step S301 of some embodiments, the first connection set may be a set of target clients whose corresponding target disconnection rate is greater than a preset safety rate threshold; the second connection set may be a set of target clients whose corresponding target disconnection rate is less than or equal to the preset safety rate threshold. Because the target disconnection rate is the number of target clients disconnected from the server within the first preset unit time, when the first preset unit time is 1s, the preset safety rate threshold is 1000 / s, and the target disconnection rate is 2500 / s, the second connection set may be the first 1000 target clients among the 2500 target clients disconnected from the server within 1s, and the first connection set may be the last 1500 target clients among the 2500 target clients disconnected from the server within 1s. In some embodiments, the target clients exceeding the preset safety rate threshold are stored in an abnormal connection collector, that is, the first connection set exists in the abnormal connection collector, and the abnormal connection collector may be a system component or tool in a daemon thread for storing client connections that require special processing.

[0105] In step S302 of some embodiments, the first preset time may be a preset disconnection delay time corresponding to the second candidate client, such as 0s, that is, the second candidate client in the second connection set may be disconnected from the server in real time.

[0106] In step S303 of some embodiments, the preset time interval may be a preset time interval, such as [1000, 5000] milliseconds (ms). The first client group may be a target client selected from the first candidate client. The first number may be a preset number, such as 500, 1000, etc.

[0107] See also Figure 4In some embodiments, step S303 may include but is not limited to steps S401 to S402:

[0108] Step S401, selecting a random delay time from a preset time interval;

[0109] Step S402: Using the random delay time as the disconnection delay time corresponding to the first client group.

[0110] In step S401 of some embodiments, the random delay time may be a time randomly selected from a preset time interval. When the preset time interval is [1000, 5000] ms, the random delay time may be 1000 ms, 2500 ms, 5000 ms, and so on.

[0111] In step S402 of some embodiments, the aforementioned random delay time is used as a disconnection delay time of each target client in the first client group, so that each target client is disconnected after the disconnection delay time.

[0112] It should be noted that setting a disconnection delay time for each target client can be achieved by using a timer. After the disconnection delay time of the first client group is determined, the first client group will enter a dormant state. When the disconnection delay time ends, each target client in the first client group immediately triggers a disconnection operation with the server. The dormant state refers to a state in which a long connection has been established, but there is no data transmission or communication activity for a period of time, and the long connection itself has not been explicitly closed. After the first client group enters the dormant state, if the first connection set is an empty set at this time, each target client has determined the corresponding disconnection delay time; if the first connection set is not an empty set at this time, the first candidate client in the first connection set is selected to obtain a second client group, the second client group includes a first number of first candidate clients, and the disconnection delay time corresponding to the second client group is determined based on a preset time interval, and this cycle is repeated until the first connection set is an empty set.

[0113] The embodiment of the present application sets a disconnection delay time for each target client according to the target disconnection rate and the preset safety rate threshold, so that each target client performs disconnection after the disconnection delay time. In this way, the present application can control the disconnection rate between the server and the client by setting the disconnection delay time, avoid the instability of the server caused by the excessively high disconnection rate, and ensure the stable operation of the server.

[0114] In other embodiments, all target clients connected to the server are classified according to their geographical locations and divided into several larger regions such as South China, North China, and East China. When establishing a long connection, the server synchronously analyzes the target client and classifies it into the corresponding region, and configures an independent counter for each region to record the number of disconnections. When a certain number of connections need to be disconnected, the daemon thread can calculate and determine the number of connections that should be disconnected in each region based on the proportion of connections in each region, thereby achieving regional balance of disconnection operations. It should be noted that when a certain number of connections, such as 1,000, need to be disconnected at the same time, the daemon thread can determine the proportion of each region by calculating the proportion of the disconnection value of each regional counter to the total number of connections. Then, the total number of connections to be disconnected (1,000) is multiplied by the proportion of each region, thereby obtaining the number of connections that should be disconnected in each region under the current circumstances. When the target client initiates a reconnection request after disconnection, since the connections are evenly distributed, these requests will be dispersed to the servers in different regions, thereby avoiding excessive pressure on the servers in a single region.

[0115] For example, see Figure 5, when starting the server, two threads are started at the same time: the worker thread and the daemon thread. The worker thread is the core of the server and is responsible for handling client connection, disconnection, and communication services. The daemon thread is responsible for monitoring and controlling the disconnection rate to ensure the stability of the server. The worker thread pool is a mechanism for managing multiple worker threads. It pre-creates and manages a group of worker threads. The worker thread pool can detect whether there is a target client disconnection. If so, the worker thread can send a signal to the daemon thread. The daemon thread is configured with a rate calculator. Through the rate calculator, the daemon thread can obtain the target disconnection rate, that is, the number of target clients disconnected from the server per second; the daemon thread also sets a preset safety rate threshold, such as 1000 / s. The preset safety rate threshold can be adjusted according to actual business needs and is not limited here. When the target disconnection rate does not exceed the preset safety rate threshold set by the daemon thread, the server will use the conventional disconnection method, that is, real-time disconnection, to ensure a quick response. If the target disconnection rate exceeds the preset safety rate threshold, the daemon thread will record the exception and generate an alarm log, which will be sent to the server via email. If the target disconnection rate exceeds the preset safety rate threshold three times in a row, the server may be in an unstable state, and the random delay disconnection protection mechanism will be triggered. It should be noted that when the random delay disconnection protection mechanism is triggered, the daemon thread will store the target clients that exceed the preset safety rate threshold in the abnormal connection collector. Then, the daemon thread randomly selects a random delay time in the range of 1000 milliseconds to 5000 milliseconds, randomly selects 1000 target clients from the abnormal connection collector, and sets the random delay time as the disconnection delay time of these 1000 target clients, so that these 1000 target clients enter a dormant state. After the disconnection delay time ends, these 1000 target clients are immediately disconnected from the server. After these 1000 target clients enter dormancy, the daemon thread determines whether the abnormal connection collector is an empty set. If not, a random delay time is re-obtained, and 1000 target clients that need to be processed are randomly selected from the abnormal connection collector until the abnormal connection collector is an empty set.

[0116] The embodiment of the present application aims to indirectly adjust the client's reconnection behavior by accurately controlling the disconnection rate through a random delay disconnection protection mechanism to maintain the business continuity and stability of the server. This mechanism not only avoids the peak traffic caused by excessively high disconnection rates from the source, but also significantly reduces the maintenance cost of the client and simplifies the development requirements of the client. Since all control logic is implemented on the server, maintenance and adjustment strategies become more convenient and flexible. In addition, the proactive control strategy of this solution ensures that once the disconnection rate is effectively limited, the client's reconnection behavior will also be controlled synchronously, thereby fundamentally preventing the occurrence of peak traffic and improving the stability and reliability of the entire network system.

[0117] See also Figure 6 The embodiment of the present application further provides a device for disconnecting a server from a client, which can implement the above-mentioned method for disconnecting a server from a client. The device is applied to the server, and the device includes:

[0118] The detection module 601 is used to determine the working thread and the daemon thread corresponding to the server, and the daemon thread is used to detect the disconnection data of multiple target clients connected to the server;

[0119] A receiving module 602 is used to receive a target disconnection signal based on a working thread, where the target disconnection signal is used to indicate that at least one target client is disconnected from the server;

[0120] An acquisition module 603 is used to acquire a target disconnection rate of multiple target clients based on the target disconnection signal and the daemon thread, where the target disconnection rate is used to represent the number of target clients disconnected from the server within a first preset unit time;

[0121] A determination module 604, configured to determine a disconnection state of the server based on a target disconnection rate;

[0122] The delay module 605 is used to determine the disconnection delay time of each target client based on the disconnection state, so that the target client is disconnected from the server after the corresponding disconnection delay time.

[0123] The specific implementation of the device for disconnecting the server from the client is substantially the same as the specific implementation of the method for disconnecting the server from the client, and will not be described in detail herein.

[0124] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned method of disconnecting the server and the client when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0125] See also Figure 7 , Figure 7 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0126] The processor 701 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0127] The memory 702 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 702 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 702, and the processor 701 calls and executes the disconnection method between the server and the client in the embodiment of this application;

[0128] Input / output interface 703, used to implement information input and output;

[0129] Communication interface 704, used to realize communication interaction between the device and other devices, which can be realized through wired mode (such as USB, network cable, etc.) or wireless mode (such as mobile network, WIFI, Bluetooth, etc.);

[0130] A bus 705 that transmits information between the various components of the device (e.g., the processor 701, the memory 702, the input / output interface 703, and the communication interface 704);

[0131] The processor 701 , the memory 702 , the input / output interface 703 and the communication interface 704 are connected to each other in communication within the device via a bus 705 .

[0132] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the above-mentioned method for disconnecting the server and the client.

[0133] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0134] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0135] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0136] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0137] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0138] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0139] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0140] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0141] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple 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.

[0142] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0143] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0144] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A method for disconnecting a server from a client, characterized in that: Applied to the server, the method includes: Determine a working thread and a daemon thread corresponding to the server, wherein the daemon thread is used to detect disconnection data of multiple target clients connected to the server; Receiving a target disconnection signal based on the working thread, the target disconnection signal is used to indicate that at least one of the target clients is disconnected from the server; Acquire a target disconnection rate of the plurality of target clients based on the target disconnection signal and the daemon thread, wherein the target disconnection rate is used to represent the number of the target clients disconnected from the server within a first preset unit time; Determining a disconnection state of the server based on the target disconnection rate; The disconnection delay time of each target client is determined based on the disconnection state, so that the target client is disconnected from the server after the corresponding disconnection delay time.

2. The method according to claim 1, characterized in that The determining the disconnection state of the server based on the target disconnection rate includes: Acquire a target rate group based on a second preset unit time, the target rate group including a first target disconnection sub-rate and at least one second target disconnection sub-rate that are acquired continuously, wherein an acquisition time corresponding to the first target disconnection sub-rate is earlier than an acquisition time corresponding to the second target disconnection sub-rate; Performing status detection on the server based on the first target disconnection sub-rate to obtain a first disconnection sub-status; When the first disconnection sub-state is an unstable disconnection state, performing state detection on the server based on at least one of the second target disconnection sub-rates to obtain a second disconnection sub-state; The disconnection state of the server is determined based on the second disconnection sub-state.

3. The method according to claim 2, characterized in that The performing status detection on the server based on the first target disconnection sub-rate to obtain a first disconnection sub-state includes: When the first target disconnection sub-rate is greater than a preset safety rate threshold, determining that the first disconnection sub-state is the unstable disconnection state; or, When the first target disconnection sub-rate is less than or equal to the preset safety rate threshold, it is determined that the first disconnection sub-state is a stable disconnection state.

4. The method according to claim 2, characterized in that: The determining the disconnection state of the server based on the second disconnection sub-state includes: When the second disconnection sub-state is an unstable disconnection state, determining that the disconnection state of the server is an unstable disconnection state; or, When the second disconnection sub-state is a stable disconnection state, it is determined that the disconnection state of the server is a stable disconnection state.

5. The method according to claim 3, characterized in that: The determining the disconnection delay time of each target client based on the disconnection state includes: When the disconnection state is an unstable disconnection state, a first connection set and a second connection set are constructed based on the target client, the first connection set includes a first candidate client, and the first candidate client is used to represent the target client whose corresponding target disconnection rate is greater than the preset safety rate threshold; the second connection set includes a second candidate client, and the second candidate client is used to represent the target client whose corresponding target disconnection rate is less than or equal to the preset safety rate threshold; Determine a disconnection delay time corresponding to the second candidate client based on the first preset time; Client selection is performed on the first candidate clients in the first connection set to obtain a first client group, where the first client group includes a first number of the first candidate clients, and a disconnection delay time corresponding to the first client group is determined based on a preset time interval.

6. The method according to claim 5, characterized in that The determining the disconnection delay time corresponding to the first client group based on a preset time interval includes: Select a random delay time from a preset time interval; The random delay time is used as the disconnection delay time corresponding to the first client group.

7. The method according to claim 1, characterized in that The receiving a target disconnect signal based on the working thread includes: Receiving a disconnection request from the target client based on the working thread, generating the target disconnection signal according to the disconnection request; or, The working thread receives a disconnection instruction from the server, and generates the target disconnection signal according to the disconnection instruction.

8. A device for disconnecting a server from a client, applied to a server, the device comprising: A detection module, used to determine a working thread and a daemon thread corresponding to the server, wherein the daemon thread is used to detect disconnection data of multiple target clients connected to the server; A receiving module, configured to receive a target disconnection signal based on the working thread, wherein the target disconnection signal is used to indicate that at least one of the target clients is disconnected from the server; an acquisition module, configured to acquire a target disconnection rate of the plurality of target clients based on the target disconnection signal and the daemon thread, wherein the target disconnection rate is used to represent the number of the target clients disconnected from the server within a first preset unit time; A determination module, configured to determine a disconnection state of the server based on the target disconnection rate; A delay module is used to determine a disconnection delay time of each target client based on the disconnection state, so that the target client is disconnected from the server after the corresponding disconnection delay time.

9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the method for disconnecting a server and a client as described in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for disconnecting a server and a client according to any one of claims 1 to 7 is implemented.