CN111193796A - Session keeping method based on delay queue, server and readable storage medium - Google Patents

Session keeping method based on delay queue, server and readable storage medium Download PDF

Info

Publication number
CN111193796A
CN111193796A CN201911399160.7A CN201911399160A CN111193796A CN 111193796 A CN111193796 A CN 111193796A CN 201911399160 A CN201911399160 A CN 201911399160A CN 111193796 A CN111193796 A CN 111193796A
Authority
CN
China
Prior art keywords
target
session object
delay queue
session
server
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201911399160.7A
Other languages
Chinese (zh)
Other versions
CN111193796B (en
Inventor
肖根元
陈存祺
王佟
陈明忠
安宏伟
邹熠
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
SHENZHEN STOCK EXCHANGE
Original Assignee
SHENZHEN STOCK EXCHANGE
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by SHENZHEN STOCK EXCHANGE filed Critical SHENZHEN STOCK EXCHANGE
Priority to CN201911399160.7A priority Critical patent/CN111193796B/en
Publication of CN111193796A publication Critical patent/CN111193796A/en
Application granted granted Critical
Publication of CN111193796B publication Critical patent/CN111193796B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/143Termination or inactivation of sessions, e.g. event-controlled end of session
    • H04L67/145Termination or inactivation of sessions, e.g. event-controlled end of session avoiding end of session, e.g. keep-alive, heartbeats, resumption message or wake-up for inactive or interrupted session
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • H04L43/0805Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
    • H04L43/0811Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking connectivity

Landscapes

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

Abstract

The invention discloses a conversation maintaining method based on a delay queue, which comprises the following steps: after the server establishes communication connection with a client, a session object corresponding to the client is generated, and the session object is listed in the tail of a delay queue; determining a session object positioned at the head of the delay queue as a first target session object; and sending detection information to a target client corresponding to the first target session object to judge whether the target client keeps a session with the server, wherein the session object at the head of the delay queue is replaced after the server sends the detection information to the target client. The invention also discloses a server and a readable storage medium. The conversation between the server and the client of the invention is kept and judged, and the consumed CPU resource and network bandwidth resource are less.

Description

Session keeping method based on delay queue, server and readable storage medium
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a session holding method based on a delay queue, a server, and a readable storage medium.
Background
After the client establishes connection with the server, the server needs to determine whether the client maintains a session state with the server. The server is usually connected to a plurality of clients, and therefore, the server needs a plurality of threads to determine the session state between the clients and the server, so that the server needs to consume a large amount of CPU resources, and the operating speed of the server is affected. That is, the problem of large CPU resources consumed for determining the session state between the server and the client in the prior art exists.
Disclosure of Invention
The invention mainly aims to provide a session holding method based on a delay queue, a server and a readable storage medium, and aims to solve the problem that CPU resources consumed by session state determination of the server and a client are large.
In order to achieve the above object, the present invention provides a delay queue-based session holding method, which includes the following steps:
after the server establishes communication connection with a client, a session object corresponding to the client is generated, and the session object is listed in the tail of a delay queue;
determining a session object positioned at the head of the delay queue as a first target session object;
and sending detection information to a target client corresponding to the first target session object to judge whether the target client keeps a session with the server, wherein the session object at the head of the delay queue is replaced after the server sends the detection information to the target client.
In an embodiment, after the step of determining the session object located at the head of the delay queue as the first target session object, the method further includes:
and when the session of the first target session object is timed out, executing the step of sending the detection information to the target client corresponding to the first target session object.
In an embodiment, after the step of determining the session object located at the head of the delay queue as the first target session object, the method further includes:
and when the session of the first target session object is timed out, taking out the first target session object from the delay queue, and executing the step of sending detection information to a target client corresponding to the first target session object.
In an embodiment, after the step of fetching the first target session object from the delay queue, the method further includes:
determining whether the last update time of the first target session object is consistent with the enqueue time of the first target session object in the delay queue, wherein the server updates the last update time to a system timestamp of the server for receiving information each time the server receives the information sent by the target client;
when the last update time is consistent with the enqueue time, executing the step of sending detection information to the target client corresponding to the first target session object;
when the last updating time is not consistent with the enqueuing time, updating the detention duration of the first target session object in the delay queue according to the difference value between the last updating time and the enqueuing time, and updating the enqueuing time to be the last updating time;
and according to the updated enqueuing time and the retention time, re-listing the first target session object in the delay queue. In an embodiment, the server fetches the first target session object from the delay queue through a first thread, determines the first target session object in the delay queue through the first thread, and sends probe information to the target client through a second thread.
In an embodiment, when the staying duration of the first target session object in the delay queue reaches a first preset duration, the session of the first target session object is timed out.
In an embodiment, after the step of sending the probe information to the target client corresponding to the first target session object, the method further includes:
when response information sent by the target client based on the detection information is received within a second preset time length, clearing the detention time length of the first target session object in the delay queue to arrange the first target session object in the tail of the delay queue;
and when response information sent by the target client based on the information is not received within a second preset time length, disconnecting the target client and deleting the first target session object.
In an embodiment, after the step of generating the session object corresponding to the client and queuing the session object in the tail of the delay queue, the method further includes:
receiving information sent by a client, and determining a second target session object corresponding to the information-sending client in the delay queue;
and clearing the detention time of the second target session object in the delay queue to arrange the second target session object in the tail of the delay queue.
To achieve the above object, the present invention further provides a server, which includes a memory, a processor, and a delay queue based session holding program stored in the memory and executable on the processor, wherein the delay queue based session holding program implements the steps of the delay queue based session holding method when executed by the processor.
To achieve the above object, the present invention also provides a computer-readable storage medium including a delay queue-based session holding program, which when executed by a processor implements the steps of the delay queue-based session holding method as described above.
According to the session maintaining method based on the delay queue, the server and the computer readable storage medium, after the server and the client establish communication connection, a session object corresponding to the client is generated, the session object is listed into the tail of the delay queue, and then the session object positioned at the head of the delay queue is determined as a target session object, so that detection information is sent to the target client corresponding to the target session object to judge whether the target client maintains a session with the server, and after the server sends the detection information to the target client, the session object positioned at the head of the delay queue is replaced. The server sends the detection information to the target session object aligned to the head of the delay queue and replaces the session object aligned to the head of the delay queue, so that the server sequentially judges whether the session between the server and the client is kept for the session object aligned to the head of the delay queue, the server does not need to simultaneously judge whether a plurality of clients keep session states with the server, the CPU consumed by the judgment of the session states between the server and the client is small, and the CPU resource and the network bandwidth resource consumed by the server are small.
Drawings
Fig. 1 is a schematic diagram of a hardware structure of a server according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a first embodiment of a method for holding a session based on a delay queue according to the present invention;
FIG. 3 is a flowchart illustrating a second embodiment of a method for holding a session based on a delay queue according to the present invention;
fig. 4 is a flowchart illustrating a session holding method based on a delay queue according to a third embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The embodiment of the invention provides a solution: after the server establishes communication connection with a client, a session object corresponding to the client is generated, and the session object is listed in the tail of a delay queue; determining a session object positioned at the head of the delay queue as a first target session object; and sending detection information to a target client corresponding to the first target session object to judge whether the target client keeps a session with the server, wherein the session object at the head of the delay queue is replaced after the server sends the detection information to the target client.
The server sends the detection information to the target session object aligned to the head of the delay queue and replaces the session object aligned to the head of the delay queue, so that the server sequentially judges whether the session between the server and the client is kept for the session object aligned to the head of the delay queue, the server does not need to simultaneously judge whether a plurality of clients keep session states with the server, the CPU consumed by the judgment of the session states between the server and the client is small, and the CPU resource and the network bandwidth resource consumed by the server are small.
As shown in fig. 1, fig. 1 is a schematic diagram of a hardware structure of a server according to an embodiment of the present invention.
As shown in fig. 1, the server may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), the optional user interface 1003 may also include a standard wired interface and a wireless interface, and the wired interface of the user interface 1003 may be a Universal Serial Bus (USB) interface in the present invention. The memory 1005 may be a high speed Random Access Memory (RAM); or may be a stable memory, such as a non-volatile memory, and may be a disk memory. The memory 1005 may alternatively be a storage device separate from the processor 1001.
It will be appreciated by those skilled in the art that the session maintenance device configuration shown in fig. 1 does not constitute a limitation of the session maintenance device and may include more or fewer components than shown, or some components in combination, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include therein: an operating system, a network communication module, a user interface module, and a delay queue based session holding program. In fig. 1, the network communication module is mainly used for connecting and communicating data with the client, and the processor 1001 may be configured to call the session holding program based on the delay queue stored in the memory 1005, and perform the following operations:
after the server establishes communication connection with a client, a session object corresponding to the client is generated, and the session object is listed in the tail of a delay queue;
determining a session object positioned at the head of the delay queue as a first target session object;
and sending detection information to a target client corresponding to the first target session object to judge whether the target client keeps a session with the server, wherein the session object at the head of the delay queue is replaced after the server sends the detection information to the target client.
In one embodiment, the processor 1001 may be configured to invoke a delay queue based session holding program stored in the memory 1005 and perform the following operations:
and when the session of the first target session object is timed out, executing the step of sending the detection information to the target client corresponding to the first target session object.
In one embodiment, the processor 1001 may be configured to invoke a delay queue based session holding program stored in the memory 1005 and perform the following operations:
and when the session of the first target session object is timed out, taking out the first target session object from the delay queue, and executing the step of sending detection information to a target client corresponding to the first target session object.
In one embodiment, the processor 1001 may be configured to invoke a delay queue based session holding program stored in the memory 1005 and perform the following operations:
determining whether the last update time of the first target session object is consistent with the enqueue time of the first target session object in the delay queue, wherein the server updates the last update time to a system timestamp of the server for receiving information each time the server receives the information sent by the target client;
when the last update time is consistent with the enqueue time, executing the step of sending detection information to the target client corresponding to the first target session object;
when the last updating time is not consistent with the enqueuing time, updating the detention duration of the first target session object in the delay queue according to the difference value between the last updating time and the enqueuing time, and updating the enqueuing time to be the last updating time;
and according to the updated enqueuing time and the retention time, re-listing the first target session object in the delay queue. In one embodiment, the processor 1001 may be configured to invoke a delay queue based session holding program stored in the memory 1005 and perform the following operations:
the server takes the first target session object out of the delay queue through a first thread, determines the first target session object in the delay queue through the first thread, and sends detection information to the target client through a second thread.
In one embodiment, the processor 1001 may be configured to invoke a delay queue based session holding program stored in the memory 1005 and perform the following operations:
and when the detention time of the first target session object in the delay queue reaches a first preset time, the session of the first target session object is overtime.
In one embodiment, the processor 1001 may be configured to invoke a delay queue based session holding program stored in the memory 1005 and perform the following operations:
when response information sent by the target client based on the detection information is received within a second preset time length, clearing the detention time length of the first target session object in the delay queue to arrange the first target session object in the tail of the delay queue;
and when response information sent by the target client based on the information is not received within a second preset time length, disconnecting the target client and deleting the first target session object.
In one embodiment, the processor 1001 may be configured to invoke a delay queue based session holding program stored in the memory 1005 and perform the following operations:
receiving information sent by a client, and determining a second target session object corresponding to the information-sending client in the delay queue;
and clearing the detention time of the second target session object in the delay queue to arrange the second target session object in the tail of the delay queue.
According to the scheme, after the server establishes communication connection with the client, a session object corresponding to the client is generated, the session object is listed at the tail of the delay queue, and then the session object positioned at the head of the delay queue is determined as a target session object, so that detection information is sent to the target client corresponding to the target session object to judge whether the target client keeps a session with the server, and after the server sends the detection information to the target client, the session object at the head of the delay queue is replaced. The server sends the detection information to the target session object aligned to the head of the delay queue and replaces the session object aligned to the head of the delay queue, so that the server sequentially judges whether the session between the server and the client is kept for the session object aligned to the head of the delay queue, the server does not need to simultaneously judge whether a plurality of clients keep session states with the server, the CPU consumed by the judgment of the session states between the server and the client is small, and the CPU resource and the network bandwidth resource consumed by the server are small.
Based on the hardware architecture of the server, various embodiments of the session holding method based on the delay queue are provided.
Referring to fig. 2, fig. 2 is a first embodiment of the session holding method based on delay queues according to the present invention, where the session holding method based on delay queues includes the following steps:
step S10, after the server establishes communication connection with the client, a session object corresponding to the client is generated, and the session object is listed in the tail of the delay queue;
in this embodiment, the execution subject is a server, which may be a game server, a financial server, a database server, or the like. The client may be in communication connection with the server through multiple communication protocols such as a hypertext transfer protocol (HTTP), a transmission control protocol/internet protocol (TCP/IP), an electronic mail protocol (MAILTO), and a User Datagram Protocol (UDP), that is, a session between the server and the client may be a TCP session, an HTTP session, a MAILTO session, and a UDP session.
The server is provided with a delay queue. After the server establishes communication connection with the client, the server generates a session object corresponding to the client, and then the session object is listed at the tail of the delay queue. It can be understood that each session object in the delay queue is sorted from early to late according to the generation time of the session object, and the earlier the generation time is, the closer the session object is to the head position of the delay queue. It should be noted that, after the server is connected to the client, the server may verify the client, after the verification is passed, establish a session object corresponding to the client, and when the session object is established, generate a sessionID for the session object, where the sessionID is an identifier of the session object, and the server may determine the client corresponding to the session object through the sessionID.
Step S20, determining the session object located at the head of the delay queue as a first target session object;
step S30, sending probe information to the target client corresponding to the first target session object to determine whether the target client maintains a session with the server, wherein the session object at the head of the delay queue is replaced after the server sends the probe information to the target client.
The delay queue contains a plurality of session objects, and each session object is sorted in the delay queue according to the generation time, and the server can determine the session state of the session object at the head position in the delay queue in turn. Specifically, the server determines the session object at the head of the delay queue as a first target session object, and sends probe information to the target client corresponding to the first target session object, so as to determine whether the target client maintains a session with the server. The detection information can be a detection heartbeat packet, and when the target client receives the detection heartbeat packet, if the target client and the server keep a session state, the target client can respond to the detection heartbeat packet so as to send response information to the server; if the target client and the server do not keep the session state, the target client does not respond to the detection heartbeat packet, that is, the target client does not send response information to the server. The server can judge whether the server and the target client keep conversation according to whether the response information sent by the target client is received.
The server determines the session state only for the first session object in the delay queue pair. Therefore, after the server sends the detection information to the target client, the session object at the head of the delay queue is replaced, that is, the first target session object is taken out, so that the session object which is positioned in the delay queue and is sequenced in the second order becomes the new first target session object.
And the extracted first target session object carries out corresponding processing according to the judgment result of the session maintenance between the server and the target client. And within the preset time (second preset time), when the server does not receive the response information sent by the target client based on the detection information, judging that the session state between the server and the target client is not kept, and at the moment, disconnecting the communication connection with the target client by the server and deleting the first target session object. Further, the server may send the probe information to the target client at intervals of a third preset duration, where the third preset duration is less than the second preset duration, so that the server sends the probe information to the target client multiple times within the second preset duration, if the server receives the response information sent by the target client, the server stops sending the probe information, and if the server sends the probe information to the target client multiple times and does not receive the response information sent by the target client, it may be determined that the server and the target client do not maintain the session state.
When the server receives response information sent by the target client based on the detection information within a second preset time length, the server and the target client can be judged to keep a session state, and the server puts the first target session object into the tail of the delay queue, so that the first target session object is sorted in the delay queue again, and the server can judge whether the session is kept for the continuous target client.
In addition, the client and the server can perform data interaction, namely, the client can actively send information to the server, and if the server receives the information sent by the client, the client and the server can be determined to keep conversation. At this time, the server determines a second target session object corresponding to the client sending the information in the delay queue, and the server then lists the second target session object in the tail of the delay queue.
In this embodiment, the internal data structure of the delay queue is a minimum top heap, namely: the first session object at the head of the queue will be the first expired session object and also the first dequeued session object. In an exemplary technology, the technical means for determining whether a session is expired is as follows: the session object which is expired first is found from the set containing n session objects, and the computation complexity is n. According to the principle of minimum top heap, the computation complexity of head elements is 1, the computation complexity of enqueuing is log (n), and the computation complexity of dequeuing is log (n). That is, the computational complexity of determining whether the client maintains the session with the server in the delay queue manner is much less than that of determining whether the client maintains the session with the server in the exemplary technology.
In addition, in this embodiment, when the client sends information to the server, the server only records the record of the information sent by the client, and does not feed back the information to the client, that is, in this embodiment, the client communicates with the server in a single-side heartbeat packet manner, so that the server can save network overhead for feeding back the information to the client. Furthermore, the detection information sent by the server to the client is actually a detection heartbeat packet, and the client feeds back the detection heartbeat packet to the server when receiving the detection heartbeat packet, that is, the server judges whether the client and the server keep a session in a form of a bilateral heartbeat packet, so that the server can accurately determine whether the client and the server keep the session. Meanwhile, the server has a retransmission mechanism for sending the detection information, namely the server sends the detection information to the client again after not receiving the feedback of the client based on the detection information within the preset time length, so that the server is prevented from misjudging that the client does not keep conversation with the server, namely the server has higher conversation judgment reliability.
In the technical scheme provided by this embodiment, after a server establishes a communication connection with a client, a session object corresponding to the client is generated, the session object is listed at the tail of a delay queue, and then the session object positioned at the head of the delay queue is determined as a target session object, so that probe information is sent to a target client corresponding to the target session object to determine whether the target client maintains a session with the server, and after the server sends the probe information to the target client, the session object at the head of the delay queue is replaced. The server sends the detection information to the target session object aligned to the head of the delay queue and replaces the session object aligned to the head of the delay queue, so that the server sequentially judges whether the session between the server and the client is kept for the session object aligned to the head of the delay queue, the server does not need to simultaneously judge whether a plurality of clients keep session states with the server, the CPU consumed by the judgment of the session states between the server and the client is small, and the CPU resource and the network bandwidth resource consumed by the server are small.
Referring to fig. 3, fig. 3 is a second embodiment of the session holding method based on the delay queue according to the present invention, and based on the first embodiment, after step S20, the method further includes:
step S40, when the session of the first target session object times out, take out the first target session object from the delay queue, and execute the step of sending the probe information to the target client corresponding to the first target session object.
In this embodiment, since the client may actively send information to the server, the server determines that the client maintains a session with the server. In contrast, the server may set an timeout duration corresponding to the client, and within the timeout duration, if the server does not receive information sent by the target client corresponding to the first target session object, it may determine that the session of the first target session object is timeout, and the server sends detection information to the target client to determine whether the target client maintains a session with the server.
The server can judge whether the session of the first target session object is overtime or not according to the detention time of the first target session object in the delay queue. The detention time length refers to the time length of the detention of the session object in the delay queue, and when the session object is listed at the tail of the delay queue, the detention time length of the session object in the delay queue is started to be timed. It can be understood that, when the first target session object and the second target session object are re-queued at the tail of the delay queue, the residence time lengths of the first target session object and the second target session object are cleared to restart the timing of the residence time lengths of the first target session object and the second target session object.
And when the detention time length of the first target session object is longer than a first preset time length, taking out the first target session object, and then sending detection information to a target client corresponding to the first target session object. The first predetermined period of time may be any suitable value, for example, the first predetermined period of time may be 300 s.
It should be noted that, when a session object is established, the session object has three times, which are the last update time (lastactivetestamp), the enqueue time (enqueueTimestamp), and the system timestamp, and the three times are equal to each other. The enqueue time is the time for the session object to be queued in the delay queue. Meanwhile, the server also sets the delay time sessionTimeout of the session object, which is the above-mentioned retention time. In the technical scheme provided by this embodiment, when the server determines the first target session object and the session of the first target session object is timed out, the server takes out the first target session object to send the detection information to the target client corresponding to the first target session object, so that the server does not need to make a judgment on session maintenance for the client that actively sends information to the server, and the judgment times of the server are reduced; meanwhile, the server takes out the first target session object with the overtime session, so that the server can conveniently judge the session maintenance of the first target session object after the first target session object is replaced in the delay queue.
Referring to fig. 4, fig. 4 is a third embodiment of the session holding method based on the delay queue according to the present invention, and based on the second embodiment, after the step 40, the method further includes:
step S50, determining whether a last update time of the first target session object is consistent with a queuing time of the first target session object in the delay queue, wherein the server updates the last update time to a system timestamp of the server receiving information each time the server receives information sent by the target client;
step S60, when the last update time is consistent with the enqueue time, executing the step of sending probe information to the target client corresponding to the first target session object;
step S70, when the last update time is not consistent with the enqueue time, updating the staying time of the first target session object in the delay queue according to the difference between the last update time and the enqueue time, and updating the enqueue time to the last update time;
step S80, re-enqueue the first target session object in the delay queue according to the updated enqueue time and the retention time.
In this embodiment, the client actively sends information to the server. When the server receives the information sent by the client, the server can determine that the client and the server keep conversation, and at the moment, the server updates the last updating time corresponding to the conversation object corresponding to the client into the time when the client sends the information to the server. Therefore, when the first target session object at the head of the delay queue is overtime, that is, the staying time of the first target session object corresponding to the delay reaches the first preset time, the server takes out the first target session object, and determines whether the last update time of the first target session object is consistent with the enqueue time.
If the last update time of the first target session object is inconsistent with the enqueue time, it indicates that the target client of the first target session object actively sends information to the server, and the server does not need to send detection information to the target client to determine whether the target client keeps a session with the server, at this time, the server calculates the difference between the enqueue time and the last update time, so as to update the retention time of the first target session object in the delay queue according to the difference, then updates the enqueue time of the first target session object to the last update time, and finally re-queues the first target session object in the delay queue according to the updated enqueue time and the retention time. This is illustrated for ease of understanding. Assuming that the enqueuing time of the first target session object is 9:00am, the last updating time is 9:00am, the preset time duration is 5min, the target client of the first target session object actively sends information to the server at 9:03am, and the last updating time is updated to 9:03am from 9:00 am; when the current time reaches 9:05am, the server calculates that the absolute value of the difference between the enqueue time and the last update time is 3min, then the preset time length is 5min and 3min is subtracted to obtain 2min, the detention time length (delay time) of the first target session object is updated to 2min, meanwhile, the enqueue time is updated to 9:03am, and the server lists the first target session object with the updated enqueue time and detention time length in a delay queue. It should be noted that, because each session object in the delay queue is queued in chronological order, and the enqueue time of the first target session object is updated to the time when the target client actively sends information to the server, the first target session object is actually inserted into the delay queue once.
If the last update time is consistent with the enqueue time, it is indicated that the first target session object does not actively send information to the server, and at this time, the server needs to send detection information to the target client.
In the technical scheme provided by this embodiment, when the first target session object times out, the server performs a second judgment on the first target session object, that is, judges whether the first target session object actively sends information to the server, where the information includes a normal service message and a heartbeat message, and if the target client actively sends information to the server, the server does not need to send probe information to the target client; if the target client does not actively send information to the server, the target client needs to send detection information, so that the server is prevented from sending the detection information to the client of the information which is actively sent, and the network overhead of the server is reduced.
In one embodiment, the server may keep a judgment on the session between the client and the server through the thread. Specifically, the server may set a first thread and a second thread, where the first thread is used to determine a first target session object in the delay queue and monitor a staying duration of the first target session object in the delay queue. When the detention time of the first target session object is longer than a first preset time, the first thread takes out the first target session object, the second thread sends detection information to a target client of the first target session object, the first thread determines the first target session object in the delay queue again, and the detention time of the first target session object in the delay queue which is determined again is monitored. It can be understood that the server can complete the judgment of session maintenance between the server and a plurality of clients through two threads, and the CPU resource of the server is greatly saved.
Thread pools are a form of multi-threaded processing in which tasks are added to a queue and then automatically started after a thread is created. The thread pool threads are all background threads. Each thread uses a default stack size, runs at a default priority, and is in a multi-threaded unit. If a thread is idle in managed code (e.g., waiting for an event), the thread pool will insert another helper thread to keep all processors busy. If all thread pool threads remain busy all the time, but pending work is contained in the queue, the thread pool will create another helper thread after a period of time but the number of threads never exceeds the maximum. Threads that exceed the maximum value may be queued, but they wait until other threads are completed before starting.
It is understood that the thread pool is composed of a plurality of threads, and the server can simultaneously perform a plurality of tasks through the plurality of threads. When the thread pool contains idle threads, the idle threads are that the server does not configure tasks for the threads, and the server determines the idle threads as first threads. And when the thread pool does not contain idle threads, the server creates an auxiliary thread as the first thread, but the sum of the auxiliary thread and the number of threads existing in the thread pool should not exceed the maximum number of threads of the thread pool. And if the maximum thread number is exceeded and the thread pool does not contain idle threads, the server waits for the threads to finish the task, so that the threads which finish the task are used as the first threads without creating the threads. The second thread may be a thread that is idle in the probe thread pool, or the server creates an assist thread in the probe thread pool.
The present invention also provides a server, which includes a memory, a processor, and a delay queue based session holding program stored in the memory and executable on the processor, and when executed by the processor, the delay queue based session holding program implements the steps of the delay queue based session holding method according to the above embodiments.
The present invention also provides a readable storage medium, which includes a delay queue based session holding program, and when executed by a processor, the delay queue based session holding program implements the steps of the delay queue based session holding method according to the above embodiments.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention essentially or contributing to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for holding a session based on a delay queue, comprising the steps of:
after the server establishes communication connection with a client, a session object corresponding to the client is generated, and the session object is listed in the tail of a delay queue;
determining a session object positioned at the head of the delay queue as a first target session object;
and sending detection information to a target client corresponding to the first target session object to judge whether the target client keeps a session with the server, wherein the session object at the head of the delay queue is replaced after the server sends the detection information to the target client.
2. The delay queue-based session holding method according to claim 1, wherein after the step of determining the session object located at the head of the delay queue as the first target session object, further comprising:
and when the session of the first target session object is timed out, executing the step of sending the detection information to the target client corresponding to the first target session object.
3. The delay queue-based session maintenance method of claim 2, wherein after the step of determining the session object located at the head of the delay queue as the first target session object, further comprising:
and when the session of the first target session object is timed out, taking out the first target session object from the delay queue, and executing the step of sending detection information to a target client corresponding to the first target session object.
4. The delay queue-based session maintenance method of claim 3, wherein after the step of retrieving the first target session object from the delay queue, further comprising:
determining whether the last update time of the first target session object is consistent with the enqueue time of the first target session object in the delay queue, wherein the server updates the last update time to a system timestamp of the server for receiving information each time the server receives the information sent by the target client;
when the last update time is consistent with the enqueue time, executing the step of sending detection information to the target client corresponding to the first target session object;
when the last updating time is not consistent with the enqueuing time, updating the detention duration of the first target session object in the delay queue according to the difference value between the last updating time and the enqueuing time, and updating the enqueuing time to be the last updating time;
and according to the updated enqueuing time and the retention time, re-listing the first target session object in the delay queue.
5. The delay queue-based session maintenance method of claim 3, wherein the server fetches the first target session object from the delay queue through a first thread, determines the first target session object in the delay queue through the first thread, and sends probe information to the target client through a second thread.
6. The session control method according to claim 2, wherein the session of the first target session object times out when a staying time period of the first target session object in the delay queue reaches a first preset time period.
7. The delay queue-based session maintenance method of claim 6, wherein after the step of sending probe information to the target client corresponding to the first target session object, the method further comprises:
when response information sent by the target client based on the detection information is received within a second preset time length, clearing the detention time length of the first target session object in the delay queue to arrange the first target session object in the tail of the delay queue;
and when response information sent by the target client based on the information is not received within a second preset time length, disconnecting the target client and deleting the first target session object.
8. The method for holding session based on delay queue as claimed in any of claims 1-3 or 5-7, wherein after the step of generating the session object corresponding to the client and queuing the session object in the tail of the delay queue, further comprising:
receiving information sent by a client, and determining a second target session object corresponding to the information-sending client in the delay queue;
and clearing the detention time of the second target session object in the delay queue to arrange the second target session object in the tail of the delay queue.
9. A server, comprising a memory, a processor, and a delay queue based session holding program stored in the memory and executable on the processor, the delay queue based session holding program when executed by the processor implementing the steps of the delay queue based session holding method of any one of claims 1-8.
10. A readable storage medium, comprising a delay queue based session holding program, which when executed by a processor implements the steps of the delay queue based session holding method of any one of claims 1-8.
CN201911399160.7A 2019-12-26 2019-12-26 Session keeping method based on delay queue, server and readable storage medium Active CN111193796B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911399160.7A CN111193796B (en) 2019-12-26 2019-12-26 Session keeping method based on delay queue, server and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911399160.7A CN111193796B (en) 2019-12-26 2019-12-26 Session keeping method based on delay queue, server and readable storage medium

