CN106155794A - A kind of event dispatcher method being applied in multi-threaded system and device - Google Patents
A kind of event dispatcher method being applied in multi-threaded system and device Download PDFInfo
- Publication number
- CN106155794A CN106155794A CN201610579344.1A CN201610579344A CN106155794A CN 106155794 A CN106155794 A CN 106155794A CN 201610579344 A CN201610579344 A CN 201610579344A CN 106155794 A CN106155794 A CN 106155794A
- Authority
- CN
- China
- Prior art keywords
- event
- serialization
- queue
- buffer zone
- group
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/4881—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5083—Techniques for rebalancing the load in a distributed system
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Memory System Of A Hierarchy Structure (AREA)
Abstract
The present invention relates to communication technical field, particularly relate to a kind of event dispatcher method being applied in multi-threaded system and device, load balancing and the problem avoiding resource contention cannot be realized present in prior art in order to solving simultaneously.In the present embodiment, when detecting that any one event is triggered, if event is correlating event, whether then need is the first event being triggered and the buffer status of corresponding serialization buffer zone and duty in affiliated serialization event group according to this event, determine to carry out caching or being assigned directly to the head of the queue of event queue or be assigned to the tail of the queue of event queue by this event, if this event is independent event, then this event is assigned directly to the tail of the queue of event queue, to wait by corresponding thread dispatching.Thus so that each event can be dispatched by equilibrium assignment, it is ensured that load equilibrium, and so that serialization event can perform according to service logic relation serialization, it is to avoid resource contention.
Description
Technical field
The present invention relates to communication technical field, particularly relate to a kind of event dispatcher method being applied in multi-threaded system and
Device.
Background technology
Along with the development of computer multi-core technology, people are increasingly using Mutli-thread Programming Technology and give full play to
The performance of CPU.In existing multi-threaded system, in order to ensure the load balancing of CPU, business is cut into the list of smaller particle size
Position, such as, perform in units of event in thread.
In existing multi-threaded system, event allocation strategy specifically includes that static binding distribution and dynamic binding distribution;Its
In:
With reference to shown in Fig. 1 (a), for the event distribution principle model schematic that the static binding method of salary distribution is corresponding, the most in advance
The event relevant by same or same group of resource and the thread binding specified, the event making these resources relevant operates in same
In individual thread.It is visible, by event makes by the way of thread static binding the event that same resource is relevant be able to serialization
Perform, solve and there is the event of service logic and need serialization to perform and the resource competing problem that produces.But, by event with
After thread static binding, owing to the operand of different event is different, sheer loads equilibrium between thread, cannot be realized, and
And due to the impact of service logic, the concurrency between CPU also can be by a certain degree of impact.For example, event A, B, C, D
Four event bindings are on same thread S1, and current event A is processed;If there is service logic in event B and event A
(i.e. needing and the serial of event A), then event B needs to wait in line;Event C and event D do not have any service logic to close with event A
Connection, can be instantly available process the most completely on other the most idle thread, but, actually event C and event D is also same
Sample needs to wait in line to be performed by thread S1.Analyze accordingly and learn, owing to number of threads is for the impact of systematic function, in system
The impossible infinite extension of the quantity of thread, in the case of ensureing that the event that resource is relevant is all bound to same thread, some
The incoherent event of resource (the most above-mentioned event C does not exist service logic with event D with event A and associates) also can each other
It is bound to same thread.Simultaneously as cross-thread does not has absolute load balancing, it is possible to occur that a thread is the most idle
Time, some events that should be performed but carry out unnecessary waiting in line and can not get performing on another thread.
With reference to shown in Fig. 1 (b), for the event distribution principle model schematic that the dynamic binding method of salary distribution is corresponding, the program
Have employed event and the mode of thread dynamic binding, event is held by random being assigned on thread by the way of waiting in line
OK, solve the problem of load balancing between thread, maximize and improve running efficiency of system.But, event and thread are dynamic
The mode of binding may make event that some resources are relevant (i.e. there is service logic association and the thing that needs serialization to perform
Part) it is dispatched in different threads perform, when these events are performed simultaneously in different threads, resource will be produced
Competition, thus increase exploitation complexity.
In sum, either static binding allocative decision or dynamic binding allocative decision, all cannot realize line simultaneously
The load balancing of journey and avoid the purpose of resource contention, therefore, needs badly and finds one to be preferably applied in multi-threaded system
Event allocative decision.
Summary of the invention
The embodiment of the present invention provides a kind of event dispatcher method being applied in multi-threaded system and device, existing in order to solve
Have present in technology and cannot realize load balancing and the problem avoiding resource contention simultaneously.
The embodiment of the present invention is by the following technical solutions:
A kind of event dispatcher method being applied in multi-threaded system, described method includes:
When detecting that any one event is triggered, it is judged that whether described event is correlating event;
If correlating event, it is judged that whether described event is the first event being triggered in affiliated serialization event group;
If the first event being triggered, then described event is assigned to the tail of the queue of event queue, if the non-first event being triggered,
Then when be cached with described event belonging to the event of same serialization event group, and/or, event queue or thread have with described
When belonging to event, the event of same serialization event group is scheduled, by described event buffer, when being buffered in described event
Before caching and with described event belonging to after the event of same serialization event group has been scheduled, described event is assigned to
The head of the queue of described event queue, otherwise, is assigned directly to the head of the queue of described event queue by described event;
If independent event, described event is assigned directly to the tail of the queue of described event queue, to wait by corresponding line
Journey is called.
Alternatively, it is judged that whether described event is correlating event, specifically includes:
Inquire about the mark whether recording described event in each serialization buffer zone successively, if successful inquiring, the most really
Fixed described event is correlating event, and the serialization event corresponding with the serialization buffer zone recording the mark having described event
Group is associated, otherwise, it determines described event is independent event.
Alternatively, described serialization buffer zone creates in the following manner:
Analyze the service logic relation between each event in event sets to be allocated, same service logic relation will be there is
Each event correlation in same serialization event group;
A serialization buffer zone therewith with one-to-one relationship is created for each serialization event group;
Wherein, in described serialization buffer zone record have have therewith in the serialization event group of one-to-one relationship each
The mark of individual event;Any one event in the serialization event group that described serialization buffer zone is corresponding is from being assigned to described thing
Part queue starts to by thread to have performed, and described serialization buffer zone is in running order, and otherwise, described serialization caches
Region is in resting state.
Alternatively, it is judged that whether described event is the first event being triggered in affiliated serialization event group, specifically wraps
Include:
Inquire about in the serialization buffer zone belonging to described event and whether have distribution labelling, if there being distribution labelling, then it represents that
Described event is the non-first event being triggered in the serialization event group that described serialization buffer zone is corresponding, if not distribution
Labelling, then it represents that described event is the first event being triggered in the serialization event group that described serialization buffer zone is corresponding.
Alternatively, described event is cached, before being buffered in described event caching and with described event belonging to
After whole events of same serialization event group have been scheduled, described event is assigned to the head of the queue of event queue, specifically
Including:
By described event buffer to the serialization buffer zone corresponding with the serialization event group belonging to described event;
Do not store described in described serialization buffer zone is in resting state and described serialization buffer zone
When carrying out, before the moment that event is buffered, the event cached, described event is assigned to the head of the queue of described event queue.
A kind of event distributor being applied in multi-threaded system, including:
Judging unit, for when detecting that any one event is triggered, it is judged that whether described event is correlating event;With
And, after described judging unit judges that described event is correlating event, determine whether whether described event is affiliated serial
Change the first event being triggered in event group;And, judge that described event is the non-first thing being triggered at described judging unit
During part, further determine whether to be cached with described event belonging to the event of same serialization event group, and event queue
Or whether thread has with described event belonging to the event of same serialization event group be scheduled;
Processing unit, for when described judging unit judges that described event is independent event, directly divides described event
It is fitted on the tail of the queue of event queue, to wait by corresponding thread dispatching;And, for judging described event at described judging unit
During for the first event being triggered, described event is assigned to the tail of the queue of described event queue;And, for judging list described
Unit judges that described event is the non-first event being triggered, and be cached with described event belonging to the thing of same serialization event group
Part, and/or, event queue or thread have with described event belonging to the event of same serialization event group be scheduled time,
By described event buffer, before being buffered in described event caching and with described event belonging to same serialization event group complete
After portion's event has been scheduled, described event is assigned to the head of the queue of event queue;And, for sentencing at described judging unit
Disconnected described event is the non-first event being triggered, and uncached have with described event belonging to the thing of same serialization event group
In part, and event queue or thread not with described event belonging to the event of same serialization event group be scheduled time,
Described event is assigned directly to the head of the queue of described event queue.
Alternatively, described judging unit when judging whether described event is correlating event, specifically for:
Inquire about the mark whether recording described event in each serialization buffer zone successively, if successful inquiring, the most really
Fixed described event is correlating event, and the serialization event corresponding with the serialization buffer zone recording the mark having described event
Group is associated, otherwise, it determines described event is independent event.
Alternatively, described serialization buffer zone creates in the following manner:
Analyze the service logic relation between each event in event sets to be allocated, same service logic relation will be there is
Each event correlation in same serialization event group;
A serialization buffer zone therewith with one-to-one relationship is created for each serialization event group;
Wherein, in described serialization buffer zone record have have therewith in the serialization event group of one-to-one relationship each
The mark of individual event;Any one event in the serialization event group that described serialization buffer zone is corresponding is from being assigned to described thing
Part queue starts to by thread to have performed, and described serialization buffer zone is in running order, and otherwise, described serialization caches
Region is in resting state.
Alternatively, described judging unit is judging whether described event is first in affiliated serialization event group being triggered
Event time, specifically for:
Inquire about in the serialization buffer zone belonging to described event and whether have distribution labelling, if there being distribution labelling, then it represents that
Described event is not the first event being triggered in the serialization event group that described serialization buffer zone is corresponding, if not dividing
Join labelling, then it represents that described event is the first thing being triggered in the serialization event group that described serialization buffer zone is corresponding
Part.
Alternatively, described event is being cached by described processing unit, before being buffered in described event caching and
With described event belonging to after whole events of same serialization event group have been scheduled, described event is assigned to event team
During the head of the queue arranged, specifically for:
By described event buffer to the serialization buffer zone corresponding with the serialization event group belonging to described event;
Do not store described in described serialization buffer zone is in resting state and described serialization buffer zone
When carrying out, before the moment that event is buffered, the event cached, described event is assigned to the head of the queue of described event queue.
In the event allocative decision that the embodiment of the present invention is applied in multi-threaded system, based on the event team under dynamic binding
Row wait in line distribution mechanism, there is same service logic by being pre-created in multi-threaded system for controlling, cache
The serialization buffer zone of the event of relation, when detecting that any one event is triggered, first, it is determined that whether this event is association
Event, if correlating event, it is judged that whether this event is the first event being triggered in affiliated serialization event group, if headed by
The individual event being triggered, then be assigned to the tail of the queue of event queue by event, allows this event wait in line by phase in event queue
Idle thread is answered to call;If the non-first event being triggered, then when be cached with described event belonging to same serialization event
The event of group, and/or, event queue or thread have with described event belonging to the event of same serialization event group adjusted
When spending, show current there is with this event the just queuing or just in thread in event queue of event that serializing logic associates
Called, in order to ensure, when serialization performs, resource contention to occur, need this event buffer, when being buffered it in event
Front caching and with this event belonging to after the event of same serialization event group has been scheduled, event is assigned to event queue
Head of the queue be called with serialized order as early as possible so that belonging to the event of same serialization event group;If event is non-head
The individual event being triggered, and uncached have with event belonging to the event of same serialization event group, and event queue or thread
In not with event belonging to the event of same serialization event group be scheduled, now, showed before this event is scheduled
All events be scheduled, this event is without being buffered wait, but is directly assigned to the head of the queue of event queue,
If not associating, showing that this event is independent event, this event is assigned directly to the tail of the queue of event queue, to wait by accordingly
Thread dispatching.Distribution mechanism is waited in line, by multithreading system owing to the program is based on the event queue under dynamic binding
System is pre-created for controlling, cache the serialization buffer zone with the event of same service logic relation so that each
The allocation schedule that event can be equalized, it is ensured that the harmony of load, and so that serialization event can be patrolled according to business
Volume relation serialization performs, it is to avoid the competition of resource in multi-threaded system, effectively reduces the complexity of programming, improves and hold
Line efficiency.
Accompanying drawing explanation
For the technical scheme being illustrated more clearly that in the embodiment of the present invention, in embodiment being described below required for make
Accompanying drawing briefly introduce, it should be apparent that, below describe in accompanying drawing be only some embodiments of the present invention, for this
From the point of view of the those of ordinary skill in field, on the premise of not paying creative work, it is also possible to obtain it according to these accompanying drawings
His accompanying drawing.
Fig. 1 (a) is the event distribution principle model schematic that the static binding method of salary distribution is corresponding;
Fig. 1 (b) is the event distribution principle model schematic that the dynamic binding method of salary distribution is corresponding;
Fig. 2 is the event distribution principle model schematic involved by the embodiment of the present invention;
The flow chart of steps of the event dispatcher method being applied in multi-threaded system that Fig. 3 provides for the present invention;
Event distribution schematic diagram involved by the instantiation that Fig. 4 provides for the present invention.
The event distributor structural representation being applied in multi-threaded system that Fig. 5 provides for the present invention.
Detailed description of the invention
In order to make the object, technical solutions and advantages of the present invention clearer, below in conjunction with accompanying drawing the present invention made into
One step ground describes in detail, it is clear that described embodiment is only a part of embodiment of the present invention rather than whole enforcement
Example.Based on the embodiment in the present invention, those of ordinary skill in the art are obtained under not making creative work premise
All other embodiments, broadly fall into the scope of protection of the invention.
First, introduce the application scenarios that the scheme involved by the embodiment of the present invention is suitable for, with reference to shown in Fig. 2, to be allocated
Multiple event concurrency arrangement wait in event sets is triggered, and the sequencing that considered critical is not triggered, permissible
It is to trigger any one event at random.After these events are triggered, it is necessary to just can be assigned to the thread of free time through event queue
Perform.Additionally, the present invention is different from prior art, the space beyond the memory area of event queue place, it is pre-created
Serialization buffer zone, for being controlled distribution to the event of described same serialization event group, to realize load balancing
Simultaneously, it is to avoid resource contention.
Below by specific embodiment, technical scheme involved in the present invention is described in detail, the present invention include but
It is not limited to following example.
As it is shown on figure 3, be the step of a kind of event dispatcher method being applied in multi-threaded system in the embodiment of the present invention
Flow chart, the method mainly comprises the steps that
Step 31: when detecting that any one event is triggered, it is judged that whether described event is correlating event;If association thing
Part, then perform step 32, otherwise, jump to step 33.
Alternatively, in the step 31 of the embodiment of the present invention, it is judged that whether described event is correlating event, specifically performs
For: inquire about the mark whether recording described event in each serialization buffer zone successively, if successful inquiring, it is determined that described
Event is correlating event, and the serialization event group having the serialization buffer zone of mark of described event corresponding to record is relevant
Connection, otherwise, it determines described event is independent event.
Step 32: judge whether this event is the first event being triggered in affiliated serialization event group, if first
The event being triggered, then perform step 33, otherwise, perform step 34.
Alternatively, in the step 32 of the embodiment of the present invention, it is judged that whether this event is described serialization buffer zone pair
The first event being triggered in the serialization event group answered, whether concrete execution is: inquire about in described serialization buffer zone and have
Distribution labelling, if there being distribution labelling, then it represents that described event is not the serialization event that described serialization buffer zone is corresponding
The first event being triggered in group, if not distributing labelling, then it represents that described event is that described serialization buffer zone is corresponding
The first event being triggered in serialization event group.For example, it is possible to while serialization buffer zone creates, generate one point
Assortment table, if corresponding event is assigned to event queue, then to should the position of event generating forever in this distribution list
The distribution labelling of property.This distribution is marked at the when of creating new serialization buffer zone next time just can be together with the serial at its place
Change buffer zone be eliminated together or replace.
Step 33: described event is assigned directly to the tail of the queue of event queue, is called by its respective thread to wait.
Step 34: judge whether to meet: be cached with this event belonging to the event of same serialization event group, and/or, thing
Part queue or thread have with described event belonging to the event of same serialization event group be scheduled, if meeting, then perform
Step 35, otherwise, performs step 36.
Specifically, can be by serialization buffer zone corresponding to same serialization event group belonging to inquiry and this event
Whether have with this event belonging to the event of same serialization event group, if having, the most whether event queue or thread have with
Belonging to this event, the event of same serialization event group is scheduled, and is required for performing step 35;Furthermore it is possible to by inquiry
With this event belonging to the state of serialization buffer zone corresponding to same serialization event group, if duty, no matter this string
Whether rowization buffer zone stores event, has been required for performing step 35;Only meet above-mentioned two condition when simultaneously, i.e. do not have
Have be cached with this event belonging in the event of same serialization event group, and event queue or thread not and described event institute
The event belonging to same serialization event group is scheduled, and just needs to perform step 36.
Step 35: by described event buffer, before being buffered in described event caching and with described event belonging to same
After the event of serialization event group has been scheduled, described event is assigned to the head of the queue of described event queue.
Wherein, this step 35 specifically perform be: by described event buffer to the serialization event group belonging to described event
Corresponding serialization buffer zone;In described serialization buffer zone is in resting state and described serialization buffer zone not
Storage has when carrying out, before the moment that described event is buffered, the event cached, and described event is assigned to described event queue
Head of the queue.
Step 36: described event is assigned directly to the head of the queue of described event queue.
Alternatively, in embodiments of the present invention, serialization buffer zone can create in the following manner: analyzes to be allocated
Service logic relation between each event in event sets, and multiple event correlations of same service logic relation will be there are extremely
In one serialization event group;A serialization caching therewith with one-to-one relationship is created for each serialization event group
Region;Wherein, any one event in the serialization event group that described serialization buffer zone is corresponding is from being assigned to described event
Queue starts to by thread to have performed, and described serialization buffer zone is in running order;When described serialization buffer zone
When not having event to be performed by thread in corresponding serialization event group, described serialization buffer zone is in resting state.
In scheme involved in the present invention, after creating serialization buffer zone, needs will delay with each serialization
Deposit event and the foundation association of corresponding serialization buffer zone, tool that region has in the serialization event group of one-to-one relationship
Body ground can be by the way of in event registration to serialization buffer zone or by recording serialization buffer area in event
The mode of the mark in territory realizes.
It is assumed that event sets to be allocated comprises event a, event b, event c, event d and event e, however, it is determined that event a
And there is between event b service logic relation 1, there is between event c and event d service logic relation 2, event e and other
Service logic relation is not had between event, then, it may be determined that event a and event b are a serialization event group, event c
It is another serialization event group with event d.User can create serialization delay according to the establishment mode of serialization buffer zone
Deposit region 1 and serialization buffer zone 2, and event a and event b are registered in serialization buffer zone 1, by event c and thing
Part d is registered in serialization buffer zone 2.According to the mode of registration, then serialization buffer zone 1 can record respectively busy
Part a and the mark of event b, or to event a, attribute information that event b is relevant;Serialization buffer zone 2 also can be remembered accordingly
Record has a mark of time c and event d, or to event c, attribute information that event d is relevant.Additionally, user can also pass through
There is the mark recording serialization buffer zone 1 in event a of one-to-one relationship and event b respectively with serialization buffer zone 1
Know, and in event c with serialization buffer zone 2 with one-to-one relationship and event d, record serialization caching respectively
The mark in region 2.
It should be noted that the foundation of the establishment of above serialization buffer zone and incidence relation all occurs to be allocated
Before event in event sets is triggered, its concrete implementation mode can be artificial setting, it is also possible to by implanting
Algorithm is arranged automatically, and this is not specifically limited by the present invention.
Additionally, in embodiments of the present invention, when the being associated property of event being triggered is judged, except mentioned above
Outside mode, it is also possible to be accomplished by:
After creating serialization buffer zone, each event that there is same service logic relation has recorded respectively accordingly
The mark of serialization buffer zone;So, step 31 specifically can perform be: inquire about and whether this event recorded arbitrary serial
Change buffer zone mark, if successful inquiring, it is determined that this event is correlating event, and with the serial belonging to the mark inquired
The serialization event group changing buffer zone corresponding is associated, otherwise, it determines this event is independent event.
Below by way of concrete example, event allocative decision involved in the present invention is described in detail.
With reference to shown in Fig. 4, it is assumed that current event sets to be allocated has 7 events be in state to be allocated, i.e. wait tune
Degree.Wherein, event A, event B and event C have association in service logic, need to be serialized execution, event D and event E
In service logic, there is another association, it is also desirable to be serialized execution, it should be noted that event A, event B, event C
As a serialization event group and event D, event E as there is no serialization requirement between a serialization event group, and thing
All do not have service logic to associate between other any events in part F and this event sets to be allocated, therefore, there is no need to arbitrary
Event serialization performs.Therefore, dual serial buffer zone can be created according to analysis result, by event A event B and event C
Identification record in serialization buffer zone 3, by the identification record of event D and event E to serialization buffer zone 4.
When system call brings into operation, it is specifically described with following example:
Example 1: the event A of detecting is triggered, by the way of inquiring about the mark recorded in each serialization buffer zone
Determine that this event A is relevant with serialization buffer zone 1, first, in the serialization buffer zone 1 belonging to query event A whether
Having distribution labelling, Query Result is nothing, determines that this event A is the first event being triggered in affiliated serialization event group.That
, can directly this event A be assigned to the tail of the queue of event queue, if this queue does not now have other events, this event A can
Directly to be called execution by corresponding idle thread, otherwise, need to wait in line.
It should be noted that serialization buffer zone 1 is assigned to event queue in event A initially enters duty,
Till this event A has been performed by its respective thread.When serialization buffer zone 1 is in running order, if with this serial
After other events in addition to event A of changing in the serialization event group of buffer zone 1 correspondence are triggered, all cannot directly be distributed
To event queue, but it is medium to be dispensed to need to be cached to this serialization buffer zone 1.
Example 2: execution based on above-mentioned example 1, subsequent detection is triggered to event B, and determine this event B also with serial
Changing buffer zone 1 relevant, before this, only event A is triggered, and has been assigned in event queue wait by thread
Call execution, therefore, serialization buffer zone 1 do not cache other events, then, can be according to the distribution mark inquired
Note (after each event being buffered is assigned to event queue, will be made to distribute in corresponding serialization buffer zone
Labelling, represents that this event was the most once buffered in this space and had been assigned to event queue or by thread dispatching),
Determine this event be not serialization buffer zone 1 correspondence serialization event group in the first event being triggered;Inspection further
Survey this serialization buffer zone 1 the most in running order, if in running order, represent that now event A is also in waiting quilt
Performing or be performed, event B can not be assigned directly in event queue that (and all events involved in the present invention are required for
Queuing through event queue just can be called execution by its respective thread), can only be cached in serialization buffer zone 1;If
It is in resting state, represents that now event A has had been carried out, then, further in detection serialization buffer zone 1 whether
Also it is cached with other events, it is clear that do not have, then event B can be assigned directly to the head of the queue of event queue, in order to belong to same
The event of one serialization event group can be performed in serialized mode as early as possible.
Example 3: based on example 2, then, the event C of detecting is triggered, and determine this event C also with serialization buffer area
Territory 1 is relevant, and in fact, each event is performed required time uncertain, therefore, after event C is triggered, needs first to examine
Survey in serialization buffer zone 1 and whether be cached with event, if the event of being cached with, then show current time to have therewith there is business to patrol
The event of the relation of collecting is performed, and has the event therewith with service logic relation to be buffered in serialization buffer zone 1, should
Event C needs to be cached in serialization buffer zone 1, and to be dispensed according to the order etc. entering this serialization buffer zone 1.
Such as, if this serialization buffer zone 1 is cached with event B, then after event A has performed, this serialization buffer zone 1
Switch to resting state, can be by the head of the queue of event B distribution to event queue, to ensure that this event B has performed it in event A
After can be performed by its respective thread in time, as far as possible reduce event B delay perform, and event C need performed in event B
Afterwards, when i.e. serialization buffer zone 1 switches to resting state next time, just can be assigned to the head of the queue of event queue;If
Uncached have event, then can perform according to the scheme in example 2, not repeat at this.
At this it should be noted that based on example 1 or example 2 or example 3, the event D of detecting is triggered, and determines this thing
Part D is relevant with serialization buffer zone 2, then, this event D can be carried out according to the method for salary distribution of above-mentioned event A, each serial
The dispatching distribution scheme changed between buffer zone does not influence each other, and each performs according to the above-mentioned scheme related to.And for
Event F that serialization buffer zone is unconnected, then be directly assigned to the tail of the queue of event queue by this event F, to wait by phase
Thread scheduling is answered to perform.So circulation so that the event very first time required without serialization obtains scheduling execution to ensure
Event execution efficiency, meanwhile, has the event of serialization requirement to be able to serialization in the case of without other synchronization mechanisms and performs,
Avoid resource contention.
By above-mentioned involved embodiment, the present invention is based on the event queue under dynamic binding to be waited in line point
Join mechanism, by being pre-created in multi-threaded system for controlling, cache the string with the event of same service logic relation
Rowization buffer zone so that the allocation schedule that each event can be equalized, it is ensured that the harmony of load, and so that string
Row event can perform according to service logic relation serialization, it is to avoid the competition of resource in multi-threaded system, effectively reduces
The complexity of programming, improves execution efficiency.
Same inventive concept is belonged to a kind of event dispatcher method being applied in multi-threaded system of above-mentioned offer, this
Bright embodiment additionally provides a kind of event distributor being applied in multi-threaded system.
As it is shown in figure 5, the event distributor structure being applied in multi-threaded system for embodiment of the present invention offer is shown
Being intended to, this device specifically includes that
Judging unit 51, for when detecting that any one event is triggered, it is judged that whether described event is correlating event;With
And, after described judging unit judges that described event is correlating event, determine whether whether described event is affiliated serial
Change the first event being triggered in event group;And, judge that described event is the non-first thing being triggered at described judging unit
During part, further determine whether to be cached with described event belonging to the event of same serialization event group, and event queue
Or whether thread has with described event belonging to the event of same serialization event group be scheduled;
Processing unit 52, for when judging unit 51 judges that event is independent event, is assigned directly to event by event
The tail of the queue of queue, to wait by corresponding thread dispatching;And, for judging that event is first being triggered at judging unit 51
During event, event is assigned to the tail of the queue of event queue;And, for judging that event is non-first is triggered at judging unit 51
Event, and be cached with event belonging to the event of same serialization event group, and/or, event queue or thread have and thing
When belonging to part, the event of same serialization event group is scheduled, by event buffer, before being buffered in event caching and
With event belonging to after whole events of same serialization event group have been scheduled, event is assigned to the team of event queue
First;And, for judging that event is the non-first event being triggered at judging unit 51, and uncached have with event belonging to same
In the event of serialization event group, and event queue or thread not with event belonging to same serialization event group event just
When being scheduled, event is assigned directly to the head of the queue of event queue.
Alternatively, it is judged that unit 51 when judging whether described event is correlating event, specifically for: inquire about each successively
Whether serialization buffer zone records the mark of described event, if successful inquiring, it is determined that described event is correlating event,
And the serialization event group corresponding with the serialization buffer zone recording the mark having described event is associated, otherwise, it determines institute
The event of stating is independent event.
Alternatively, serialization buffer zone creates in the following manner: analyze in event sets to be allocated each event it
Between service logic relation, each event correlation of same service logic relation will be there is in same serialization event group;For
Each serialization event group creates a serialization buffer zone therewith with one-to-one relationship;Wherein, described serialization
In buffer zone, record has and has the mark of each event in the serialization event group of one-to-one relationship therewith;Described serialization
Any one event in the serialization event group that buffer zone is corresponding starts to by thread to perform from being assigned to described event queue
Completing, described serialization buffer zone is in running order, and otherwise, described serialization buffer zone is in resting state.
Alternatively, it is judged that unit 51 is judging whether event is the first event being triggered in affiliated serialization event group
Time, specifically for: whether the serialization buffer zone belonging to query event there is distribution labelling, if there being distribution labelling, then it represents that
Event is not the first event being triggered in the serialization event group that described serialization buffer zone is corresponding, if not distributing mark
Note, then it represents that event is the first event being triggered in the serialization event group that described serialization buffer zone is corresponding.
Alternatively, event is being cached by processing unit 52, before being buffered in event caching and with event belonging to
After whole events of same serialization event group have been scheduled, when event is assigned to the head of the queue of event queue, specifically use
In: by event buffer to the serialization buffer zone corresponding with the serialization event group belonging to event;In serialization buffer zone
It is in resting state and serialization buffer zone and does not stores when carrying out, before the moment that event is buffered, the event cached,
Event is assigned to the head of the queue of event queue.
Those skilled in the art are it should be appreciated that embodiments of the invention can be provided as method, system or computer program
Product.Therefore, the reality in terms of the present invention can use complete hardware embodiment, complete software implementation or combine software and hardware
Execute the form of example.And, the present invention can use at one or more computers wherein including computer usable program code
The upper computer program product implemented of usable storage medium (including but not limited to disk memory, CD-ROM, optical memory etc.)
The form of product.
The present invention is with reference to method, equipment (system) and the flow process of computer program according to embodiments of the present invention
Figure and/or block diagram describe.It should be understood that can the most first-class by computer program instructions flowchart and/or block diagram
Flow process in journey and/or square frame and flow chart and/or block diagram and/or the combination of square frame.These computer programs can be provided
Instruction arrives the processor of general purpose computer, special-purpose computer, Embedded Processor or other programmable data processing device to produce
A raw machine so that the instruction performed by the processor of computer or other programmable data processing device is produced for real
The device of the function specified in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame now.
These computer program instructions may be alternatively stored in and computer or other programmable data processing device can be guided with spy
Determine in the computer-readable memory that mode works so that the instruction being stored in this computer-readable memory produces and includes referring to
Make the manufacture of device, this command device realize at one flow process of flow chart or multiple flow process and/or one square frame of block diagram or
The function specified in multiple square frames.
These computer program instructions also can be loaded in computer or other programmable data processing device so that at meter
Perform sequence of operations step on calculation machine or other programmable devices to produce computer implemented process, thus at computer or
The instruction performed on other programmable devices provides for realizing at one flow process of flow chart or multiple flow process and/or block diagram one
The step of the function specified in individual square frame or multiple square frame.
Although preferred embodiments of the present invention have been described, but those skilled in the art once know basic creation
Property concept, then can make other change and amendment to these embodiments.So, claims are intended to be construed to include excellent
Select embodiment and fall into all changes and the amendment of the scope of the invention.
Obviously, those skilled in the art can carry out various change and the modification essence without deviating from the present invention to the present invention
God and scope.So, if these amendments of the present invention and modification belong to the scope of the claims in the present invention and equivalent technologies thereof
Within, then the present invention is also intended to comprise these change and modification.
Claims (10)
1. the event dispatcher method being applied in multi-threaded system, it is characterised in that described method includes:
When detecting that any one event is triggered, it is judged that whether described event is correlating event;
If correlating event, it is judged that whether described event is the first event being triggered in affiliated serialization event group;If
The first event being triggered, then be assigned to the tail of the queue of event queue by described event;If the non-first event being triggered, then when
Be cached with described event belonging to the event of same serialization event group, and/or, event queue or thread have and described event
When the event of affiliated same serialization event group is scheduled, by described event buffer, before being buffered in described event
Caching and with described event belonging to after the event of same serialization event group has been scheduled, described event is assigned to described
The head of the queue of event queue;Otherwise, described event is assigned directly to the head of the queue of described event queue;
If independent event, described event is assigned directly to the tail of the queue of described event queue, is adjusted by corresponding thread to wait
With.
2. the method for claim 1, it is characterised in that judge whether described event is correlating event, specifically includes:
Inquire about the mark whether recording described event in each serialization buffer zone successively, if successful inquiring, it is determined that institute
The event of stating is correlating event, and the serialization event group phase corresponding with the serialization buffer zone recording the mark having described event
Association, otherwise, it determines described event is independent event.
3. method as claimed in claim 2, it is characterised in that described serialization buffer zone creates in the following manner:
Analyze the service logic relation between each event in event sets to be allocated, each of same service logic relation will be there is
In individual event correlation extremely same serialization event group;
A serialization buffer zone therewith with one-to-one relationship is created for each serialization event group;
Wherein, in described serialization buffer zone, record has and has each thing in the serialization event group of one-to-one relationship therewith
The mark of part;Any one event in the serialization event group that described serialization buffer zone is corresponding is from being assigned to described event team
Row start to having been performed by thread, and described serialization buffer zone is in running order, otherwise, and described serialization buffer zone
It is in resting state.
4. method as claimed in claim 2 or claim 3, it is characterised in that judge whether described event is affiliated serialization event
The first event being triggered in group, specifically includes:
Inquire about in the serialization buffer zone belonging to described event and whether have distribution labelling, if there being distribution labelling, then it represents that described
Event is the non-first event being triggered in the serialization event group that described serialization buffer zone is corresponding, if not distributing mark
Note, then it represents that described event is the first event being triggered in the serialization event group that described serialization buffer zone is corresponding.
5. method as claimed in claim 2 or claim 3, it is characterised in that described event is cached, when being delayed in described event
Deposit before caching and with described event belonging to after whole events of same serialization event group have been scheduled, by described event
It is assigned to the head of the queue of event queue, specifically includes:
By described event buffer to the serialization buffer zone corresponding with the serialization event group belonging to described event;
Do not store in described event in described serialization buffer zone is in resting state and described serialization buffer zone
When carrying out, before the moment being buffered, the event cached, described event is assigned to the head of the queue of described event queue.
6. the event distributor that a kind is applied in multi-threaded system, it is characterised in that including:
Judging unit, for when detecting that any one event is triggered, it is judged that whether described event is correlating event;And,
After described judging unit judges that described event is correlating event, determine whether whether described event is affiliated serialization event
The first event being triggered in group;And, described judging unit judge described event be non-first be triggered event time, enter
One step judge whether to be cached with described event belonging in the event of same serialization event group, and event queue or thread
Whether have with described event belonging to the event of same serialization event group be scheduled;
Processing unit, for when described judging unit judges that described event is independent event, is assigned directly to described event
The tail of the queue of event queue, to wait by corresponding thread dispatching;And, for headed by described judging unit judges described event
Individual be triggered event time, described event is assigned to the tail of the queue of described event queue;And, for sentencing at described judging unit
Disconnected described event is the non-first event being triggered, and be cached with described event belonging to the event of same serialization event group,
And/or, event queue or thread have with described event belonging to the event of same serialization event group be scheduled time, by institute
State event buffer, before being buffered in described event caching and with described event belonging to whole things of same serialization event group
After part has been scheduled, described event is assigned to the head of the queue of event queue;And, for judging institute at described judging unit
The event of stating is the non-first event being triggered, and uncached have with described event belonging to the event of same serialization event group, with
And in event queue or thread not with described event belonging to the event of same serialization event group be scheduled time, by described
Event is assigned directly to the head of the queue of described event queue.
7. device as claimed in claim 6, it is characterised in that described judging unit is judging whether described event is association thing
During part, specifically for:
Inquire about the mark whether recording described event in each serialization buffer zone successively, if successful inquiring, it is determined that institute
The event of stating is correlating event, and the serialization event group phase corresponding with the serialization buffer zone recording the mark having described event
Association, otherwise, it determines described event is independent event.
8. device as claimed in claim 7, it is characterised in that described serialization buffer zone creates in the following manner:
Analyze the service logic relation between each event in event sets to be allocated, each of same service logic relation will be there is
In individual event correlation extremely same serialization event group;
A serialization buffer zone therewith with one-to-one relationship is created for each serialization event group;
Wherein, in described serialization buffer zone, record has and has each thing in the serialization event group of one-to-one relationship therewith
The mark of part;Any one event in the serialization event group that described serialization buffer zone is corresponding is from being assigned to described event team
Row start to having been performed by thread, and described serialization buffer zone is in running order, otherwise, and described serialization buffer zone
It is in resting state.
9. device as claimed in claim 7 or 8, it is characterised in that described judging unit is judging whether described event is institute
Belong to serialization event group in first be triggered event time, specifically for:
Inquire about in the serialization buffer zone belonging to described event and whether have distribution labelling, if there being distribution labelling, then it represents that described
Event is not the first event being triggered in the serialization event group that described serialization buffer zone is corresponding, if not distributing mark
Note, then it represents that described event is the first event being triggered in the serialization event group that described serialization buffer zone is corresponding.
10. device as claimed in claim 7 or 8, it is characterised in that described event is being cached by described processing unit,
Before being buffered in described event caching and with described event belonging to whole events of same serialization event group be scheduled
After one-tenth, when described event is assigned to the head of the queue of event queue, specifically for:
By described event buffer to the serialization buffer zone corresponding with the serialization event group belonging to described event;
Do not store in described event in described serialization buffer zone is in resting state and described serialization buffer zone
When carrying out, before the moment being buffered, the event cached, described event is assigned to the head of the queue of described event queue.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610579344.1A CN106155794B (en) | 2016-07-21 | 2016-07-21 | A kind of event dispatcher method and device applied in multi-threaded system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610579344.1A CN106155794B (en) | 2016-07-21 | 2016-07-21 | A kind of event dispatcher method and device applied in multi-threaded system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106155794A true CN106155794A (en) | 2016-11-23 |
CN106155794B CN106155794B (en) | 2019-11-19 |
Family
ID=58059835
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610579344.1A Active CN106155794B (en) | 2016-07-21 | 2016-07-21 | A kind of event dispatcher method and device applied in multi-threaded system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106155794B (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107369088A (en) * | 2017-07-19 | 2017-11-21 | 中国银行股份有限公司 | The treating method and apparatus of account transaction |
CN109246470A (en) * | 2018-09-29 | 2019-01-18 | 武汉斗鱼网络科技有限公司 | Barrage distribution method, device, equipment and the storage medium of Multi-thread synchronization |
CN110650008A (en) * | 2019-08-30 | 2020-01-03 | 武汉船舶通信研究所(中国船舶重工集团公司第七二二研究所) | Multi-port FC encryption method and device |
CN111247515A (en) * | 2017-10-18 | 2020-06-05 | 思科技术公司 | Apparatus and method for providing a performance-based packet scheduler |
CN112527509A (en) * | 2020-12-21 | 2021-03-19 | 北京百度网讯科技有限公司 | Resource allocation method and device, electronic equipment and storage medium |
Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1517917A (en) * | 2003-01-27 | 2004-08-04 | ������������ʽ���� | Method for managing affairs processing correlation to enduring structure in multi-line program enviroment |
CN1706204A (en) * | 2002-06-14 | 2005-12-07 | 国际商业机器公司 | Service logic context cache for signaling events |
CN1874538A (en) * | 2005-07-20 | 2006-12-06 | 华为技术有限公司 | Concurrent method for treating calling events |
US20080134203A1 (en) * | 2006-11-30 | 2008-06-05 | Franz Weber | Event correlation |
CN101364190A (en) * | 2008-09-24 | 2009-02-11 | 金蝶软件(中国)有限公司 | Method for executing synchronous and asynchronous operation on graphical user interface and device |
US20090083752A1 (en) * | 2007-09-20 | 2009-03-26 | Kddi Corporation | Event processing apparatus and method based on operating system |
US20100043003A1 (en) * | 2008-08-12 | 2010-02-18 | Verizon Data Services Llc | Speedy event processing |
US7730501B2 (en) * | 2003-11-19 | 2010-06-01 | Intel Corporation | Method for parallel processing of events within multiple event contexts maintaining ordered mutual exclusion |
CN103092682A (en) * | 2011-10-28 | 2013-05-08 | 浙江大华技术股份有限公司 | Asynchronous network application program processing method |
CN104932946A (en) * | 2009-07-28 | 2015-09-23 | 瑞典爱立信有限公司 | Equipment and method used for processing events in telecommunication network |
-
2016
- 2016-07-21 CN CN201610579344.1A patent/CN106155794B/en active Active
Patent Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1706204A (en) * | 2002-06-14 | 2005-12-07 | 国际商业机器公司 | Service logic context cache for signaling events |
CN1517917A (en) * | 2003-01-27 | 2004-08-04 | ������������ʽ���� | Method for managing affairs processing correlation to enduring structure in multi-line program enviroment |
US7730501B2 (en) * | 2003-11-19 | 2010-06-01 | Intel Corporation | Method for parallel processing of events within multiple event contexts maintaining ordered mutual exclusion |
CN1874538A (en) * | 2005-07-20 | 2006-12-06 | 华为技术有限公司 | Concurrent method for treating calling events |
US20080134203A1 (en) * | 2006-11-30 | 2008-06-05 | Franz Weber | Event correlation |
US20090083752A1 (en) * | 2007-09-20 | 2009-03-26 | Kddi Corporation | Event processing apparatus and method based on operating system |
US20100043003A1 (en) * | 2008-08-12 | 2010-02-18 | Verizon Data Services Llc | Speedy event processing |
CN101364190A (en) * | 2008-09-24 | 2009-02-11 | 金蝶软件(中国)有限公司 | Method for executing synchronous and asynchronous operation on graphical user interface and device |
CN104932946A (en) * | 2009-07-28 | 2015-09-23 | 瑞典爱立信有限公司 | Equipment and method used for processing events in telecommunication network |
CN103092682A (en) * | 2011-10-28 | 2013-05-08 | 浙江大华技术股份有限公司 | Asynchronous network application program processing method |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107369088A (en) * | 2017-07-19 | 2017-11-21 | 中国银行股份有限公司 | The treating method and apparatus of account transaction |
CN111247515A (en) * | 2017-10-18 | 2020-06-05 | 思科技术公司 | Apparatus and method for providing a performance-based packet scheduler |
CN109246470A (en) * | 2018-09-29 | 2019-01-18 | 武汉斗鱼网络科技有限公司 | Barrage distribution method, device, equipment and the storage medium of Multi-thread synchronization |
CN109246470B (en) * | 2018-09-29 | 2020-10-16 | 武汉斗鱼网络科技有限公司 | Multi-thread synchronous bullet screen distribution method, device, equipment and storage medium |
CN110650008A (en) * | 2019-08-30 | 2020-01-03 | 武汉船舶通信研究所(中国船舶重工集团公司第七二二研究所) | Multi-port FC encryption method and device |
CN112527509A (en) * | 2020-12-21 | 2021-03-19 | 北京百度网讯科技有限公司 | Resource allocation method and device, electronic equipment and storage medium |
CN112527509B (en) * | 2020-12-21 | 2023-09-01 | 北京百度网讯科技有限公司 | Resource allocation method and device, electronic equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN106155794B (en) | 2019-11-19 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106155794A (en) | A kind of event dispatcher method being applied in multi-threaded system and device | |
CN101727357B (en) | Method and apparatus for allocating resources in a compute farm | |
Warneke et al. | Exploiting dynamic resource allocation for efficient parallel data processing in the cloud | |
KR101638136B1 (en) | Method for minimizing lock competition between threads when tasks are distributed in multi-thread structure and apparatus using the same | |
US7559062B2 (en) | Intelligent scheduler for multi-level exhaustive scheduling | |
US6735769B1 (en) | Apparatus and method for initial load balancing in a multiple run queue system | |
US6993767B2 (en) | System for preventing periodic load balancing if processor associated with lightest local run queue has benefited from idle processor load balancing within a determined time period | |
Dong et al. | Scheduling mixed real-time and non-real-time applications in mapreduce environment | |
US8782649B2 (en) | Real-time scheduling of task sets and determination of task sets based on verified weight, cache hit radio of the tasks and available processing cores | |
US8316365B2 (en) | Computer system | |
CN105389206B (en) | A kind of cloud computation data center resources of virtual machine quickly configuration method | |
CN109857535B (en) | Spark JDBC-oriented task priority control implementation method and device | |
CN102360309A (en) | Scheduling system and scheduling execution method of multi-core heterogeneous system on chip | |
CN106033373A (en) | A method and a system for scheduling virtual machine resources in a cloud computing platform | |
CN110308982A (en) | A kind of shared drive multiplexing method and device | |
US20210390405A1 (en) | Microservice-based training systems in heterogeneous graphic processor unit (gpu) cluster and operating method thereof | |
US10360079B2 (en) | Architecture and services supporting reconfigurable synchronization in a multiprocessing system | |
US9367350B2 (en) | Meta-scheduler with meta-contexts | |
US11875425B2 (en) | Implementing heterogeneous wavefronts on a graphics processing unit (GPU) | |
CN111767145A (en) | Container scheduling system, method, device and equipment | |
CN1326567A (en) | Job-parallel processor | |
US20030191794A1 (en) | Apparatus and method for dispatching fixed priority threads using a global run queue in a multiple run queue system | |
CN104090826A (en) | Task optimization deployment method based on correlation | |
US20150212859A1 (en) | Graphics processing unit controller, host system, and methods | |
DE102013100169A1 (en) | Computer-implemented method for selection of a processor, which is incorporated in multiple processors to receive work, which relates to an arithmetic problem |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |