Summary of the invention
Technical problem to be solved by this invention provides a kind of new method based on WSP realization data quick-processing, avoid internal memory frequently to apply for discharging the overhead that brings, to take memory space still less, avoid defects caused by inconvenient judgment and comparison, be used to improve WAP gateway performance and stability.
Technical scheme of the present invention is as follows:
A kind of method based on WSP realization data quick-processing, it may further comprise the steps: A1, pre-established hash index array, session status machine array and method state machine array; A2, obtain subscription request message from message queue, calculate its Hash key assignments, in described hash index array, whether inquiry exists the session id of described message, otherwise sets up session and create described session information for this user; A3, according to the session id of described message, in described method state machine array, whether inquiry exists the method state machine information of described session id correspondence, otherwise is described message establishing method state machine information; A4, carry out data processing, and upgrade the method state machine information of storing in the described method state machine array according to described message and method state machine information thereof.
Described method wherein, is also carried out following steps: A11, is judged user's online after the steps A 1, then set up session and create described session information for this user; Create described session information and comprise, described session information is stored in a certain session element of described session status machine array, and with the subscript of described session element as session id, be stored in described hash index array; Perhaps, A12, judging the described user messaging of surfing the Net, then is each interactive messages creation method state machine information; The creation method state machine information comprises, with the session id of handled method state machine information of current interactive messages and affiliated session thereof, is stored in a certain method element of described method state machine array; Perhaps, A13, the described user of judgement finish online or overtime operation, then disconnect described session, discharge the session element of the method element of its described method state machine array that takies, described session status machine array, the index element of described hash index array.
Described method, wherein, further comprising the steps of after the steps A 12: as to make regular check on described session status machine array, clear up overtime session element.
Described method wherein, according to the serviceability of WAP gateway, pre-sets the size of described hash index array, described session status machine array and described method state machine array.
Described method, wherein, the following method state machine ID that is designated as the gateway distribution of described method element; And,
Also carry out following steps A20 before the steps A 2: gateway judges that described message is the message returned of server and has described method state machine ID, then searches the method state machine information of described message, execution in step A4 in method state machine information array; Otherwise execution in step A2.
Described method, wherein, Hash key assignments described in the steps A 2, IP address and port according to user's IP address and port and WAP gateway calculate by hash algorithm.
Described method, wherein, steps A 2 further comprising the steps of A21: judge that Query Result surpasses a session id,, inquire about the session that the affiliated user of described message sets up, adopt its session id then according to the user's IP address of each session id institute respective session.
Described method wherein, adopts session information in a plurality of session elements as chained list, carries out the session that the user under the described message of sequential query sets up.
Described method wherein, according to the user's IP address and the port of each session id institute respective session, is inquired about the session that the affiliated user of described message sets up.
Described method wherein, is also carried out following steps A5 after the steps A 4: the method element that discharges the method state machine information array that described message takies.
Adopt such scheme, the present invention is by array fixed allocation internal memory, the Message Processing flow process is mapped in the array, determine the element of the state machine of Message Processing fast by Hash (Hash) key assignments, solve the Dram distribution method and frequently the internal memory application has been discharged the overhead that brings, and improved operational efficiency, reduced shared memory space, avoided defects caused by inconvenient judgment and comparison; Use the storage of array session information in addition, therefore the corresponding cellphone subscriber of each session has improved simultaneously online cellphone subscriber's quantity and WAP gateway concurrent processing ability, thereby improves WAP gateway performance and stability.
Embodiment
Below in conjunction with the drawings and specific embodiments, the present invention is described in detail.
The present invention sorts out processing to packet by the cellphone subscriber in conjunction with Hash lookup algorithm by adopting the fixed memory method of salary distribution of array, the processing data packets flow process is mapped as the two-stage Hash lookup, to reach the purpose of fast processing packet.Therefore, as shown in Figure 1, the invention provides and a kind ofly realize the method for data quick-processing, below its step is specifically described based on WSP.
A1, pre-established hash index array, session status machine array and method state machine array; When setting up each array, can pre-set the size of described hash index array, described session status machine array and described method state machine array according to the serviceability of WAP gateway.
Hash index storage of array session id, directed session state machine array; Session status machine storage of array session information, session information can pointing method state machine array a plurality of method state machine information.Specifically, the session id of the storage WAP gateway of the element in the described hash index array and cellphone subscriber's foundation; The session information that element memory mobile phone in the session status machine information array and WAP gateway are set up; The ID of session under the storage in the method state machine information array, and the state machine information of current Message Processing.
After steps A 1, can also carry out following each step.
A11, judgement user online are for this user sets up session and creates described session information; The described session information of described establishment comprises, described session information is stored in a certain session element of described session status machine array, and with the subscript of described session element as session id, be stored in described hash index array.
A12, judging the described user messaging of surfing the Net, is each interactive messages creation method state machine information; Described creation method state machine information comprises, session id with handled method state machine information of current interactive messages and affiliated session thereof, be stored in a certain method element of described method state machine array, promptly handle by corresponding, method element and session element that described session id is identical are associated.Can also may further comprise the steps afterwards: make regular check on described session status machine array, clear up overtime session element; Can for example, use timer module to make regular check on the element of session status machine information array by the default time periodic cleaning of system operator, clear up overtime session.
A13, the described user of judgement finish online or overtime operation, then disconnect described session, discharge the session element of the method element of its described method state machine array that takies, described session status machine array, the index element of described hash index array.When mobile phone rolls off the production line or overtime gateway initiatively disconnects session, at first discharge the method that the takies state machine information element under the session, discharge occupied session status machine information element again, corresponding element also will discharge in the corresponding hash index array.
Need to prove that above steps A11, A12 and A13 can distinguish independent execution, also can carry out, for example, carry out A111 earlier, carry out A12 again, carry out A13 then by pre-seting order.
A2, obtain subscription request message from message queue, calculate its Hash key assignments (Key Value), in described hash index array, whether inquiry exists the session id of described message, otherwise sets up session and create described session information for this user; Create described session information as mentioned above.Wherein, described Hash key assignments can calculate by hash algorithm according to the IP address and the port of user's IP address and port and WAP gateway.
An embodiment can be steps A 2 further comprising the steps of A21: judge that Query Result surpasses a session id, then according to the user's IP address of each session id institute respective session, inquire about the session that the affiliated user of described message sets up, adopt its session id.For example, adopt session information in a plurality of session elements, carry out the session that the user under the described message of sequential query sets up as chained list.And for example, according to the user's IP address and the port of each session id institute respective session, inquire about the session that the affiliated user of described message sets up.
That is, when hash-collision occurring, for example corresponding a plurality of sessions of KEY value, a plurality of session information element can be designed to the linked list order inquiry, cellphone subscriber's IP address relatively, perhaps relatively cellphone subscriber's IP address and port are up to finding out the session that this cellphone subscriber sets up.The cellphone subscriber at a time, may send a plurality of requesting methods, session equally can corresponding a plurality of method state machine information, method state machine information array element equally also is designed to the linked list type inquiry, finds the method state machine information element of mobile phone request according to the service mark that carries in the message.
Another embodiment adopts the subscript of the method state machine ID of gateway distribution as described method element, at this moment, also carry out following steps A20 before the steps A 2: gateway judges that described message is the message returned of server and has described method state machine ID, then in method state machine information array, search the method state machine information of described message, execution in step A4; Otherwise execution in step A2.Promptly can carry out fast processing to the message that server returns.
A3, according to the session id of described message, in described method state machine array, whether inquiry exists the method state machine information of described session id correspondence, otherwise is described message establishing method state machine information; The creation method state machine information as mentioned above.
A4, carry out data processing, and upgrade the method state machine information of storing in the described method state machine array according to described message and method state machine information thereof.
Be more preferably, in arbitrary embodiment of the present invention, after steps A 4, can also carry out following steps A5: the method element that discharges the method state machine information array that described message takies.
For example, briefly, the invention provides the data quick-processing method under a kind of WSP, comprise following committed step:
A. create a hash index array, a session status machine information array (being session status machine array) and a method state machine information array (being method state machine array).
B. obtain the message in the message queue in the WSP module, and this message is carried out Hash operate, calculate a Hash KEY value, described Hash KEY value, IP address, the port that can pass through cellphone subscriber's IP address, port and WAP gateway calculate by hash algorithm and get.
C. mobile phone one is reached the standard grade and is then set up a session, takies an element store session state machine information in the session status machine information array, a corresponding element store session of the hash index array ID that takies.When WSP receives the request message that bottom sends, in the hash index array of correspondence, inquire about the session id that whether exists mobile phone and WAP gateway to set up according to Hash KEY value, if there is session id, then carry out D; If there is no, then newly create a session, carry out D again.
D. online mobile phone sends a PULL or receives receives a PUSH message, then can take the information of an element storage means state machine of method state machine array, and this method state machine element and affiliated session status machine information array element be associated, identical subscript promptly is set.When WSP receives request message after session is set up, then whether the method state machine information array element of searching cellphone subscriber's request according to relevant session information in method state machine information array has the method state machine information, does not find and then creates a method state machine information.
E. according to request message that receives and the mobile phone requesting method state machine information array element that finds, handle the mobile phone request message, upgrade canned data in this state machine information array element.
Can also comprise that WAP gateway receives the processing method of server corresponding message, carry out following steps:
F. the state machine information ID that carries of the message of returning according to server directly searches in method state machine information array, handles the message of receiving, the new information of recording status machine is in the state machine information array element.
G. after the processing of method state machine flow process finishes, the element of the method state machine information array of release busy then.
Below in conjunction with Fig. 1, to method provided by the invention, be elaborated, the cellphone subscriber sends the workflow of asking Message Processing, when adopting the inventive method to handle, can comprise the steps.
Step 100: begin to carry out the inventive method.
Step 101: create a hash index array, a session status machine information array and a method state machine information array.
A) WAP gateway distributes a session for each cellphone subscriber that reaches the standard grade, an element of the corresponding hash index array of each session id.
B) the element memory mobile phone user of session status machine information array and session that WAP gateway is set up, the corresponding mobile phone of each the session number group element user that reaches the standard grade.
C) state machine information handled of method state machine information storage of array current phone request message, once mutual between corresponding cellphone subscriber of each method state machine array element and the application server.Session id under storing simultaneously, each session promptly shown in Figure 2.
D) size of each array can be decided according to the WAP gateway existing network serviceability that operator clearly stipulates.
Step 102: read user's request message from message queue, the parameter of sign cellphone subscriber identity is the IP address and the port of mobile phone in the message, carries out the Hash operation according to WAP gateway address port and cellphone subscriber's address port, calculates Hash KEY value.The subscript of the corresponding hash index table of KEY value.
Step 103: search in KEY the element whether have session information to hash index table (being the hash index array) according to the KEY value, for example, the KEY value is 17, then searches the 17th element to the hash index table and whether has session information, do not exist to forward step 104 to, exist then to forward step 105 to.
Step 104: the element that in session status machine information array, finds a sky, set up WAP gateway and this cellphone subscriber's session, and session information is stored in this sky element, and the following table of this element is as session id, simultaneously store session ID in the concordance list in KEY element and the hash index array associate.If be not free element in the session status machine information array, then refusal and this cellphone subscriber set up session.
Step 105: after cellphone subscriber and WAP gateway are set up session, mobile phone sends a PUL message or accepts a PUSH message, whether there is the method state machine information of mobile phone requesting method under judging under the session, do not exist to forward step 106 to, exist then to forward 107 to.
To not setting up session, mobile phone is the method request message of initiation just, and WAP gateway can directly be abandoned.
Step 106, the vacant element of lookup method state machine information array, set up the state machine information element of cellphone subscriber's requesting method, the following method state machine ID that is labeled as the WAP gateway distribution of method state machine information array, the relevant method state machine information of this element space storage, and the ID of session under preserving, associate with affiliated session status machine information array element.If when receiving do not have vacant element in the method state machine information array by user's requesting method, then WAP gateway is directly abandoned this request message.
Step 107: according to request message that receives and the mobile phone requesting method state machine information array element that finds, handle the mobile phone request message, upgrade canned data in this state machine information array element.
The response message that the WAP gateway application server is returned is handled, according to the method state machine ID that carries in the response message, directly in method state machine information array, search, the response message that finds the reprocessing of requesting method information element to receive, the new information of recording status machine is in the state machine information array element.After the processing of method state machine flow process finishes, the element of the method state machine information array of release busy then.After method state machines all under the affiliated session was finished dealing with, then the element of the session status machine information array of release busy was used in order to other.Can use simultaneously timer cycle to check the session information array, clear up overtime session.
Step 108: finish to carry out the inventive method.
As shown in Figure 2, it has comprised the structural representation of each array, below in conjunction with Fig. 2 the present invention is further explained for WSP carries out data processing.
Step 201: WSP provides a message queue to accept all message, no matter message be terminal or server end, the unified message queue that is stored in, the address that the request message that mobile phone sends is formed with the IP address port of mobile phone and WAP gateway is to as a token of, and the response message that server returns is a sign with method state machine ID.
WAP gateway obtains message from message queue, judge this message be client or server end, the message of client can be operated the lookup method state machine through Hash by IP address and port, and server end can be according to method state machine ID directly to middle inquiry.
Step 202: the element store session ID in the hash index array, when receiving user's request message, the Hash operation is carried out in the IP address of mobile phone and the IP address and the port of port and WAP gateway, calculate a Hash KEY value.The subscript of KEY value representation hash index array directly searches whether deposit the session id of having set up in the hash index array.Because the hash index array is a static allocation, so get surplus according to the greatest member number of array to the KEY value.Hash-collision may occur like this, session id can not represent it is the session id that this cellphone subscriber sets up in the concordance list.Therefore in case of necessity, also need in session status machine information array, to search as linked list order.
In the session status machine information array as shown in Figure 2, user's [1] (being session [1], session id [1]) KEY value is 1, the index of its corresponding hash index array [1], the method [0] of method state machine information array.
Step 203: each reaches the standard grade mobile phone just and WAP gateway is set up a session, the subscript of session status machine information array is distributed to each session id, in this session id storage hash index array, when in the hash index array, finding this session id, directly search the session of foundation in the session status machine information array.For the phenomenon of hash-collision, be 17 o'clock as Hash KEY value among Fig. 2, corresponding 3 sessions comprise Session:28, Session:14, Session:0 (being session id); After WAP gateway is received the mobile phone request message, from the hash index array, at first find session 28, then this three sessions, 28,14,0 chained list of being formed is searched, for example make sequential search.Search criterion can be the IP address and the port of mobile phone, also can only be the IP address of mobile phone; Because when each mobile phone is reached the standard grade, WAP gateway can distribute a unique IP address for it.If do not find, then create a new session, be linked to session 0 back, form the chained list of 4 elements.
Step 204: after mobile phone and WAP gateway were set up session, mobile phone began and the server swap data, by PULL or PUSH method.Method state machine array index is assigned as method state machine ID, finds state machine ID in the session information array, just can directly find element in the method state machine array.The corresponding a plurality of methods of each session possibility are made sequential search so the identical method state machine element of affiliated session also can be formed chained list.The present invention is to various lookup methods and unrestricted.
Should be understood that, for those of ordinary skills, can be improved according to the above description or conversion, and all these improvement and conversion all should belong to the protection range of claims of the present invention.