Publications (2)

Publication Number Publication Date
CN111193796A true CN111193796A (en) 2020-05-22
CN111193796B CN111193796B (en) 2023-01-17

Family

ID=70711074

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911399160.7A Active CN111193796B (en) 2019-12-26 2019-12-26 Session keeping method based on delay queue, server and readable storage medium

Country Status (1)

Country Link
CN (1) CN111193796B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111917617A (en) * 2020-07-31 2020-11-10 宁波奥克斯电气股份有限公司 Intelligent household electrical appliance control method and device, server and storage medium
CN113055460A (en) * 2021-03-09 2021-06-29 百果园技术(新加坡)有限公司 Server selection method, device, equipment and medium
CN113259429A (en) * 2021-05-11 2021-08-13 鸬鹚科技(深圳)有限公司 Session keeping control method, device, computer equipment and medium
CN114363395A (en) * 2021-12-31 2022-04-15 深圳金蝶账无忧网络科技有限公司 Session processing method, device and computer readable storage medium
WO2023273838A1 (en) * 2021-06-29 2023-01-05 中兴通讯股份有限公司 Method and apparatus for establishing session on basis of bfd technology, and network device and computer storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5835724A (en) * 1996-07-03 1998-11-10 Electronic Data Systems Corporation System and method for communication information using the internet that receives and maintains information concerning the client and generates and conveys the session data to the client
CN1561043A (en) * 2004-02-20 2005-01-05 中兴通讯股份有限公司 Multi-user concurrent insertion device and its method
CN102340480A (en) * 2010-07-14 2012-02-01 杭州华三通信技术有限公司 Method for keeping alive between terminals and center server, center server and terminals thereof
CN103297390A (en) * 2012-02-27 2013-09-11 成都谛听科技有限公司 Method for enabling server to be connected with client-sides reversely
CN105490956A (en) * 2015-12-07 2016-04-13 方正移动传媒技术(北京)有限公司 Network request processing method and network request processing device
US20160330206A1 (en) * 2015-05-07 2016-11-10 Alibaba Group Holding Limited Method, device and server for managing user login sessions
CN107360054A (en) * 2017-06-23 2017-11-17 武汉票据交易中心有限公司 A kind of maintaining method and system of client session object
CN108809761A (en) * 2018-06-12 2018-11-13 威创集团股份有限公司 Presence detection method and device

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5835724A (en) * 1996-07-03 1998-11-10 Electronic Data Systems Corporation System and method for communication information using the internet that receives and maintains information concerning the client and generates and conveys the session data to the client
CN1561043A (en) * 2004-02-20 2005-01-05 中兴通讯股份有限公司 Multi-user concurrent insertion device and its method
CN102340480A (en) * 2010-07-14 2012-02-01 杭州华三通信技术有限公司 Method for keeping alive between terminals and center server, center server and terminals thereof
CN103297390A (en) * 2012-02-27 2013-09-11 成都谛听科技有限公司 Method for enabling server to be connected with client-sides reversely
US20160330206A1 (en) * 2015-05-07 2016-11-10 Alibaba Group Holding Limited Method, device and server for managing user login sessions
CN105490956A (en) * 2015-12-07 2016-04-13 方正移动传媒技术(北京)有限公司 Network request processing method and network request processing device
CN107360054A (en) * 2017-06-23 2017-11-17 武汉票据交易中心有限公司 A kind of maintaining method and system of client session object
CN108809761A (en) * 2018-06-12 2018-11-13 威创集团股份有限公司 Presence detection method and device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
任立勇等: "基于P2P和CDN的流媒体直播系统的设计与实现", 《计算机科学》 *
黄秋波等: "证券交易复杂事件处理策略管理服务模块的设计与实现", 《计算机应用与软件》 *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111917617A (en) * 2020-07-31 2020-11-10 宁波奥克斯电气股份有限公司 Intelligent household electrical appliance control method and device, server and storage medium
CN111917617B (en) * 2020-07-31 2022-03-29 宁波奥克斯电气股份有限公司 Intelligent household electrical appliance control method and device, server and storage medium
CN113055460A (en) * 2021-03-09 2021-06-29 百果园技术(新加坡)有限公司 Server selection method, device, equipment and medium
CN113055460B (en) * 2021-03-09 2024-04-19 百果园技术(新加坡)有限公司 Method, device, equipment and medium for selecting server
CN113259429A (en) * 2021-05-11 2021-08-13 鸬鹚科技(深圳)有限公司 Session keeping control method, device, computer equipment and medium
CN113259429B (en) * 2021-05-11 2023-12-05 鸬鹚科技(深圳)有限公司 Session maintenance management and control method, device, computer equipment and medium
WO2023273838A1 (en) * 2021-06-29 2023-01-05 中兴通讯股份有限公司 Method and apparatus for establishing session on basis of bfd technology, and network device and computer storage medium
CN114363395A (en) * 2021-12-31 2022-04-15 深圳金蝶账无忧网络科技有限公司 Session processing method, device and computer readable storage medium

