Disclosure of Invention
The invention provides a method and a device for session management, which are used for solving the problems of poor real-time performance of business transaction, low efficiency of system resource utilization and the like in the prior art.
In a first aspect, an embodiment of the present invention provides a session management method, including: scanning a session updating record table according to a session scanning rule, wherein the session updating record table comprises session updating time and a corresponding session key value; determining first session updating time meeting a first set condition, and determining a corresponding first session key value according to the first session updating time; searching a first session detailed record corresponding to the first session key value in a session detailed record table according to the first session key value, wherein the session detailed record table comprises session detailed information and the corresponding session key value; performing exception analysis on the first session detailed record according to an exception session rule to determine exception session information; and writing the abnormal session information into an abnormal session information table, and clearing the first session detailed record in the session detailed record table.
Optionally, after determining a first session update time meeting a first set condition and determining a corresponding first session key value according to the first session update time, the method further includes: and clearing the session update record corresponding to the first session update time in the session update record table.
Optionally, before scanning the session update record table according to the session scanning rule, the method further includes: and receiving a scanning triggering instruction.
Optionally, the session key is a session unique code ID.
Optionally, the updating process of the session detail record table is as follows: receiving an interface message sent by a session service initiator, wherein the interface message comprises a session initial request message or a session updating request; analyzing the interface message according to a multi-layer protocol; extracting messages related to session management in the analyzed interface messages, wherein the messages related to session management comprise second session detailed information and second session key values; according to a first set algorithm, the second session key value is quickly searched in the session detailed record table stored in the distributed memory bank; if the second session key value is not found in the session detailed record table, inserting the second session key value, second session detailed information corresponding to the second session key value and the current time of the inserting operation into the session detailed record table; and if the second session key value is found in the session detailed record table, replacing the session detailed information corresponding to the second session key value in the session detailed record with the second session detailed information corresponding to the second session key value, and reading the timestamp of the last updating operation and the time of the current updating operation.
Optionally, if the second session key value is found in the session detail record table, replacing the session detail information corresponding to the second session key value in the session detail record with the second session detail information corresponding to the second session key value, and reading the timestamp of the last update operation and the time of the current update operation, where the update process of the session update record table is as follows: searching a session updating record corresponding to the second session key value in the session updating record table according to the second session key value and the last updating operation timestamp and according to a second algorithm, and deleting the session updating record; and inserting the time of the current updating operation corresponding to the second session detailed information into a new session updating record according to the current timestamp and the second algorithm.
Optionally, if the second session key value is not found in the session detail record table, the second session key value, second session detail information corresponding to the second session key value, and the current time of the inserting operation are inserted into the session detail record table, and the updating process of the session update record table is as follows: and inserting the current time of the inserting operation corresponding to the second session detailed information into a new session updating record according to the current timestamp and the second algorithm.
In a second aspect, an embodiment of the present invention provides an apparatus for session management, including: the scanning module is used for scanning a session updating record table according to a session scanning rule, wherein the session updating record table comprises session updating time and a corresponding session key value; the determining module is used for determining first session updating time meeting a first set condition and determining a corresponding first session key value according to the first session updating time; the searching module is used for searching a first session detailed record corresponding to the first session key value in a session detailed record table according to the first session key value, wherein the session detailed record table comprises session detailed information and the corresponding session key value; the analysis module is used for carrying out abnormal analysis on the first session detailed record according to an abnormal session rule to determine abnormal session information; and the processing module is used for writing the abnormal session information into an abnormal session information table and clearing the first session detailed record in the session detailed record table.
Optionally, after determining a first session update time meeting a first set condition and determining a corresponding first session key value according to the first session update time, the apparatus further includes a clearing module: and the session update record corresponding to the first session update time is cleared from the session update record table.
Optionally, before scanning the session update record table according to the session scanning rule, the apparatus further includes a receiving module: for receiving a scan trigger instruction.
Optionally, the session key is a session unique code ID.
Optionally, the update process of the session detail record table is processed by the following modules included in the apparatus: the receiving module is used for receiving an interface message sent by a session service initiator, wherein the interface message comprises a session initial request message or a session updating request; the analysis module is used for analyzing the interface message according to a multi-layer protocol; the extracting module is used for extracting the analyzed messages related to session management in the interface messages, wherein the messages related to session management comprise second session detailed information and second session key values; the searching module is configured to perform fast searching on the second session key value in the session detail record table stored in the distributed memory bank according to a first setting algorithm; the processing module is further configured to insert the second session key value, second session detail information corresponding to the second session key value, and current insertion operation time into the session detail record table if the second session key value is not found in the session detail record table; the processing module is further configured to, if the second session key value is found in the session detail record table, replace the session detail information corresponding to the second session key value in the session detail record with the second session detail information corresponding to the second session key value, and read the timestamp of the last update operation and the time of the current update operation.
Optionally, if the second session key value is found in the session detail record table, replacing the session detail information corresponding to the second session key value in the session detail record with the second session detail information corresponding to the second session key value, and reading the timestamp of the last update operation and the time of the current update operation, where the update process of the session update record table is processed by the processing module included in the apparatus: searching a session updating record corresponding to the second session key value in the session updating record table according to the second session key value and the last updating operation timestamp and according to a second algorithm, and deleting the session updating record; and inserting the time of the current updating operation corresponding to the second session detailed information into a new session updating record according to the current timestamp and the second algorithm.
Optionally, if the second session key is not found in the session detail record table, the second session key, second session detail information corresponding to the second session key, and time of a current insertion operation are inserted into the session detail record table, and an update process of the session update record table is processed by the processing module included in the apparatus: and inserting the current time of the inserting operation corresponding to the second session detailed information into a new session updating record according to the current timestamp and the second algorithm.
In a third aspect, an embodiment of the present invention provides a non-volatile computer storage medium, where the computer storage medium stores an executable program, and the executable program is executed by a processor to implement any of the steps of the session management method.
In a fourth aspect, an embodiment of the present invention provides a computing device, including a memory, a processor, and a computer program stored on the memory, where the processor implements any of the above-mentioned steps of the session management method when executing the program.
The method and the device for session management provided by the embodiment of the invention have the following beneficial effects: determining a first session update time meeting a first set condition and a corresponding session key value according to the session scanning rule, the corresponding first session detailed record can be quickly searched in the session detailed record table according to the first session key value, the real-time performance of the business transaction is improved, according to abnormal conversation rule, determining abnormal conversation information, writing said abnormal conversation information into abnormal conversation information table, determining and recording abnormal conversation, namely, the service which can not be used is determined, the abnormal session information is cleared when the detailed record of the first session is cleared subsequently, so that the session is normally used, and the recorded abnormal session information can be analyzed to cause the abnormal session, and the first session detailed record is cleared in the session detailed record table, so that the invalid session data is effectively cleared, the system resources are saved, and the resource utilization efficiency is improved.
Detailed Description
The following describes the session management method and apparatus provided in the embodiments of the present invention in detail with reference to specific embodiments.
In the embodiments of the present invention, the references to "first" and "second" are merely for distinguishing and are not limited to the order.
Detailed description of the preferred embodiment
As shown in fig. 1, a method for session management according to a first embodiment of the present invention includes the following steps:
step 101, scanning a session update record table according to a session scanning rule, wherein the session update record table includes session update time and a corresponding session key value.
Specifically, the session scanning rule includes, but is not limited to, a trigger condition, a scanning object, a scanning start position, and a scanning end condition.
The session key value is a unique field in the session, preferably, the unique code (ID) of the session is selected as the session key value, the session update record table is a skip (skip) table, and the skip table is a hash (HASHMAP) memory table.
And 102, determining first session updating time meeting a first set condition, and determining a corresponding first session key value according to the first session updating time.
Specifically, the sessions in the session update record table are sorted according to the update time, the sessions are scanned forward in sequence from the tail of the session update record table, the scanning is stopped when the records meeting the end condition are scanned, and the first session update time meeting the first set condition is determined in the scanning process, where the tail of the session update record table is a position corresponding to the record of the session with the longest interval between the update time and the current time, and the end condition may be that the time interval between the update time and the current time is less than T, and T is expiration time.
Step 103, finding a first session detailed record corresponding to the first session key value in a session detailed record table according to the first session key value, where the session detailed record table includes session detailed information and the corresponding session key value.
Specifically, the session detail information includes, but is not limited to, a session unique code ID, a session sequence number, a session request type, a client ID, a type of a segment service carried in a session, and the like, the session detail list is a HASH map memory table, and the session unique code ID is used as a session key value, which may also be referred to as a HASH key value.
And 104, performing exception analysis on the first session detailed record according to an exception session rule to determine exception session information.
The exception rule includes response timeout, update timeout, end timeout, response exception, request sequence number disorder, and the like, and the exception rule is not limited in the present application.
And 105, writing the abnormal session information into an abnormal session information table, and clearing the first session detailed record in the session detailed record table.
Specifically, the abnormal session information is written into the abnormal session information table, the session record corresponding to the abnormal session information in the session detailed record table is cleared, and for a normal session, the session record corresponding to the clearer is directly cleared in the session detailed record table, that is, the first session detailed record is finally cleared in the session detailed record table.
The session management method provided by the embodiment of the invention has the following beneficial effects: determining a first session update time meeting a first set condition and a corresponding session key value according to the session scanning rule, the corresponding first session detailed record can be quickly searched in the session detailed record table according to the first session key value, the real-time performance of the business transaction is improved, according to abnormal conversation rule, determining abnormal conversation information, writing said abnormal conversation information into abnormal conversation information table, determining and recording abnormal conversation, namely, the service which can not be used is determined, the abnormal session information is cleared when the detailed record of the first session is cleared subsequently, so that the session is normally used, and the recorded abnormal session information can be analyzed to cause the abnormal session, and the first session detailed record is cleared in the session detailed record table, so that the invalid session data is effectively cleared, the system resources are saved, and the resource utilization efficiency is improved.
As a possible implementation manner, after step 102, the session update record corresponding to the first session update time is cleared in the session update record table.
As a possible implementation, before step 101, a scan trigger instruction is received.
Specifically, the trigger condition corresponding to the scan trigger instruction may be to perform scanning every 10 minutes.
Detailed description of the invention
As shown in fig. 2, another session management method according to a second embodiment of the present invention is described, which includes the following steps:
step 201, receiving an interface message sent by a session service initiator, where the interface message includes a session initiation request message or a session update request message.
And temporarily storing all contents of the interface message in a cache according to a tree structure.
Step 202, analyzing the interface message according to a multi-layer protocol.
Specifically, the interface message is analyzed layer by layer according to a multi-layer Protocol, where the Protocol includes, but is not limited to, an ethernet frame Protocol, a Transmission Control Protocol (TCP)/Internet Protocol (Internet Protocol, IP), a Data Communication (DCC) Protocol, and the like.
Step 203, extracting the analyzed messages related to session management from the interface messages, where the messages related to session management include second session detailed information and a second session key value.
And 204, quickly searching the second session key value in the session detail record table stored in the distributed memory bank according to a first setting algorithm.
Wherein, the first setting algorithm may be a HASHMAP algorithm.
The method adopts the distributed memory banks for data storage, and can improve the real-time performance of business transaction.
Step 2041, if the second session key value is not found in the session detail record table, inserting the second session key value, second session detail information corresponding to the second session key value, and current time of the inserting operation into the session detail record table.
Step 2042, if the second session key value is found in the session detail record table, replacing the session detail information corresponding to the second session key value in the session detail record with the second session detail information corresponding to the second session key value, and reading the timestamp of the last update operation and the time of the current update operation.
Step 2051, after step 2041, insert the time of the current insert operation corresponding to the second session detail information into a new session update record according to the current timestamp and the second algorithm.
Wherein the second algorithm may be a skiplist technique.
Step 2052, after the step 2042, finding a session update record corresponding to the second session key value in the session update record table according to the second session key value and the last update operation timestamp and according to a second algorithm, and deleting the session update record.
Step 2053, after the step 2052, inserting the time of the current update operation corresponding to the second session detail information into a new session update record according to the current timestamp and the second algorithm.
In the embodiment of the application, when a single process is applied, the tail part of the session update record table can be directly positioned, and the latest session update record is inserted; when the application is multi-process concurrent processing, a session update record table is searched by using a skip technology and the current timestamp, and when the position corresponding to the current timestamp is searched, the latest session update record is inserted.
Detailed description of the preferred embodiment
A third embodiment of the present invention provides a session management apparatus, as shown in fig. 3, including:
the scanning module 301 is configured to scan a session update record table according to a session scanning rule, where the session update record table includes session update time and a corresponding session key value.
The determining module 302 is configured to determine a first session update time meeting a first set condition, and determine a corresponding first session key value according to the first session update time.
The searching module 303 is configured to search, according to the first session key value, a first session detail record corresponding to the first session key value in a session detail record table, where the session detail record table includes session detail information and the corresponding session key value.
And the analysis module 304 is configured to perform anomaly analysis on the first session detail record according to an anomaly session rule, and determine anomaly session information.
The processing module 305 is configured to write the abnormal session information into an abnormal session information table, and clear the first session detail record in the session detail record table.
As a possible implementation, the apparatus further includes a clearing module: and the session update record corresponding to the first session update time is cleared from the session update record table.
As a possible implementation, the apparatus further includes a receiving module: for receiving a scan trigger instruction.
As a possible implementation, the session key is a session unique code ID.
As a possible implementation manner, the update process of the session detail record table is processed by the following modules included in the apparatus: the receiving module is used for receiving an interface message sent by a session service initiator, wherein the interface message comprises a session initial request message or a session updating request; the analysis module is used for analyzing the interface message according to a multi-layer protocol; the extracting module is used for extracting the analyzed messages related to session management in the interface messages, wherein the messages related to session management comprise second session detailed information and second session key values; the searching module is configured to perform fast searching on the second session key value in the session detail record table stored in the distributed memory bank according to a first setting algorithm; finding; the processing module is further configured to insert the second session key value, second session detail information corresponding to the second session key value, and current insertion operation time into the session detail record table if the second session key value is not found in the session detail record table; the processing module is further configured to, if the second session key value is found in the session detail record table, replace the session detail information corresponding to the second session key value in the session detail record with the second session detail information corresponding to the second session key value, and read the timestamp of the last update operation and the time of the current update operation.
As a possible implementation manner, the update process of the session update record table is processed by the processing module included in the apparatus: searching a session updating record corresponding to the second session key value in the session updating record table according to the second session key value and the last updating operation timestamp and according to a second algorithm, and deleting the session updating record; and inserting the time of the current updating operation corresponding to the second session detailed information into a new session updating record according to the current timestamp and the second algorithm.
As a possible implementation manner, the update process of the session update record table is processed by the processing module included in the apparatus: and inserting the current time of the inserting operation corresponding to the second session detailed information into a new session updating record according to the current timestamp and the second algorithm.
The session management device provided by the embodiment of the invention has the following beneficial effects: determining a first session update time meeting a first set condition and a corresponding session key value according to the session scanning rule, the corresponding first session detailed record can be quickly searched in the session detailed record table according to the first session key value, the real-time performance of the business transaction is improved, according to abnormal conversation rule, determining abnormal conversation information, writing said abnormal conversation information into abnormal conversation information table, determining and recording abnormal conversation, namely, the service which can not be used is determined, the abnormal session information is cleared when the detailed record of the first session is cleared subsequently, so that the session is normally used, and the recorded abnormal session information can be analyzed to cause the abnormal session, and the first session detailed record is cleared in the session detailed record table, so that the invalid session data is effectively cleared, the system resources are saved, and the resource utilization efficiency is improved.
The embodiment of the present invention further provides a nonvolatile computer storage medium, where an executable program is stored in the computer storage medium, and the executable program is executed by a processor to implement any of the steps of the method provided in the first embodiment.
An embodiment of the present invention further provides a computing device, configured to execute the session management method according to any one of the first and second embodiments, as shown in fig. 4, which is a schematic diagram of a hardware structure of the computing device according to the third embodiment of the present invention, where the computing device may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, and the like. The computing device may comprise a memory 401, a processor 402, and a computer program stored on the memory, which when executed by the processor, performs the steps of the method of the first embodiment. Memory 401 may include, among other things, Read Only Memory (ROM) and Random Access Memory (RAM), and provides the processor 402 with program instructions and data stored in the memory 401.
Further, the computing device may further include an input device 403, an output device 404, and the like. The input device 403 may include a keyboard, mouse, touch screen, etc.; the output device 404 may include a Display device such as a Liquid Crystal Display (LCD), a Cathode Ray Tube (CRT), or the like. The memory 401, the processor 402, the input device 403 and the output device 404 may be connected by a bus or other means, and fig. 4 illustrates an example of a connection by a bus.
The processor 402 calls the program instructions stored in the memory 401 and executes the method of session management provided in the first and second embodiments according to the obtained program instructions.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.