A kind of AFC (Automatic Fare Collection) data processing method of many queuesTechnical field
The present invention relates to a kind of data processing method of Services in Distributed System device, particularly relate to the many queues AFC (Automatic Fare Collection) data processing method in a kind of AFC system.
Background technology
In the AFC system of subway station, equipment and station computer form a closed distributed system, all devices is sent to station computer the AFC (Automatic Fare Collection) data produced at any time by network and processes in real time, and feed back to station operating personnel in time, complete information sharing and monitoring.The efficiency of AFC system data processing is normal to station, high-efficiency operation is most important.
Along with subway business development, traditional AFC (Automatic Fare Collection) data processing method cannot meet flexible, a large amount of data handling requirements.Its reason is: first, and in subway line, the scale of each website is inconsistent, causes the data volume of the station computer process of each website not identical; Secondly, along with updating of subway business, traffic data type constantly changes, and the data volume that equipment produces is also in continuous growth.As by increasing the change of number of computers reply data volume, so hardware input cost and the software development and design cost for multiple stage computing machine all higher, and computer hardware performance upgrades and promotes very fast, makes later stage HardwareUpgring cost higher.Therefore under former mentality of designing, traditional automatic ticketing data processing method cannot give full play to and use active computer hardware resource, brings adverse effect to the effective use of hardware resource and ticket sale system, and causes the larger wasting of resources.
How to make that existing AFC system is formed efficiently, low cost, easily flexible running status, improve data handling procedure, just become the problem that the present invention wants to solve.
Summary of the invention
In view of above-mentioned the deficiencies in the prior art, the present invention aims to provide a kind of AFC (Automatic Fare Collection) data processing method of many queues, for computer equipment provides the low cost expansion scheme of software view, on the basis of guaranteeing data-handling efficiency, the phenomenon realizing reply AFC system data volume and constantly change is calculated, to meet operation, the regulatory requirement at AFC (Automatic Fare Collection) station by configuration.
The present invention is achieved by the following technical solutions:
An AFC (Automatic Fare Collection) data processing method for many queues, it is characterized in that, concrete steps comprise:
Step one, first to set up in computer equipment data handling procedure: one-level queue and dispatch thread pond, and secondary queue and the business processing thread pool corresponding with secondary queue.
Step 2, utilize the real time data bag of described one-level queue receiving front-end station equipment, simultaneously, one-level queue also provides blocking mechanism to use the CPU of computer equipment, detailed process is: as described in there is no data in one-level queue, thread in described dispatch thread pond can block when obtaining data, until just continue after obtaining data to perform; As described in after data packet number reaches the upper limit in one-level queue, no longer will receive packet.
Step 3, obtain data by described dispatch thread pond from described one-level queue, resolution data bag also puts into described secondary queue after judging type.
Step 4, described secondary queue receive the packet meeting preset kind from described dispatch thread pond, simultaneously, secondary queue also provides blocking mechanism to use the CPU of computer equipment, detailed process is: as described in there is no data in secondary queue, thread in corresponding business processing thread pool can block when obtaining data, until just continue after obtaining data to perform; As described in after data packet number reaches the upper limit in secondary queue, dispatch thread pond can obstruction be sent stored in during data, until etc. just continue to perform after success to be deposited.
The packet that step 5, described business processing thread pool obtain from the described secondary queue of correspondence carries out business processing, completes data handling procedure.
If packet requires to return, then the packet that the data assembling completed business processing returns, and is sent back to by network service.
The quantity in described one-level queue and dispatch thread pond is respectively one, and the thread in dispatch thread pond performs with concurrent or parallel mode.
The quantity of described secondary queue is one or more; The quantity of described business processing thread pool and one_to_one corresponding identical with described secondary queue quantity, corresponding business processing thread pool is only responsible for the data in secondary queue corresponding to process one; The thread of described business processing thread pool performs with concurrent or parallel mode.
The capacity of described one-level queue and the capacity of secondary queue calculate from corresponding computer equipment memory size and anticipatory data bag treatment capacity respectively, and formula is as follows:
Wherein, N is the number of secondary queue, DT1... DTnfor the data number of each queue expection process per second, PM expects the size of every bar data, and TM is computer equipment memory size, and FQ is one-level queue assignment size, SQiit is the allocated size of i-th secondary queue.
Described dispatch thread pond thread quantity and described business processing thread pool thread quantity calculate from the CPU quantity of computer equipment and anticipatory data bag treatment effeciency respectively, and formula is as follows:
Wherein N is the number of secondary queue, DT1... DTnfor the data number of each queue expection process per second, UT is CPU sum in computer equipment, and FT is the number of threads that dispatch thread pond is distributed, STibe i-th secondary queue business processing thread pool thread quantity allotted.
Thread in thread in described dispatch thread pond and described business processing thread pool, as in the computer equipment of single cpu, thread performs with concurrent fashion; As in the computer equipment of multiple CPU, thread performs with parallel or concurrent fashion.
Described computer equipment comprises personal computer, server or other network equipment.
As can be seen from the above scheme, the capacity of one-level queue and secondary queue in the present invention, and dispatch thread pond and business processing thread pool can change flexibly for data volume and hardware configuration.When data volume changes, without the need to Adjustable calculation machine quantity or amendment Software for Design, self rapid adjustment can be made, meet the needs of communication transfer, not only save hardware and software cost, also solve AFC (Automatic Fare Collection) data volume and change the difficult problem brought, concrete beneficial effect comprises:
(1) be convenient to dispose, be easy to realize, effectively reduce costs
The present invention adopts the mode of software merit rating to meet the processing requirements of elastic traffic amount, dropping into or change Software for Design, reducing the cost when increase of reply portfolio or business change without the need to increasing hardware.
(2) applied range
The service end data processing of distributed system under LAN (Local Area Network) state can be widely used in.
(3) data-handling efficiency is high
Adopt the concurrent or parallel mode of multiple thread to carry out AFC (Automatic Fare Collection) Data dissemination and process, speed is fast, and data-handling efficiency can meet business need completely.
Accompanying drawing explanation
Fig. 1 is the AFC (Automatic Fare Collection) data processing method structural representation of a kind of many queues of the present invention;
Fig. 2 is the Data dissemination schematic flow sheet of the AFC (Automatic Fare Collection) data processing method of a kind of many queues of the present invention;
Fig. 3 is the flow chart of data processing schematic diagram of the AFC (Automatic Fare Collection) data processing method of a kind of many queues of the present invention.
Embodiment
Below in conjunction with the drawings and specific embodiments, the present invention is described in further detail:
The AFC (Automatic Fare Collection) data processing method of a kind of many queues of the present invention, concrete steps comprise:
Step S100, in the data handling procedure of computer equipment, first set up one-level queue and dispatch thread pond, and secondary queue and the business processing thread pool corresponding with secondary queue.
Computer equipment can be personal computer, server or other network equipment, in present embodiment, as shown in Figure 1, the quantity in one-level queue 1 and dispatch thread pond 2 is respectively one, the quantity of secondary queue 3 is two, the quantity of business processing thread pool 4 is identical with secondary queue 3 quantity and form annexation one to one, that is, the data in the secondary queue 3 that the responsible process of corresponding business processing thread pool 4 is corresponding.In the computer equipment of single cpu, the thread in dispatch thread pond 2 and the thread of business processing thread pool 4 perform with concurrent fashion respectively; And in the computer equipment of multiple CPU, the thread in dispatch thread pond 2 and the thread of business processing thread pool 4 then perform with parallel or concurrent fashion.
Then, as shown in Figure 2, one-level queue AFC (Automatic Fare Collection) Data dissemination flow process is as follows:
Step S101, utilize one-level queue to receive the real time data bag of station equipment, namely receive AFC (Automatic Fare Collection) data by network service thread, attempt stored in one-level queue.
Step S102, judge in one-level queue, whether AFC (Automatic Fare Collection) quantity reaches the upper limit, if then perform S101, continue to attempt stored in one-level queue; Otherwise perform S103.
Step S103, AFC (Automatic Fare Collection) data are stored in one-level queue.
Whether there are the pending datas such as thread block in step S104, dispatch thread pond, if having, perform S107, otherwise perform S105.
Step S105, dispatch thread pond thread are attempted obtaining AFC (Automatic Fare Collection) data from one-level queue.
Step S106, judge that whether one-level queue is empty, if then perform S107, otherwise perform S108.
Attempt the thread block obtaining AFC (Automatic Fare Collection) data in step S107, dispatch thread pond, wait in one-level queue and have data to perform stored in rear continuation.
Step S108, dispatch thread pond thread gets AFC (Automatic Fare Collection) data, and resolution data bag puts into corresponding secondary queue according to type.
Again then, as shown in Figure 3, described secondary AFC (Automatic Fare Collection) flow chart of data processing is as follows:
Step S201, above-mentioned dispatch thread pond thread are attempted to secondary queue stored in AFC (Automatic Fare Collection) data.
Step S202, judge whether have the pending datas such as thread block in processing threads pond, if having, perform S208, wait for secondary queue data stored in; Otherwise perform S203.
In step S203, secondary queue, whether AFC (Automatic Fare Collection) data reach the upper limit, if then perform S204, otherwise perform S205.
Attempt the thread block stored in AFC (Automatic Fare Collection) data in step S204, dispatch thread pond, wait for and continue to perform after having living space in secondary queue.
Step S205, AFC (Automatic Fare Collection) data are stored in secondary queue.
Step S206, business processing thread pool thread are attempted obtaining AFC (Automatic Fare Collection) data from secondary queue.
Whether step S207, secondary queue are empty, if then perform S208, otherwise perform S209.
Attempt the thread block obtaining AFC (Automatic Fare Collection) data in step S208, business processing thread pool, wait in secondary queue and continue to perform after having data.
Step S209, business processing thread pool thread are got AFC (Automatic Fare Collection) data and are processed.
Whether have obstruction thread in step S210, dispatch thread pond, if having, perform S204, otherwise this process terminates.
In said process, the capacity of one-level queue and the capacity of secondary queue calculate from corresponding computer equipment memory size and anticipatory data bag treatment capacity respectively, and formula is as follows:
Wherein, N is the number of secondary queue, DT1... DTnfor the data number of each queue expection process per second, PM expects the size of every bar data, and TM is computer equipment memory size, and FQ is one-level queue assignment size, SQiit is the allocated size of i-th secondary queue.
And dispatch thread pond thread quantity and business processing thread pool thread quantity calculate from the CPU quantity of computer equipment and anticipatory data bag treatment effeciency respectively, formula is as follows:
Wherein N is the number of secondary queue, DT1... DTnfor the data number of each queue expection process per second, UT is CPU sum in computer equipment, and FT is the number of threads that dispatch thread pond is distributed, STibe i-th secondary queue business processing thread pool thread quantity allotted.
Certainly, after information processing completes, if packet requires to return, then the packet that the data assembling completed business processing returns, and sent back to by network service.
By the description of above implementation process, those skilled in the art can be well understood to the realization of the present invention at software view.Based on such understanding, technical scheme of the present invention embodies with the form of software product in essence or to the contribution of prior art, this computer software product is stored in a storage medium, comprises all or part of step of some instructions in order to make a computer equipment perform method described in each embodiment of the present invention.And aforesaid storage medium comprises: ROM (read-only memory) (ROM), random access memory (RAM), magnetic disc or CD etc. various can be program code stored medium.
Obviously, said process is only a specific embodiment of the present invention, instead of whole embodiments.Based on the content that the present invention describes, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.