Background technology
Middleware is a software layer between application program and operating system, is mainly used under distributed environment, shields the heterogeneous characteristic between each platform and the host computer system, connects each application component and communicates.At present, more common a kind of middleware is a message-oriented middleware, also claim Message Oriented Middleware (MessageOriented-Middleware, be called for short MOM), its core is message transfer mechanism or message queue pattern, by using high-efficiency reliable message transfer mechanism or message queue pattern, simplify the transfer of data between the application program.
In the practical application, influenced by Network Transmission situation and receiving terminal load state etc., the message that transmits by message-oriented middleware tends to take place various unforeseen situations such as information drop-out, when these situations take place, message-oriented middleware this message that just need retransfer, promptly message retransmits.The message retransmission processes is based on that certain timeout interval triggers, and timeout interval is meant that transmitting terminal sends transmitting terminal with a message and thinks that this message lost and retransmit time of this message.And in the real network, will accurately determine timeout interval is not a nothing the matter, because network process communication is not only to carry out on a local area network (LAN), pass through many go-betweens possibly, and the communication delay between the different processes is except depending on the loading condition of different channels, depend on that also different receiving terminals are at difference loading condition constantly in the message-oriented middleware system, therefore, the excursion of message transmission delay is very big, that is to say, receive that from initiating a message to receiving terminal is dynamic change to the affirmation message of this message required two-way time.Based on this, how to determine timeout interval, for the message-oriented middleware system be emphasis be again difficult point.
In a kind of prior art, timeout interval rule of thumb is set at a quiescent value, after message sends,, then retransmits this message if in the timeout interval of this setting, do not receive the affirmation message of this message.The mode of this non-self-adapting can realize that simple message retransmits, but has following problem in actual applications:
If it is too short that timeout interval is set, then can produce unnecessary messages and retransmit, this all is a kind of waste for Internet resources and message sink end, and in some cases, can increase the weight of the load of message sink end;
If it is oversize that timeout interval is set, then behind information drop-out, the time of delay that message retransmits is long, cause system not to be for further processing according to message in time, for example, during some system interactions are used, because the delay of message retransmission, system can not in time make feedback to the user, may cause user's repetitive operation.
In another prior art, the Jacobson algorithm application that the TCP transport network layer is commonly used at present is used to estimate timeout interval in the message-oriented middleware system.With this algorithm application in the message-oriented middleware system, when especially being applied in the message-oriented middleware system that handles complex data, because the incompatibility of algorithm, can cause in normal transmission problems such as unnecessary messages re-transmission, the main cause that produces these problems is:
The message-oriented middleware system handles the message of application layer, in the transport process of message, the condition that some application layers that often require emphasis are relevant, for example, message transmits the situation of failure, the dynamic change situation of message sink end load etc. on transport network layer.In addition, on system environments, application layer and transport network layer also have very big difference, application layer adopts multithread mode more, the processing of message happens suddenly often, has the situation of a plurality of concurrent message, and the concurrent number of message is many more, influence to the RTT (Round Trip Time, two-way time) of message is big more; And therefore the single-threaded often tupe of transport network layer is applied directly to the Jacobson algorithm in the message-oriented middleware system, obviously is unconformable.
Further, comprise the two-way time of application layer messages time, receiving terminal that message transmits at network from the transport network layer buffering area, read message to the time that sends out acknowledge message and acknowledge message in time that network transmits, bigger variation all can take place along with the difference of Network Transmission situation and receiving terminal load state in these times, this compares with transport network layer message metastable two-way time, and the amplitude of variation of the two-way time of message is very big; And, under sending, must wait for the wait characteristic of the affirmation message of preceding a piece of news before a piece of news based on the stop-and-wait protocol among the TCP, when adopting this kind wait strategy in application layer, can make the utilance of system reduce greatly, therefore, use Jacobson algorithm estimation timeout interval in the message-oriented middleware aspect, can produce bigger estimated delays.
In sum, the prior art of above-mentioned definite timeout interval is applied to the message-oriented middleware system, when especially being applied in the message-oriented middleware system that handles complex data, its adaptability is very poor, deviation with timeout interval reality the timeout interval of determining is very big, thereby the re-transmission of control messages effectively, make unnecessary messages retransmit or can not to carry out the problem that message retransmits in time apparent in view, the efficiency of transmission of system is very low.
Embodiment
For the timeout interval of the timeout interval that makes the message of determining in the message-oriented middleware system and message reality more approaching, thereby the more effectively re-transmission of control messages, the embodiment of the invention has proposed control method and the device that a kind of message retransmits, and is explained in detail to the main realization principle of the embodiment of the invention, specific implementation process and to the beneficial effect that should be able to reach below in conjunction with Figure of description.
At first, the inadaptability that the embodiment of the invention exists in the message-oriented middleware system time at the Jacobson algorithm application has proposed a kind of algorithm of the new timeout interval that is used to estimate message (MsgTimeout), and concrete computing formula is as follows:
MsgTimeout=R
*(RTT+X
*D)。
Wherein, X can rule of thumb be worth definite, and generally rule of thumb value is got X=4.Below, parameter R, RTT and D in this formula are introduced respectively:
(1) R is called delay factor, is used for representing the loading condition of communication session.Particularly, delay factor R can obtain according to following formula:
Wherein, CurWaitWindowSize represents the size (being the carrying quantity of message in the communication session) of the current wait window of Messages-Waiting formation in the communication session, and MaxWaitWindowSize represents the size (being the maximum carrying quantity of message in the communication session) of the maximum wait window of Messages-Waiting formation in the communication session.
(2) RTT represents the desired value (being optimum estimation value) of the two-way time of message, wherein, refers to that message is from sending to the time that the affirmation message that receives this message is experienced the two-way time of message.Particularly, RTT can obtain according to following formula:
RTT=α
*RTT+(1-α)
*M;
Wherein, α is the random value between (0,1), and M refers to the actual two-way time of message, and the RTT of equal sign front represents according to the value after upgrading the actual two-way time of this message, the value of safeguarding in the system before the RTT of equal sign back represents to upgrade.
RTT is according to upgrading the actual two-way time that overtime message does not take place, it is the every transmission a piece of news of message-oriented middleware system, and the affirmation message of this message arrives in the timeout interval of setting, and then actual two-way time and the above formula according to this message upgrades RTT.
(3) D represents the smooth value of the difference of the desired value of two-way time of message and actual value.Particularly, variables D can obtain according to following formula:
D=r
*D+(1-r)
*|RTT-M|;
Wherein, r be [0.5,1) between random value, RTT represents according to the value after upgrading actual two-way time of message, the D of equal sign front represents according to the value after the actual two-way time of message and the RTT renewal, the value of safeguarding in the system before the D of equal sign back represents to upgrade.
Safeguard that the purpose of variables D is to improve the accuracy of the timeout interval of determining, because if only determine the timeout interval of next message according to the two-way time of current message, the fluctuation of the timeout interval of then determining is bigger.
In order to make the relation between each variable more directly perceived, as shown in Figure 1, be the schematic diagram that concerns between RTT, D, R and the MsgTimeout, wherein, RTT and D upgrade synchronously, i.e. the every transmission a piece of news of message-oriented middleware system, and the affirmation message of this message arrives in timeout interval, then upgrade RTT, upgrade D according to the RTT after upgrading then; Delay factor R upgrades according to the variation of Messages-Waiting formation in the communication session, and the renewal process of its renewal process and RTT or D is separate.
It is pointed out that the mode of utilizing above-mentioned formula to upgrade MsgTimeout is not a sole mode,, also alternate manner can be arranged as long as R is taken into account.
When the message-oriented middleware system uses for the first time, owing to there is not the actual two-way time (promptly not having the M value) of message, then timeout interval is set to system default value, after system uses for the first time and withdraws from, the MsgTimeout that calculates of the last time was kept in the configuration file before system withdrawed from, after system start-up next time, the MsgTimeout that calls preservation from this configuration file is as initial value.
Further, for the definite algorithm that makes above-mentioned timeout interval can be applicable to the message-oriented middleware system better, the embodiment of the invention is that every message to be sent is added following attribute:
The transmitting time and the last transmitting time first time of the life cycle of message, message.
Wherein, the life cycle of message is in this message establishing, by the application program setting.
In addition, also need in the message-oriented middleware system, safeguard a WaitingMessageMap class, safeguard the relevant information of Messages-Waiting formation in the current communication session in such, promptly deposit and sent but also do not receive the message and the corresponding ID thereof of acknowledge message.Particularly, before system sends message, this message and corresponding ID thereof are added in this Messages-Waiting formation, after the affirmation message that receives this message, this message and corresponding ID thereof are deleted from the WaitingMessageMap class.
The information of safeguarding in such can be used for the computing relay factor R, is about in the current communication session ratio of the maximum message quantity that the quantity of message and this communication session can be carried in the Messages-Waiting formation, is defined as delay factor R.
Based on the above-mentioned attribute that message is added, and the information in the WaitingMessageMap class of safeguarding, the control procedure that in the embodiment of the invention message is retransmitted is mainly reflected in to the transmission control of message and to the monitoring of this transmission of messages time and handles, and is specific as follows:
As shown in Figure 2, among the embodiment, the transmission of message control is mainly comprised:
Step 201, obtain the transmitting time first time of this message from the attribute of message to be sent, if do not get access to transmitting time for the first time, then execution in step 202, otherwise execution in step 203.
Step 202, current system time is defined as the transmitting time first time of this message to be sent, and with this first time transmitting time add in the attribute of this message.
Step 203, according to the transmitting time and the life cycle first time of this message, judge whether this message expired, if judge that this message is not out of date, execution in step 204~step 207 then, otherwise execution in step 208.
In this step,, judge that whether this message is expired, is specially according to the transmitting time and the life cycle first time of this message:
The transmitting time first time of this message is added that time and the current system time that obtain the life cycle of this message compare,, determine that then this message is not out of date if the former is less than the latter; If the former is greater than the latter, determine that then this message is expired.
Step 204, the time of utilizing current system time and predetermined timeout interval addition to obtain, the monitor of this message is set, and this monitor is added in the overtime manager of system.
Particularly, can identify by the ID of this message for the monitor of message setting in this step.
Step 205, utilize the last transmitting time in the attribute of current system time setting message to be sent.
In this step,, then add to current system time in the attribute of this message as the last transmitting time if the last transmitting time in the attribute of message to be sent is empty; If the last transmitting time in the attribute of message to be sent be a sky, then utilize current system time to upgrade the last transmitting time in the attribute of this message.
Step 206, will this message to be sent and corresponding ID put into the WaitingMessageMap class.
Step 207, send message, and start the monitor of this message correspondence.
Step 208, abandon sending this message.
After message being sent according to said process, need monitor the time-out time that is provided with in the monitor in the overtime manager of system, the message-oriented middleware system may interiorly at one time send multiple messages, correspondingly, need monitor the time-out time of a plurality of monitors.As shown in Figure 3, among the embodiment, the monitoring of the time-out time of transmitted message handled comprise:
Step 301, judge whether that the time-out time that is provided with receives the affirmation message of this message before arriving in the monitor of message correspondence, if, execution in step 302~step 306 then; If not, execution in step 307 then.
The ID of step 302, the message confirmed according to the affirmation message that receives obtains the message of this ID correspondence from the WaitingMessageMap class.
Step 303, from the attribute of the message obtained, obtain the transmitting time and the last transmitting time first time of this message.
Step 304, the transmitting time and the last transmitting time first time of this message relatively, if two times equate execution in step 305, otherwise execution in step 306.
Step 305, determine that this message do not carry out re-transmission, calculate the actual two-way time of this message according to the last transmitting time of current system time and this message, according to the timeout interval of estimating message this actual two-way time and preserve, be used for sending next time the time-out time that monitor is set before the message.
In this step, definite method of timeout interval is described in detail in above-mentioned flow process, no longer is repeated in this description herein.
Among this embodiment, the timeout interval of message is according to upgrading the actual two-way time of the message that did not take place to retransmit, because if message took place to retransmit, can't determine that then this acknowledge message is the affirmation message of message correspondence when which time transmits, and then can't determine the actual two-way time of this message.
Step 306, according to the ID of this message, the monitor of this message correspondence is removed from the overtime manager of system, and will remove in this message and the corresponding Messages-Waiting formation of ID from the WaitingMessageMap class thereof.
Step 307, retransmit this message.
Further, in the one embodiment of the invention, before step 307 resend messages, judge whether this message is expired,, then do not retransmit this message, thereby avoid transmitting invalid message taking Internet resources if judge that this message is expired; If judge that this message is not out of date, then retransmit this message.Particularly, judging that message is whether expired can be by following process:
From the attribute of this message, obtain the life cycle of this message;
The life cycle of this message and time and the current system time that transmitting time addition for the first time obtains are compared,, determine that then this message is not out of date if the former is greater than the latter; If the former is less than the latter, determine that then this message is expired.
In further embodiment of this invention, consider the influence of the connection state of communication session to transmission of messages, promptly under the relatively poor situation of the connection state of communication session, the transmission of message has delay, so the timeout interval of proper extension message.Particularly,, when when step 301 is judged the time-out time arrival that is provided with in the monitor of message correspondence before, not receiving the affirmation message of this message, wouldn't retransmit this message, carry out step as shown in Figure 4 corresponding to above-mentioned flow process:
Step 401, judge whether communication session is overtime, if judge that communication session is overtime, then execution in step 402; Otherwise execution in step 403.
Based on the needs of determining that communication session is whether overtime, the embodiment of the invention has been added the timestamp attribute in communication session, this timestamp attribute is set to initial value (the current system time of correspondence when communication session is set up) when communication session is set up, and when receiving the affirmation message of message, upgrade, promptly be updated to the current system time when receiving acknowledge message. at every turn
Step 402, prolong the timeout interval of this message, and upgrade the time-out time in the monitor of this message correspondence according to the timeout interval after prolonging.
In this step, how many concrete prolongations of the timeout interval of message can be set flexibly according to the actual needs of system, for example, the timeout interval of message can be prolonged one times again on the basis of the original timeout interval of this message.
Step 403, retransmit this message.
In the above-mentioned steps 401, judge the process that communication session is whether overtime, comprising:
From the attribute of communication session, obtain the timestamp of this communication session;
The timestamp of communication session is added that the timeout interval of this communication session obtains the time-out time of this communication session;
Whether judgement received the affirmation message of message before the time-out time of communication session arrives, if receive, determine that then this communication session is not overtime; If do not receive, determine that then this communication session is overtime.
Wherein, the timeout interval of session is rule of thumb to be worth setting, for example, can be set to the twice of the timeout interval of message.
In concrete the application, can be when communication session be set up, the timestamp of this session is provided with the corresponding monitor of this communication session with the time that the timeout interval addition of session obtains, and when the communication session execution connects for the first time, start monitor the time-out time of this communication session is monitored.
In the above-mentioned steps 402, before the time-out time in the monitor that upgrades this message correspondence according to the timeout interval after prolonging, need judge, specifically comprise the validity of the time-out time after upgrading in the monitor:
Timeout interval after message prolonged with compare the life cycle of this message, greater than the latter, the timeout interval after then reducing to prolong makes its life cycle less than message as if the former.
In the above-mentioned flow process,, then recover the timeout interval of message, promptly revert to the timeout interval of message before prolonging, and the monitor of a piece of news is set down if before the time-out time of message after the prolongation arrives, received the affirmation message of message; If before the time-out time of message after the prolongation arrives, do not received the affirmation message of message, then utilize the timeout interval that prolongs back message that the monitor of a piece of news is set down.
Further, in the foregoing description, surpass certain number of times, then disconnect this connection if the overtime situation of communication session recurs.Because under the very poor situation of the connection state of communication session, even prolong the timeout interval of message, also be the affirmation message that can't receive message, if resend messages will increase nonsensical network load again, the aggravation network block up and unstable.
Corresponding above-mentioned flow process, the embodiment of the invention provides a kind of adjusting device of timeout interval of message, and as shown in Figure 5, this device comprises:
Two-way time, determining unit 501, were used for basis receives the affirmation message of message in the timeout interval of setting time, and the last transmitting time of this message, determined the actual two-way time of this message;
Timeout interval updating block 502 is used for the actual two-way time according to this message, and the ratio that is used for carrying the maximum carrying quantity of the carrying quantity of communication session message of this message and message, upgrades timeout interval.
As shown in Figure 6, among the embodiment, said apparatus also comprises the overtime judging unit 503 of communication session, when this unit is used for not receiving the affirmation message of described message in the timeout interval of setting, judges whether communication session is overtime;
Correspondingly, above-mentioned timeout interval updating block 502 also is used for, and when the overtime judging unit 503 of communication session determines that communication session is overtime, prolongs the timeout interval of message.
Further, among the embodiment, the overtime judging unit 503 of above-mentioned communication session specifically is used for, and judges in the timeout duration of session interval of setting whether receive the affirmation message of message, if do not receive, determines that then communication session is overtime.
Further, among the embodiment, above-mentioned timeout interval updating block 502 also is used for, and when receiving the affirmation message of this message in the timeout interval after message prolongs, timeout interval is updated to the preceding value of prolongation.
Pass through technique scheme, the embodiment of the invention fully takes into account the influence of the resource situation of the communication session that is used for bearer messages to transmission of messages, utilize the carrying quantity of message in actual two-way time that overtime message does not take place and the communication session to carry the ratio of quantity with the maximum of message, the timeout interval of updating message, make the timeout interval after the renewal more approaching with actual timeout interval, control re-transmission time of the message that needs retransmit effectively according to the timeout interval after upgrading, improved the efficiency of transmission of message.
In addition, in the embodiment of the invention, utilize and upgrade timeout interval the actual two-way time of re-transmission taking place and overtime message not taking place, make the timeout interval of determining more near actual timeout interval, because if message took place to retransmit, can not determine that then the affirmation message of this time returning is the affirmation message of message correspondence when transmitting for the first time, or the affirmation message of message correspondence when retransmitting.
In addition, in the embodiment of the invention, further contemplate the communication session connection state, under the bad situation of communication session connection state, timeout interval or interrupt communication session that can proper extension message, thus avoided unnecessary retransmission to message.
Obviously, those skilled in the art can carry out various changes and modification to the present invention and not break away from the spirit and scope of the present invention.Like this, if of the present invention these are revised and modification belongs within the scope of claim of the present invention and equivalent technologies thereof, then the present invention also is intended to comprise these changes and modification interior.