Also Published As

Publication number Publication date
CN111193796B (en) 2023-01-17

Similar Documents

Publication Publication Date Title
CN111193796B (en) Session keeping method based on delay queue, server and readable storage medium
US20210311781A1 (en) Method and system for scalable job processing
CN108124003B (en) Network management equipment connection processing method, device and system
JP3480794B2 (en) Server computer system and method for generating predicted response
US8244822B1 (en) Push notification delivery system
US6981048B1 (en) Keep-alive messaging when two applications are running
CN108449239B (en) Heartbeat packet detection method, device, equipment and storage medium
CN109344172A (en) A kind of high concurrent data processing method, device and client-server
CN110233881B (en) Service request processing method, device, equipment and storage medium
CN110413425B (en) Third-party message callback method, device, server and storage medium
US10944683B1 (en) Hybrid queue system for request throttling
CN112395067A (en) Task scheduling method, system, device and medium
CN110166572A (en) Network processing method, device, electronic equipment and storage medium
CN107666474B (en) Network message processing method and device and network server
CN108429703B (en) DHCP client-side online method and device
CN111522663B (en) Data transmission method, device and system based on distributed storage system
JP3161369B2 (en) Network management information collection method
CN107819855A (en) A kind of message distributing method and device
CN110912926B (en) Data resource back-source method and device
TWI296387B (en) Scheduling method for remote object procedure call and system thereof
US8332498B2 (en) Synchronized relay messaging and coordinated network processing using SNMP
US10862811B1 (en) Message brokering for asynchronous status updates
CN109621407A (en) A kind of client log on request method and apparatus
CN112333115B (en) Data transmission method, terminal device, server and storage medium
CN110971535B (en) Communication congestion control method, device, equipment and storage medium

Legal Events

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