Embodiment
Hereinafter also describe the present invention in detail with reference to accompanying drawing in conjunction with the embodiments.It should be noted that, in the situation that not conflicting, the feature in embodiment and embodiment in the application can combine mutually.
Figure 1 shows that the flow chart of the data packet transmission processing method that preferred embodiment according to the present invention provides.As shown in Figure 1, the data packet transmission processing method that preferred embodiment of the present invention provides comprises step 101~103.
In step 101, Socket thread receives pending packet.Particularly, Socket thread receives after the pending packet of user's transmission, take out preliminary treatment thread and carry out subsequent step, and Socket thread returns to the reception task that continues to carry out next pending packet immediately from thread pool.So, improved the receiving efficiency of Socket thread.
In step 102, preliminary treatment thread splices the pending packet that the deficiency of data bag that reads from buffering area and Socket thread receive, scan described splicing packet to judge whether described splicing packet mates specific data structure by regular expression, if the data packet matched specific data structure of described splicing, puts into receiving queue by the complete data packet of coupling.
In the present embodiment, complete packet has specific data structure, and above-mentioned specific data structure comprises data head, data content and data tail.For example, specific data structure starts with " <root ", end up with "/> ", centre is any random length character, as: <root type=' text ' from=' 1 ' to=' 2 ' say=' hello '/>.But the present invention is not limited thereto.In practical application, anyly start and the data structure that ends up all may be defined as specific data structure with corresponding fixed character.
Particularly, preliminary treatment thread is postponed to rush and in district, is taken out deficiency of data bag, then by the pending packet splicing that deficiency of data bag and Socket thread receive, obtains splicing packet.Then,, by regular expression macroscopic view Overlap-scanning packet, judge whether splicing packet comprises the specific data structure that meets " <root.../> ".If splicing packet does not have above-mentioned specific data structure, splicing packet is put into buffering area; If splicing packet has above-mentioned specific data structure, use again regular expression microcosmic Overlap-scanning packet, the packet that is about to meet " <root.../> " specific data structure is put into receiving queue, the packet that does not meet " <root.../> " specific data structure is put into buffering area, wait for data splicing next time.
For example, the pending packet that Socket thread receives is for the first time: <root from=' sam ' to=' sam ' type=' text ' say=' hello '/><root from=' sam '.The pending packet receiving is for the second time: to=' sam ' type=' text ' say=' hello '/><root.The pending packet receiving is for the third time: from=' sam ' to=' sam ' type=' text ' say=' hello '/><root from=' sam ' to=' sam ' type=' text ' say=' hello '/>.
In the present embodiment, Socket thread receives after pending packet for the first time, and preliminary treatment thread can from buffering area, take out deficiency of data bag and described pending packet splices.In this, because buffering area does not initially have packet, therefore the splicing packet that, preliminary treatment thread obtains: <root from=' sam ' to=' sam ' type=' text ' say=' hello '/><rootfrom=' sam '.Then, the above-mentioned splicing packet of regular expression macroscopic view scanning can find to exist the packet " <root from=' sam ' to=' sam ' type=' text ' say=' hello '/> " that meets " <root.../> " data structure, then scan above-mentioned splicing packet with regular expression microcosmic, the complete data packet " <root from=' sam ' to=' sam ' type=' text ' say=' hello '/> " obtaining is put into receiving queue, simultaneously by " <root from=' sam " " put into buffering area.
Then, receive for the second time after pending packet in Socket thread, preliminary treatment thread can take out deficiency of data bag " <root from=' sam " from buffering area ", will after the pending packet splicing of deficiency of data bag and this reception, obtain splicing packet: <root from=' sam ' to=' sam ' type=' text ' say=' hello '/><root.Then, the above-mentioned splicing packet of regular expression macroscopic view scanning, find to exist the packet " <root from=' sam ' to=' sam ' type=' text ' say=' hello '/> " that meets " <root.../> " data structure, then scan above-mentioned splicing packet with regular expression microcosmic, the complete data packet " <root from=' sam ' to=' sam ' type=' text ' say=' hello '/> " obtaining is put into receiving queue, " <root " put into buffering area simultaneously.
Then, receive for the third time after pending packet in Socket thread, preliminary treatment thread is postponed to rush in district and is taken out deficiency of data bag " <root ", will after deficiency of data bag and this pending packet splicing receiving, obtain splicing packet: <rootfrom=' sam ' to=' sam ' type=' text ' say=' hello '/><root from=' sam ' to=' sam ' type=' text ' say=' hello '/>.Then, the above-mentioned splicing packet of regular expression macroscopic view scanning, find to exist the packet " <root from=' sam ' to=' sam ' type=' text ' say=' hello '/><root from=' sam ' to=' sam ' type=' text ' say=' hello '/> " that meets " <root.../> " data structure, then scan above-mentioned splicing packet with regular expression microcosmic, the complete data packet " <rootfrom=' sam ' to=' sam ' type=' text ' say=' hello '/> " " <root from=' sam ' to=' sam ' type=' text ' say=' hello '/> " obtaining is put into receiving queue, empty the deficiency of data bag in buffering area simultaneously.
In step 103, final controlling element is dispatched complete data packet from receiving queue, and calls corresponding thread according to the type of service of complete data packet and process, and wherein, type of service has priority level, and different types of service is by different thread alignment processings.In addition,, in the time that final controlling element detects that the thread of the type of service that processing priority level is higher does not have the free time, final controlling element calls the higher type of service of thread process priority level corresponding to type of service that priority level is lower.And, in this, final controlling element timing detects the actual thread borrowing time of the type of service that priority level is higher, if what actual thread borrowing time was equal to or greater than thread corresponding to type of service that priority level is lower can borrowing time, final controlling element calls idle thread corresponding to type of service that other priority levels are lower and processes the higher type of service of priority level.
Particularly, the table of comparisons that final controlling element storage service type, thread and thread can borrowing times.Described table of comparisons example is as shown in the table.
Wherein, the priority level of above-mentioned four kinds of types of service from height to low order is: login business, publish business, text message transmission business, group message transport service.In addition, the thread a~c in thread pool is preset as the business of logining of processing, and thread d~g is preset as the business of publishing of processing, and thread h~k is preset as the text message transmission business of processing, and thread l~n is preset as and processes group message transport service.Wherein, owing to logining, the priority level of business is the highest, therefore in the time that business is carried out, need first guarantee that it processes, and the thread that therefore set handling is logined business is for using.And, thread borrowing time that can be corresponding different according to the difference that can use number of threads.But the present invention is not limited in any way this.In practical application, can borrowing time can the setting according to actual needs of the thread that different types of service is corresponding and thread.
In the present embodiment, particularly, in the time that final controlling element detects that processing the thread of logining business does not have the free time (, thread a~c is all in running order), final controlling element can call idle thread processing corresponding to type of service that priority level is lower according to priority orders and login business.In this, determine the idle thread of using from low paramount order according to the priority level of other types of service.Because the priority level type of service lower than the business of logining comprises the business of publishing, text message transmission business, group message transport service, therefore the thread of, logining business is used order: group message transport service, text message transmission business, publish business.In other words, first final controlling element can call idle thread processing corresponding to group message transport service and login business, in the case of still cannot meeting the processing demands of the business of logining, then calls successively text message transmission business or idle thread corresponding to the business of publishing.But the present invention is not limited thereto.In practical application, can set according to actual needs thread and use order.
For example, if when thread corresponding to the business of logining do not have the free time, now, if desired process newly while logining business, first final controlling element can call idle thread corresponding to group message transport service.If corresponding thread m, the n of group message transport service is idle, final controlling element separately invokes thread m or thread n process the business of logining, or business is logined in invokes thread m, n processing simultaneously.Known according to the above-mentioned table of comparisons, when the independent invokes thread m of final controlling element or thread n process while logining business, thread m or thread n's can borrowing time be 80s, and in the time that business is logined in final controlling element invokes thread m, n processing simultaneously, thread m, n's can borrowing time be 70s.
Then, login business as example taking final controlling element invokes thread m, n processing simultaneously.Detect if final controlling element carries out timing in the time that beginning thread is used, and be 10s interval time.So, when the actual thread borrowing time of logining business (for example, 70s) equal thread m, n can borrowing time (for example, 70s) time, final controlling element can be regained thread m, n and call idle thread corresponding to type of service that other priority levels are lower.Now, if text message transmission business correspondence exists idle thread, final controlling element can call idle thread processing corresponding to text message transmission business and login business.Use so, as required idle thread corresponding to type of service that priority level is lower until the business of logining does not need thread to use.
In another preferred embodiment, in the time that final controlling element calls the higher type of service of thread process priority level corresponding to type of service that priority level is lower, final controlling element starts timing, and timing be thread corresponding to type of service that priority level is lower can borrowing time, in the time arriving timing, if the higher type of service of priority level is still by thread process corresponding to the lower type of service of priority level, final controlling element calls idle thread corresponding to type of service that other priority levels are lower and processes the type of service that described priority level is higher.
According to the above-mentioned table of comparisons for example, login business as example taking final controlling element invokes thread m, n processing simultaneously.In the time of final controlling element invokes thread m, n, start timing, and timing be thread m, n can borrowing time, for example, 70s.Therefore,, in the time arriving timing, if the business of logining is still processed by thread m, n, final controlling element can be regained thread m, n and call idle thread corresponding to type of service that other priority levels are lower.Now, if text message transmission business correspondence exists idle thread, final controlling element can call idle thread processing corresponding to text message transmission business and login business.Use so, as required idle thread corresponding to type of service that priority level is lower until the business of logining does not need thread to use.
Figure 2 shows that the schematic diagram of the data packet transmission treatment system that preferred embodiment provides according to the present invention.As shown in Figure 2, the data packet transmission treatment system that preferred embodiment of the present invention provides comprises receiving system 20, pretreatment unit 21 and final controlling element 22.Receiving system 21 connects pretreatment unit 21, and pretreatment unit 21 connects final controlling element 22.Wherein, receiving system 20 is for receiving pending packet.The pending packet that pretreatment unit 21 receives for splicing the deficiency of data bag that reads from buffering area and receiving system, and scan described splicing packet to judge whether described splicing packet mates specific data structure by regular expression, if the data packet matched specific data structure of described splicing, puts into receiving queue by the complete data packet of coupling.Final controlling element 22 is for dispatching described complete data packet from described receiving queue, and call corresponding thread according to the type of service of described complete data packet and process, wherein, described type of service has priority level, and different types of service is by different thread alignment processings.About the specific operation process of described system with described in said method, therefore repeat no more in this.
In sum, the data packet transmission processing method that preferred embodiment provides according to the present invention and system, preliminary treatment thread splices the pending packet that the deficiency of data bag that reads from buffering area and Socket thread receive, by regular expression Overlap-scanning packet to judge whether splicing packet mates specific data structure, and the complete data packet that coupling is obtained is put into receiving queue.So, improve subpackage efficiency, prevented that in internal memory, overstocking mass data bag causes communication server collapse.In addition, final controlling element is dispatched complete data packet from receiving queue, and calls corresponding thread according to the type of service of complete data packet and process.So, improved the treatment effeciency of business.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, for a person skilled in the art, the present invention can have various modifications and variations.Within the spirit and principles in the present invention all, any amendment of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.