Disclosure of Invention
The technical problem to be solved by the present invention is to provide a new method for implementing data fast processing based on wireless session protocol, which avoids system overhead caused by frequent application and release of memory, so as to occupy less storage space, avoid the defect of inconvenient judgment and comparison, and is used for improving the performance and stability of the WAP gateway.
The technical scheme of the invention is as follows:
a method for realizing data rapid processing based on a wireless session protocol comprises the following steps:
a1, pre-establishing a hash index array, a session state machine array and a method state machine array; the Hash index array stores a session ID and points to a session state machine array, the session state machine array stores session information, and one session information points to at least one method state machine information of the method state machine array;
a2, obtaining user request information from the information queue, calculating the hash key value, inquiring whether the conversation ID of the information exists in the hash index array, otherwise establishing conversation for the user and establishing the conversation information; a3, according to the session ID of the message, inquiring whether method state machine information corresponding to the session ID exists in the method state machine array, otherwise, creating the method state machine information for the message; and A4, processing data according to the message and the method state machine information thereof, and updating the method state machine information stored in the method state machine array.
The method, wherein after the step A1 and before the step A2, the following steps are further executed: a11, judging the user to surf the Internet, establishing a session for the user and creating the session information; creating the session information comprises storing the session information in a certain session element of the session state machine array, and storing a subscript of the session element in the hash index array as a session ID; or A12, judging the user's message receiving and sending on the internet, and creating method state machine information for each interactive message; creating method state machine information, including storing the method state machine information processed by the current interactive message and the session ID of the session to which the method state machine information belongs in a certain method element of the method state machine array; or A13, if the user finishes surfing the Internet or does not operate overtime, disconnecting the session, and releasing the method elements of the method state machine array, the session elements of the session state machine array and the index elements of the hash index array occupied by the session.
The method, wherein, in step a12, after creating method state machine information for each interactive information, further comprises the following steps: and periodically checking the session state machine array and cleaning the overtime session elements.
The method comprises the step of presetting the sizes of the hash index array, the session state machine array and the method state machine array according to the operation capacity of the WAP gateway.
The method of (1), wherein the subscript of the method element is a method state machine ID assigned by the gateway; and,
after step a1, before a2, the following step a20 is also performed: if the gateway judges that the message is returned by the server and has the method state machine ID, searching the method state machine information of the message in a method state machine information array, and executing the step A4; otherwise, step a2 is performed.
In the method, the hash key value in the step a2 is calculated by a hash algorithm according to the IP address and the port of the user and the IP address and the port of the WAP gateway.
The method, wherein the step A2 further comprises the following step A21: and if the query result exceeds one session ID, querying the session established by the user to which the message belongs according to the IP address of the user of the session corresponding to each session ID, and adopting the session ID.
In the method, the session information in the session elements is used as a linked list to sequentially query the session established by the user to which the message belongs.
In the method, the session established by the user to which the message belongs is inquired according to the IP address and the port of the user of the session corresponding to each session ID.
The method, wherein, the following step a5 is further executed after the step a 4: and releasing the method elements of the method state machine information array occupied by the message.
By adopting the scheme, the memory is fixedly distributed through the array, the message processing flow is mapped into the array, and the element of the state machine for message processing is quickly determined through the Hash key value, so that the system overhead caused by frequent application and release of the dynamic memory distribution method to the memory is solved, the operation efficiency is improved, the occupied storage space is reduced, and the defect of inconvenient judgment and comparison is avoided; in addition, the array is used for storing the conversation information, and each conversation corresponds to one mobile phone user, so that the number of the mobile phone users who are online at the same time and the concurrent processing capacity of the WAP gateway are improved, and the performance and the stability of the WAP gateway are improved.
Detailed Description
The invention is described in detail below with reference to the figures and the specific embodiments.
The invention adopts the fixed memory allocation mode of the array and combines the Hash search algorithm to classify and process the data packet according to the mobile phone user, and maps the processing flow of the data packet into two-stage Hash search so as to achieve the purpose of rapidly processing the data packet. Therefore, as shown in fig. 1, the present invention provides a method for implementing fast data processing based on a wireless session protocol, and the steps thereof are specifically described below.
A1, pre-establishing a hash index array, a session state machine array and an array; when each array is established, the sizes of the hash index array, the session state machine array and the method state machine array can be preset according to the operation capability of the WAP gateway.
The Hash index array stores the session ID and points to the session state machine array; the array of session state machines stores session information, and one session information may point to multiple pieces of method state machine information of the array of method state machines. Specifically, the elements in the hash index array store session IDs established by the WAP gateway and the mobile phone user; elements in the information array of the session state machine store session information established by the mobile phone and the WAP gateway; the ID of the session and the state machine information processed by the current message are stored in the method state machine information array.
The following steps may also be performed after step a 1.
A11, judging the user to surf the Internet, establishing a session for the user and creating the session information; the creating of the session information includes storing the session information in a certain session element of the session state machine array, and storing a subscript of the session element as a session ID in the hash index array.
A12, judging the message sent and received by the user on the Internet, and creating method state machine information for each interactive message; the creating method state machine information comprises the step of storing the method state machine information processed by the current interactive message and the session ID of the session to which the current interactive message belongs in a certain method element of the method state machine array, namely associating the method element with the session element, the same as the session ID, through corresponding processing. The following steps can be included thereafter: periodically checking the session state machine array, and cleaning the overtime session elements; the timed-out sessions may be cleared periodically at times preset by the system administrator, for example, by periodically checking elements of the session state machine information array using a timer module.
A13, judging that the user finishes surfing the Internet or does not operate overtime, disconnecting the session, and releasing the method elements of the method state machine array, the session elements of the session state machine array and the index elements of the hash index array occupied by the session. When the mobile phone is off line or the gateway is in time-out to actively disconnect the session, the occupied method state machine information elements to which the session belongs are released firstly, then the occupied session state machine information elements are released, and the corresponding elements in the corresponding hash index array are also released.
It should be noted that, the above steps a11, a12, and a13 may be executed independently, or may be executed in a preset order, for example, first executing a111, then executing a12, and then executing a 13.
A2, obtaining user request information from the information queue, calculating the hash Key Value (Key Value), in the hash index array, inquiring whether the session ID of the information exists, otherwise, establishing a session for the user and creating the session information; creating the session information is as described above. The hash key value can be calculated by a hash algorithm according to the IP address and the port of the user and the IP address and the port of the WAP gateway.
One embodiment may be that step a2 further comprises the following step a 21: and if the query result exceeds one session ID, querying the session established by the user to which the message belongs according to the IP address of the user of the session corresponding to each session ID, and adopting the session ID. For example, the session information in the multiple session elements is used as a linked list to sequentially query the session established by the user to which the message belongs. For another example, the session established by the user to which the message belongs is queried according to the IP address and port of the user of the session corresponding to each session ID.
That is, when a hash collision occurs, for example, one KEY value corresponds to multiple sessions, multiple session information elements may be designed as a linked list sequential query, and the IP addresses of the mobile phone users are compared, or the IP addresses and ports of the mobile phone users are compared until the session established by the mobile phone user is found. A mobile phone user may send a plurality of request methods at a certain moment, one session can also correspond to a plurality of method state machine information, the method state machine information array elements are also designed into a linked list type query, and the method state machine information elements requested by the mobile phone are found according to the service marks carried in the message.
Another embodiment may be to use the gateway assigned method state machine ID as the subscript for the method element, when step a2 is preceded by the following step a 20: if the gateway judges that the message is returned by the server and has the method state machine ID, searching the method state machine information of the message in a method state machine information array, and executing the step A4; otherwise, step a2 is performed. I.e. the messages returned by the server can be processed quickly.
A3, according to the session ID of the message, inquiring whether method state machine information corresponding to the session ID exists in the method state machine array, otherwise, creating the method state machine information for the message; the creation method state machine information is as described above.
And A4, processing data according to the message and the method state machine information thereof, and updating the method state machine information stored in the method state machine array.
Preferably, in any of the embodiments of the present invention, after the step a4, the following step a5 may be further performed: and releasing the method elements of the method state machine information array occupied by the message.
For example, briefly, the present invention provides a method for rapidly processing data under a wireless session protocol, which includes the following key steps:
A. an array of hash indices, an array of session state machine information (i.e., an array of session state machines), and an array of method state machine information (i.e., an array of method state machines) are created.
B. And acquiring the message in the message queue in the WSP module, performing hash operation on the message, and calculating a hash KEY value, wherein the hash KEY value can be calculated through the IP address and the port of the mobile phone user and the IP address and the port of the WAP gateway by a hash algorithm.
C. And establishing a session on the mobile phone, occupying one element in the session state machine information array to store the session state machine information, and correspondingly occupying one element in the hash index array to store the session ID. When the WSP receives a request message sent from the bottom layer, whether a session ID established by the mobile phone and the WAP gateway exists or not is inquired in a corresponding hash index array according to the hash KEY value, and if the session ID exists, D is executed; if not, a new session is created and D is executed.
D. If the online mobile phone sends a PULL or receives a PUSH message, it will occupy an element of the method state machine array to store the information of the method state machine, and associate the element of the method state machine with the element of the session state machine information array, that is, set the same subscript. And when the WSP receives the request message after the session is established, searching whether the method state machine information array element requested by the mobile phone user has the method state machine information or not in the method state machine information array according to the related session information, and if not, creating the method state machine information.
E. And processing the mobile phone request message according to the received request message and the found mobile phone request method state machine information array element, and updating the information stored in the state machine information array element.
The method can also comprise a processing method for the WAP gateway to receive the corresponding message of the server, and the following steps are executed:
F. and directly searching in the method state machine information array according to the state machine information ID carried by the message returned by the server, processing the received message, and recording new information of the state machine into the state machine information array element.
G. And when the flow processing of the method state machine is finished, releasing the occupied elements of the information array of the method state machine.
The following describes the method provided by the present invention in detail with reference to fig. 1, and a workflow for processing a request message sent by a mobile phone user may include the following steps when the method of the present invention is used for processing.
Step 100: the method of the invention is started.
Step 101: creating a hash index array, a session state machine information array, and a method state machine information array.
a) The WAP gateway distributes a conversation for each online mobile phone user, and each conversation ID corresponds to an element of the hash index array.
b) The elements of the session state machine information array store the session established between the mobile phone user and the WAP gateway, and each element of the session array corresponds to one on-line user of the mobile phone.
c) The method state machine information array stores the state machine information processed by the current mobile phone request message, and each method state machine array element corresponds to one interaction between a mobile phone user and an application server. And stores the session ID, i.e. each session shown in fig. 2.
d) The size of each array can be determined according to the current network operation capability of the WAP gateway specified by an operator.
Step 102: reading the request message of the user from the message queue, wherein the parameters for marking the identity of the mobile phone user in the message are the IP address and the port of the mobile phone, and carrying out hash operation according to the WAP gateway address port and the mobile phone user address port to calculate the hash KEY value. The KEY value corresponds to the index of the hash index table.
Step 103: if there is session information in the KEY-th element according to the KEY value in the hash index table (i.e., hash index array), for example, if the KEY value is 17, then it is determined whether there is session information in the 17 th element in the hash index table, if not, then step 104 is performed, and if so, then step 105 is performed.
Step 104: finding a null element in the session state machine information array, establishing the session between the WAP gateway and the mobile phone user, storing the session information in the null element, taking the following table of the element as the session ID, and simultaneously storing the session ID in the KEY element in the index table to be associated with the hash index array. And if the session state machine information array has no empty element, refusing to establish a session with the mobile phone user.
Step 105: after the mobile phone user and the WAP gateway establish a session, the mobile phone sends a PULL message or receives a PUSH message, and determines whether there is method state machine information of the mobile phone request method in the session, if not, it goes to step 106, if yes, it goes to step 107.
For the method request message initiated by the mobile phone without establishing the session, the WAP gateway can be directly abandoned.
And 106, searching for spare elements of the state machine information array of the method, establishing the state machine information element of the method requested by the mobile phone user, marking the subscript of the state machine information array of the method as a method state machine ID distributed by a WAP gateway, storing related method state machine information in the element space, storing the ID of the session to which the element belongs, and associating the ID with the element of the state machine information array of the session to which the element belongs. If there is no spare element in the method state machine information array when receiving the user request method, the WAP gateway directly discards the request message.
Step 107: and processing the mobile phone request message according to the received request message and the found mobile phone request method state machine information array element, and updating the information stored in the state machine information array element.
The WAP gateway processes the response message returned by the application server, directly searches in the method state machine information array according to the method state machine ID carried in the response message, processes the received response message after finding the request method information element, and records the new information of the state machine into the state machine information array element. And when the flow processing of the method state machine is finished, releasing the occupied elements of the information array of the method state machine. And when all the method state machines under the session are processed, releasing the elements of the occupied session state machine information array for other use. Meanwhile, the session information array can be periodically checked by using a timer, and the overtime session can be cleared.
Step 108: ending the execution of the inventive method.
As shown in fig. 2, which includes a schematic diagram of the structure of each array, the data processing for the wireless session protocol according to the present invention is further explained in conjunction with fig. 2.
Step 201: the wireless session protocol provides a message queue to receive all messages, no matter whether the messages are of a terminal or a server, the messages are uniformly stored in the message queue, a request message sent by the mobile phone takes an address pair formed by the IP address ports of the mobile phone and the WAP gateway as a mark, and a response message returned by the server takes a method state machine ID as a mark.
The WAP gateway obtains the message from the message queue, judges whether the message is of the client side or the server side, the message of the client side can search the method state machine through the IP address and the port through the Hash operation, and the server side can directly inquire the method state machine according to the ID of the method state machine.
Step 202: and elements in the hash index array store the session ID, and when a request message of a user is received, hash operation is carried out on the IP address and the port of the mobile phone and the IP address and the port of the WAP gateway to calculate a hash KEY value. The KEY value indicates a subscript of the hash index array, and whether the established session ID exists is directly searched in the hash index array. Since the hash index array is statically allocated, the KEY value is left over according to the maximum number of elements of the array. Thus, hash collision may occur, and the session ID in the index table cannot indicate the session ID established by the mobile phone user. Therefore, if necessary, the sequence lookup of the linked list is also needed in the information array of the session state machine.
In the session state machine information array shown in FIG. 2, the KEY value of the user [1] (i.e., session [1], session ID [1]) is 1, which corresponds to the index of the hash index array [1], method [0] of the method state machine information array.
Step 203: and when the session ID is found in the hash index array, the established session is directly searched in the session state machine information array. For the phenomenon of hash collision, if the hash KEY value is 17 in fig. 2, 3 sessions are corresponded, including Session: 28. session: 14. session: 0 (i.e., session ID); after receiving the mobile phone request message, the WAP gateway first finds the session 28 from the hash index array, and then searches the linked list formed by the three sessions 28, 14, and 0, for example, sequentially. The searching condition can be the IP address and the port of the mobile phone or only the IP address of the mobile phone; because each mobile phone is on line, the WAP gateway can allocate a unique IP address for the mobile phone. If not, a new session is created, linked to the end of session 0, forming a linked list of 4 elements.
Step 204: after the mobile phone and the WAP gateway establish a session, the mobile phone starts to exchange data with the server by a PULL or PUSH method. And the subscript of the method state machine array is distributed as the ID of the method state machine, and the elements in the method state machine array can be directly found by searching the ID of the state machine in the session information array. Each session may correspond to multiple methods, so the state machine elements of the same method belonging to the session may also be grouped into a linked list for sequential lookup. The present invention is not limited to various search methods.
It will be understood that modifications and variations can be made by persons skilled in the art in light of the above teachings and all such modifications and variations are intended to be included within the scope of the invention as defined in the appended claims.