CN107122193A - A kind of dynamic regulating method of message threads suspension time - Google Patents
A kind of dynamic regulating method of message threads suspension time Download PDFInfo
- Publication number
- CN107122193A CN107122193A CN201710294607.9A CN201710294607A CN107122193A CN 107122193 A CN107122193 A CN 107122193A CN 201710294607 A CN201710294607 A CN 201710294607A CN 107122193 A CN107122193 A CN 107122193A
- Authority
- CN
- China
- Prior art keywords
- message
- queue
- thread
- time
- tsmax
- 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/44—Arrangements for executing specific programs
- G06F9/4401—Bootstrapping
- G06F9/4418—Suspend and resume; Hibernate and awake
-
- 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/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
Abstract
The invention provides a kind of dynamic regulating method of message threads suspension time, methods described includes:1) TS is set as thread dormancy time;2) order sends a message to the frequency of queue less than the frequency that Message Processing is obtained from queue;3) Message Processing is no more than the message response time allowed, i.e., the processing time of last message reaches response time requirement in message queue, then all message all meet response time requirement;4) message can just be continued with by making after thread dormancy for a period of time, and set the minimum dormancy time of a thread;5) the most long dormancy time of a thread is set;6) above-mentioned steps are arranged, obtaining the thread dormancy time as TS=TSmax_R makes what is most grown.
Description
Technical field
The present invention relates to the dynamic regulation of Message Processing thread, more particularly to message threads suspension time.
Background technology
Message Processing thread, i.e., continuously carry out the thread that reception message is handled again by message loop.By
Limited in cpu resource, a thread can not take CPU always, thus thread after a message has been handled, it is necessary to hang up, i.e.,
Thread is hung up, allows other same priority threads to have an opportunity acquisition CPU.When so just needing to set a rational thread suspension
Between, the time is unsuitable too short or long.If suspension time is too short, CPU is wasted, and other threads can be caused to be difficult to seize CPU;If
Overlong time, may cause message in need of immediate treatment to need to wait the long period, so as to not reach performance requirement, so that occurring
The overstocked situation of queue message occurs.
Existing processing mode is according to empirical estimating or tests a constant thread suspension time, it is ensured that processing speed is big
In receiving velocity.But, if design changes, this value may be needed to re-evaluate and test, also, estimated value is not measured
Whether the suspension time that method is used to evaluate thread distribution is reasonable, if meet design requirement (such as response time requirement).
The content of the invention
The purpose of the present invention makes the Message Processing of thread to provide a kind of method of message threads suspension time dynamic regulation
Time reaches balance as far as possible with suspension time, i.e., premised on not influenceing the efficiency of thread process message, when making thread suspension
Between it is as long as possible, to reduce CPU holding time pieces, improve CPU utilization rate, tested into independent of artificial estimation and reduction
This.
To achieve these goals, the invention provides a kind of dynamic regulating method of message threads suspension time, it is special
Levy and be, the described method comprises the following steps:
1) TS is set as thread dormancy time, unit ms;
2) order sends a message to the frequency of queue less than the frequency that Message Processing is obtained from queue:
f1<=f2
F2=1000/ (TA+TS)
Wherein:F1 is message transmission frequency, i.e., per second to send to the message number of message queue;
F2 is Message Processing frequency, i.e., per second that message number is handled from message queue;
3) Message Processing is no more than the message response time allowed, i.e., the processing time of last message in message queue
Response time requirement is reached, then all message all meet response time requirement, it is necessary to meet following condition:
TD>=n* (TS+TA)
n<=Q
TD is allows the maximum response time (be placed into queue from message, to finally have been processed into) of a message, singly
Position millisecond.
N is the message number that caches in message queue;
Q is message queue largest buffered capacity;
4) message can just be continued with by making after thread dormancy for a period of time, and set the minimum dormancy time of a thread;
TS>=TSmin
5) the most long dormancy time of a thread is set;
TS<=TSmax
6) above-mentioned steps are arranged, it is as a result as follows:
TSmin_R<=TS<=TSmax_R
TSmin_R=max (TD/Q-TS, TSmin)
TSmax_R=min (1000/f1-TA, TD/n-TA, TSmax)
Understand above, as TS=TSmax_R, thread dormancy time makes what is most grown.
In one embodiment, TS is to solve for variable, and Q, TSmin, TSmax, TD are constants, f1, and n, TA is variable.
In one embodiment, when message transmission frequency is in increase, the message of thread process in the f1=unit interval
Increase message number in number+queue newly;When message transmission frequency is reducing, the message of thread process in the f1=unit interval
Message number is reduced in number-queue.
In one embodiment, n can be obtained by API.
In one embodiment, n is obtained by the OsQueryQueue interfaces in ATS systems by MTM.
The present invention has following advantageous effects:
First, the present invention realizes automatically adjusting for thread suspension time, saves unnecessary CPU holding times, improves
Cpu busy percentage, and the performance for not influenceing message threads to perform.
Secondly, the present invention need not re-evaluate when thread code, process are changed, change suspension time, you can realize
Thread suspension time optimal.
Again, the present invention provides a kind of appraisal procedure for the dormancy time reasonability that thread is distributed.
Brief description of the drawings
The above content of the invention and following embodiment of the present invention can be obtained more preferably when being read in conjunction with the figure
Understanding.It should be noted that accompanying drawing is only as the example of claimed invention.In the accompanying drawings, identical reference
Represent same or similar element.
Fig. 1 shows the flow chart of conventional Message Processing thread process message.
Embodiment
The detailed features and advantage of the narration present invention in detail in a specific embodiment below, its content is enough to make any
Skilled in the art realises that the technology contents of the present invention and implement according to this, and specification according to disclosed by this specification, weigh
Profit is required and accompanying drawing, skilled person readily understands that the present invention related purpose and advantage.
Fig. 1 shows the flow chart of conventional Message Processing thread process message.
Step 101:Thread brings into operation;
Step 102:Circulation can all judge whether to meet thread exit criteria every time.Such as thread is not exited, that is, is unsatisfactory for line
Journey exit criteria, then carry out to step 103, otherwise carry out the circulation of step 107 exit message and terminate thread;
Step 103:Judge whether there is message in queue, there is then progress step 104, otherwise carry out step 106 and hang up;
Step 104:Message is taken out from message queue
Step 105:Message call processing function processing message, this step can be omitted as desired;
Step 106:Thread suspension, calls Sleep functions, discharges CPU controls;
Step 107:Terminate thread.
Improved institute of the invention is step 106, extends thread suspension time as far as possible, that is, make system function Sleep
(n) n in reaches the maximization in mathematical modeling.
In one embodiment, mathematical modeling can be by set-up below.
1) TS is set as thread dormancy time, and unit ms, target of the present invention is the maximum for obtaining dormancy time.
2) frequency for sending a message to queue is necessarily less than the frequency that Message Processing is obtained from queue, otherwise at one section
Between after, queue full will cause information drop-out.Accordingly, it would be desirable to meet as follows:
f1<=f2
F2=1000/ (TA+TS)
Wherein:F1 is message transmission frequency, i.e., per second to send to the message number of message queue;
F2 is Message Processing frequency, i.e., per second that message number is handled from message queue;
TA is averaged processing time for a message in message queue, without thread dormancy time.Unit millisecond.
3) otherwise Message Processing can not meet system performance requirements no more than the message response time allowed.
According to hypothesis, it is believed that the processing time of the message of last in message queue reaches response time requirement (i.e.
The worst situation of message processing time), then all message all meet response time requirement, it is therefore desirable to meet as follows:
TD>=n* (TS+TA)
n<=Q
TD is allows the maximum response time (be placed into queue from message, to finally have been processed into) of a message, singly
Position millisecond.
N is the message number that caches in message queue;
Q is message queue largest buffered capacity.
4) thread must can just continue with message after dormancy for a period of time, and otherwise other threads are difficult to obtain timeslice,
So as to influence overall performance.
If only considered 1) with 2), under high response time requirement, thread dormancy time may be caused extremely short, this will cause
Thread is processing message as fast as possible, excessively occupies CPU, so as to influence the response time of other threads, it is therefore necessary to provide
The minimum dormancy time of one thread.
TS>=TSmin
5) thread dormancy time can not be long, and message otherwise may be caused to overstock not reach response time even queue
It is full.
It is probably a collection of batch of to consider that message is sent, if now thread after having handled a collection of message when starting longer
Between dormancy, as a result because dormancy time is long, two batches message is have sent in rest period sender, results messages are overstock, and response is prolonged
Late, it is therefore necessary to provide the most long dormancy time of a thread.
TS<=TSmax
In summary, computation model is as follows:
f1<=f2
F2=1000/ (TA+TS)
TD>=n* (TS+TA)
n<=Q
TSmax>=TS>=TSmin
Model is arranged, it is as a result as follows:
TS<=1000/f1-TA
TS<=TD/n-TA
TS>=TD/Q-TS
TSmax>=TS>=TSmin
It is further to model to arrange, it is as a result as follows:
TSmin_R<=TS<=TSmax_R
TSmin_R=max (TD/Q-TS, TSmin)
TSmax_R=min (1000/f1-TA, TD/n-TA, TSmax)
Understand above, as TS=TSmax_R, thread dormancy time makes what is most grown.
In model, TS is to solve for variable, and Q, TSmin, TSmax, TD are constants, f1, and n, TA is variable, it is necessary to count tax
Value.The statistical method of each variable is provided individually below:
f1->Message transmission frequency;
When transmission frequency is in increase, message is increased newly in message number+queue of thread process in the f1=unit interval
Number;
When transmission frequency is reducing, message is reduced in message number-queue of thread process in the f1=unit interval
Number;
n->Buffered message number in queue, by API Application it is known that such as automatic train monitoring system
The OsQueryQueue in the bottom storehouse (MTM includes the encapsulation of queue (pond) operation) in system system by independent development (obtains team
The function of row caching number) interface acquisition;Wherein, API Application refer generally to the built-in function that software development is called;
TA->A message is averaged processing time in message queue, without thread dormancy time.Unit millisecond.
In one embodiment, the following is the key algorithm of software implementation method.
According to mathematical modeling, Sleep methods are encapsulated, are implemented as follows:
NSleepTime is to calculate the most long dormancy time of gained, is used when message loop is hung up and calls Sleep
NSleepTime is that can reach desired effects.
In one embodiment, call algorithm as follows:
// calculate optimal suspension time
Int nSleepTime=CalcSleepTime ();
// thread suspension
Sleep(nSleepTime);
In one embodiment, complete message loop calls example
// message threads examples of functions
int TreadFun(WPARAM wParam,LPARAM lParam)
{
It should be appreciated by those skilled in the art that after the general principles of the present invention have been understood, not departing from the general principles
In the case of, there is the mathematical modeling after modification can also make it that the thread suspension time is more reasonable.Further, made in thread example
Function can be replaced other systems function or built-in function with similar hang-up function.
Here the term and form of presentation used is only intended to description, and the present invention should not be limited to these terms and table
State.It is not meant to exclude the equivalent features of any signal and description (or which part) using these terms and statement, should recognizes
Knowing various modifications that may be present also should be comprising within the scope of the claims.Other modifications, variations and alternatives also likely to be present.
Accordingly, claim should be regarded as covering all these equivalents.
As shown in the application and claims, unless context clearly points out exceptional situation, " one ", " one ", " one
The word such as kind " and/or "the" not refers in particular to odd number, may also comprise plural number.It is, in general, that term " comprising " only points out bag with "comprising"
Include clearly identify the step of and element, and these steps and element do not constitute one it is exclusive enumerate, method or equipment
May also include other the step of or element.
Meanwhile, the application describes embodiments herein using particular words.Such as " one embodiment ", " one implements
Example ", and/or " some embodiments " mean a certain feature, structure or the feature related to the application at least one embodiment.Cause
This, it should be highlighted that and it is noted that " embodiment " or " implementation that are referred to twice or repeatedly in diverse location in this specification
Example " or " alternate embodiment " are not necessarily meant to refer to same embodiment.In addition, in one or more embodiments of the application
Some features, structure or feature can carry out appropriate combination.
Equally, it should be pointed out that although the present invention is described with reference to current specific embodiment, this technology neck
Those of ordinary skill in domain is it should be appreciated that the embodiment of the above is intended merely to the explanation present invention, without departing from the present invention
Various equivalent change or replacement can be also made in the case of spirit, therefore, as long as right in the spirit of the present invention
The change, modification of above-described embodiment will all fall in the range of following claims.
Claims (5)
1. a kind of dynamic regulating method of message threads suspension time, it is characterised in that the described method comprises the following steps:
1) TS is set as thread dormancy time, unit ms;
2) order sends a message to the frequency of queue less than the frequency that Message Processing is obtained from queue:
f1<=f2
F2=1000/ (TA+TS)
Wherein:F1 is message transmission frequency, i.e., per second to send to the message number of message queue;
F2 is Message Processing frequency, i.e., per second that message number is handled from message queue;
3) Message Processing is no more than the message response time allowed, i.e., the processing time of last message reaches in message queue
Response time requirement, then all message all meet response time requirement, it is necessary to meet following condition:
TD>=n* (TS+TA)
n<=Q
TD is allows the maximum response time (be placed into queue from message, to finally have been processed into) of a message, and unit is in the least
Second.
N is the message number that caches in message queue;
Q is message queue largest buffered capacity;
4) message can just be continued with by making after thread dormancy for a period of time, and set the minimum dormancy time of a thread;
TS>=TSmin
5) the most long dormancy time of a thread is set;
TS<=TSmax
6) above-mentioned steps are arranged, it is as a result as follows:
TSmin_R<=TS<=TSmax_R
TSmin_R=max (TD/Q-TS, TSmin)
TSmax_R=min (1000/f1-TA, TD/n-TA, TSmax)
Understand above, as TS=TSmax_R, thread dormancy time makes what is most grown.
2. the method as described in claim 1, it is characterised in that wherein, TS is to solve for variable, Q, TSmin, TSmax, TD are normal
Amount, f1, n, TA is variable..
3. method as claimed in claim 2, it is characterised in that:
When message transmission frequency is in increase, message is increased newly in message number+queue of thread process in the f1=unit interval
Number;
When message transmission frequency is reducing, message is reduced in message number-queue of thread process in the f1=unit interval
Number.
4. method as claimed in claim 2, it is characterised in that:N can be obtained by built-in function.
5. method as claimed in claim 4, it is characterised in that n by automatic train monitor system by independently opening
The function interface for obtaining queue caching number in the bottom storehouse of hair is obtained.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710294607.9A CN107122193B (en) | 2017-04-28 | 2017-04-28 | Dynamic adjustment method for message thread suspension time |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710294607.9A CN107122193B (en) | 2017-04-28 | 2017-04-28 | Dynamic adjustment method for message thread suspension time |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107122193A true CN107122193A (en) | 2017-09-01 |
CN107122193B CN107122193B (en) | 2020-09-08 |
Family
ID=59725103
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710294607.9A Active CN107122193B (en) | 2017-04-28 | 2017-04-28 | Dynamic adjustment method for message thread suspension time |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107122193B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111625322A (en) * | 2019-02-27 | 2020-09-04 | 阿里巴巴集团控股有限公司 | Data processing method, system and equipment |
CN114546617A (en) * | 2022-02-23 | 2022-05-27 | 南京航空航天大学 | Task scheduling method with low service cost in vehicle-mounted cloud environment |
CN116501475A (en) * | 2023-06-21 | 2023-07-28 | 杭州炬华科技股份有限公司 | Thread scheduling method, system and medium |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US4819229A (en) * | 1986-03-13 | 1989-04-04 | University Of Strathclyde | Local area network priority control system |
CN102609295A (en) * | 2011-10-18 | 2012-07-25 | 华中科技大学 | Dynamic operation scheduling system of virtual machine |
CN103902361A (en) * | 2014-04-04 | 2014-07-02 | 浪潮电子信息产业股份有限公司 | Thread pool capable of dynamically adjusting size |
CN104702418A (en) * | 2015-04-07 | 2015-06-10 | 江苏大学 | Vehicle identity authentication method capable of evenly sharing RSU calculated amount |
CN106227672A (en) * | 2016-08-10 | 2016-12-14 | 中车株洲电力机车研究所有限公司 | A kind of built-in application program fault catches and processing method |
CN106453141A (en) * | 2016-10-12 | 2017-02-22 | 中国联合网络通信集团有限公司 | Global queue adjustment method, service flow queue adjustment method and network system |
-
2017
- 2017-04-28 CN CN201710294607.9A patent/CN107122193B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US4819229A (en) * | 1986-03-13 | 1989-04-04 | University Of Strathclyde | Local area network priority control system |
CN102609295A (en) * | 2011-10-18 | 2012-07-25 | 华中科技大学 | Dynamic operation scheduling system of virtual machine |
CN103902361A (en) * | 2014-04-04 | 2014-07-02 | 浪潮电子信息产业股份有限公司 | Thread pool capable of dynamically adjusting size |
CN104702418A (en) * | 2015-04-07 | 2015-06-10 | 江苏大学 | Vehicle identity authentication method capable of evenly sharing RSU calculated amount |
CN106227672A (en) * | 2016-08-10 | 2016-12-14 | 中车株洲电力机车研究所有限公司 | A kind of built-in application program fault catches and processing method |
CN106453141A (en) * | 2016-10-12 | 2017-02-22 | 中国联合网络通信集团有限公司 | Global queue adjustment method, service flow queue adjustment method and network system |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111625322A (en) * | 2019-02-27 | 2020-09-04 | 阿里巴巴集团控股有限公司 | Data processing method, system and equipment |
CN111625322B (en) * | 2019-02-27 | 2024-03-29 | 阿里巴巴集团控股有限公司 | Data processing method, system and equipment |
CN114546617A (en) * | 2022-02-23 | 2022-05-27 | 南京航空航天大学 | Task scheduling method with low service cost in vehicle-mounted cloud environment |
CN116501475A (en) * | 2023-06-21 | 2023-07-28 | 杭州炬华科技股份有限公司 | Thread scheduling method, system and medium |
CN116501475B (en) * | 2023-06-21 | 2023-10-20 | 杭州炬华科技股份有限公司 | Thread scheduling method, system and medium |
Also Published As
Publication number | Publication date |
---|---|
CN107122193B (en) | 2020-09-08 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102460342B (en) | For performing the method and apparatus of energy-conservation network packet process in multiple processor cores system | |
CN107066332B (en) | Distributed system and scheduling method and scheduling device thereof | |
CN107122193A (en) | A kind of dynamic regulating method of message threads suspension time | |
CN102594691B (en) | A kind of method and device handling message | |
CN103064807B (en) | Hyperchannel DMA controller | |
CN107844187A (en) | Power consumption management method, device and electronic equipment | |
CN101354664A (en) | Method and apparatus for interrupting load equilibrium of multi-core processor | |
CN108446179B (en) | Weight priority Task scheduling method based on load balancing mechanism | |
EP3283959A1 (en) | Apparatus and method for adjusting processor power usage based on network load | |
CN110572329B (en) | Network adaptive traffic shaping method and system | |
CN112383585A (en) | Message processing system and method and electronic equipment | |
CN106550010A (en) | A kind of real-time control distributed system calls external system to service the method and system of the frequency | |
CN109729113B (en) | Method, server system and computer program product for managing dedicated processing resources | |
CN106325996B (en) | A kind of distribution method and system of GPU resource | |
CN114448989B (en) | Method, device, electronic equipment, storage medium and product for adjusting message distribution | |
CN111078391A (en) | Service request processing method, device and equipment | |
CN103823712B (en) | Data flow processing method and device for multi-CPU virtual machine system | |
WO2018090784A1 (en) | Distributed stream calculation-based processing method, system, physical equipment and storage medium | |
CN106411971B (en) | Load adjusting method and device | |
CN107544888B (en) | Log processing method and system | |
CN111309480A (en) | Method and equipment for dynamic power consumption capping regulation and control | |
EP4022446B1 (en) | Memory sharing | |
CN107360019A (en) | A kind of thread monitor method and system of server | |
CN109547277A (en) | The method for limiting speed of data transmission, system, equipment, computer readable storage medium | |
CN105264499B (en) | Message treatment method, device and reception core in a kind of shared queue |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20171228 Address after: No. 16, West Fourth Ring Road, Haidian District, Beijing, Beijing Applicant after: CRRC Corporation Limited Applicant after: Hunan CRRC Times Communications Signal Co., Ltd. Address before: 410100 Hunan economic and Technological Development Zone, Changsha Province, the people of the East Road, No. 7, building 21, floor Applicant before: Hunan CRRC Times Communications Signal Co., Ltd. |
|
TA01 | Transfer of patent application right | ||
GR01 | Patent grant | ||
GR01 | Patent grant |