Summary of the invention
In view of this, solving upper layer this application provides a kind of method and apparatus that control remote service calls frequency
System accurately cannot voluntarily adjust the technical issues of calling frequency.
In order to solve the above-mentioned technical problem, this application discloses a kind of methods that control remote service calls frequency, comprising:
Determine the expection duration for initiating to call every time;Statistics initiates the practical duration called every time;Judge whether the practical duration is small
In the expected duration;When the practical duration is less than the expected duration, into dormant state, the dormant state is held
Continuous duration is within the scope of the expected duration subtracts the maximum deviation of the difference of the practical duration.
The expection duration called is initiated in the determination every time, comprising: according to the number of threads for initiating to call and called system
The maximum of system calls frequency, determines the expected duration.
The expected duration expect_time=1 ÷ max_freq × thread_num;Wherein, max_freq represents institute
It states the maximum of called system and calls frequency, thread_num represents the number of threads for initiating to call.
The statistics initiates the practical duration called every time, comprising: record starts to process first when each Transaction Information
The second moment when moment and each complete call;Second moment is subtracted into the difference at first moment as the reality
Duration.
The method also includes: at the end of the dormant state, statistics initiates the practical duration called next time.
The method also includes: when the practical duration is greater than or equal to the expected duration, statistics is initiated next time
The practical duration called.
The method also includes: Transaction Information is obtained from database every predetermined period.
It is described that Transaction Information is obtained from database every predetermined period, comprising: each thread obtains Transaction Information every time
Quantity data_num=max_freq × interval ÷ thread_num;Wherein, max_freq represents called system
Maximum calls frequency, and thread_num represents the number of threads for initiating to call, and interval represents the predetermined period.
It is described at the end of the dormant state, or when the practical duration is greater than or equal to the expected duration
Method further include: judge whether the Transaction Information obtained is all disposed;When the Transaction Information of the acquisition is not handled all
When finishing, statistics initiates the practical duration called next time.
In order to solve the above-mentioned technical problem, disclosed herein as well is the device that a kind of control remote service calls frequency, packets
It includes: determining module, for determining the expection duration for initiating to call every time;Statistical module, for counting the reality for initiating to call every time
Border duration;First judgment module, for judging whether the practical duration is less than the expected duration;Sleep block, for working as
When the practical duration is less than the expected duration, into dormant state, the duration of the dormant state is in the expection
Duration subtracts within the scope of the maximum deviation of the difference of the practical duration.
The determining module comprises determining that submodule, for according to the number of threads and called system for initiating to call
Maximum calls frequency, determines the expected duration.
The expected duration expect_time=1 ÷ max_freq × thread_num;Wherein, max_freq represents quilt
The maximum of calling system calls frequency, and thread_num represents the number of threads for initiating to call.
The statistical module includes: record sub module, and the first moment when each Transaction Information is started to process for recording
With the second moment when each complete call;Submodule is handled, for second moment to be subtracted to the difference at first moment
As the practical duration.
The statistical module is further used at the end of the dormant state, and statistics initiates the reality called next time
Duration.
The statistical module is further used for when the practical duration is greater than or equal to the expected duration, under statistics
The primary practical duration for initiating to call.
Described device further include: module is obtained, for obtaining Transaction Information from database every predetermined period.
It is described obtain each thread of module obtain every time the quantity data_num=max_freq of Transaction Information ×
interval÷thread_num;Wherein, wherein max_freq represents the maximum of called system and calls frequency, thread_
Num represents the number of threads for initiating to call, and interval represents the predetermined period.
Described device further include: the second judgment module, at the end of working as the dormant state, or when described practical
When length is greater than or equal to the expected duration, judge whether the Transaction Information obtained is all disposed;The statistical module, into
One step is used for when the Transaction Information of the acquisition is not disposed all, and statistics initiates the practical duration called next time.
Compared with prior art, the application can be obtained including following technical effect: the practical duration for initiating to call is less than
It is expected that making up the time difference of practical duration and expected duration by suspend mode when duration, postponement continues to initiate to call next time, from
And achievees the effect that accurately to control and call frequency.
Certainly, any product for implementing the application must be not necessarily required to reach all the above technical effect simultaneously.
Specific embodiment
Carry out the embodiment that the present invention will be described in detail below in conjunction with accompanying drawings and embodiments, how the present invention is applied whereby
Technological means solves technical problem and reaches the realization process of technical effect to fully understand and implement.
Fig. 2 is a kind of method that control remote service calls frequency provided by the embodiments of the present application, is suitable for server system
System, this approach includes the following steps.
In step slo, the expection duration for initiating to call every time is determined.
Server system calls frequency max_freq according to the maximum of called system, determines the expection for initiating to call every time
Duration.The a length of fixed value when expection represents the time interval between the calling twice initiated to the system that is called.
In step s 11, statistics initiates the practical duration called every time.
A length of each process practical duration expended for initiating to call when this is practical.
In step s 12, judge whether practical duration is less than expected duration;
Since the expection duration is determining according to the maximum calling frequency for the system of being called, so if call every time
Practical duration is both less than the expection duration, then the actual maximum calling frequency for calling frequency that can be higher than called system, can lead
Cause the pressure of handling up of called system excessive.
In step s 13, when length is less than expected duration when practical, into dormant state, the duration of dormant state
Within the scope of the maximum deviation for the difference that expected duration subtracts practical duration.
Practical maximum the case where calling frequency for calling frequency to be higher than called system, occurs in order to prevent, calls when each
Practical duration when being less than expected duration, force local system to enter dormant state.The duration of the dormant state is in expection
Duration subtracts within the scope of the maximum deviation of the difference of practical duration.That is the duration of the dormant state can be expected duration and subtract
Go the difference or the slightly larger or slightly smaller difference that practical duration is subtracted in the expection duration of practical duration.When dormant state it is lasting when
It is long when being slightly less than expected duration and subtracting the difference of practical duration, it is possible to will appear practical callings frequency slightly larger than the system of being called
Maximum calls the situation of frequency, so as to cause system trigger current limliting strategy.Accordingly, it is preferred that the duration of dormant state should wait
The difference of practical duration is subtracted in or slightly larger than expected duration, and the maximum deviation range should not be too large, if the maximum deviation
Range, which crosses conference, reduces the utilization rate of flow system flow, which preferably subtracts the difference of practical duration in the expection duration
± 2% within.For example, call every time expection when a length of 100ms, i.e., call twice between expected time interval be
100ms, it is current complete once to call it is practical when a length of 80ms, then be expected duration and subtract the difference of practical duration to be 20ms, it is contemplated that
The maximum deviation range that duration subtracts the difference of practical duration is 19.96ms-20.04ms, in order to avoid triggering the current limliting plan of system
Slightly, the duration of dormant state is preferably in 20ms-20.04ms.
When the practical duration called every time is less than expected duration, the time between expected duration is made up by suspend mode
Difference prevents practical calling frequency to be higher than the maximum calling frequency of called system to accurately control local calling frequency
Situation occurs.
When length is greater than or equal to expected duration when practical, then return step S11, continues statistics and initiates calling next time
Practical duration;After the dormant state in step S13, return step S11 continues statistics and initiates the reality called next time
Duration.
The method for calling frequency using above-mentioned control remote service initiates calling amount curve when calling to called system
For schematic diagram as shown in figure 3, compared with the calling amount curve shown in FIG. 1 used under current-limit mode in the prior art, the application is real
The method that the control remote service for applying example offer calls frequency can generate more reasonable calling amount utilizing status, can only there is timing
Brought slight calling amount loss when being adjusted between task switching for the protection of global data capacity, if timing is appointed
Being engaged in, the period is longer, and the number of adjustment is fewer, and the loss of this calling amount also can be fewer.Calling amount is by being called system most
Continue dynamic below the big numerical value for calling frequency to be limited to adjust, current-limit mode will not be triggered and come into force, realize and exchange dosage
Smoothing processing more fully utilizes the calling amount between this system and called system.
Fig. 4 is the application scenarios schematic diagram for the method that control remote service provided by the embodiments of the present application calls frequency, packet
Include database and system A and system B.System A obtains Transaction Information according to predetermined period from database, by local data
After processing, then the remote service function of far call system B completes subsequent data processing.Wherein, system B is as system A's
Underlying system provides remote service function to system A, provides maximum call to system A according to the performance of the remote service function
Frequency max_freq;System A is obtained from database by the way of multi-threading parallel process every predetermined period interval
A collection of Transaction Information, and the remote service function provided to system B initiate to call.System A initiates the thread called to system B
Quantity is thread_num, then per thread once obtains quantity data_num=max_freq × interval of Transaction Information
÷thread_num.By being called frequency max_freq to be limited by the maximum of system B, system A is every predetermined period interval
The Transaction Information amount obtained from database should be less than or be equal to max_freq × interval, i.e., calls frequency max_ with the maximum
On the basis of freq, the maximum transaction data volume that B system is able to bear in this duration of predetermined period interval is obtained.System
A unite according to the mode of multi-threading parallel process, then per thread once obtains the quantity data_num=max_ of Transaction Information
Freq × interval ÷ thread_num, the Transaction Information amount for obtaining system A every predetermined period is all in the receiving of system B
Within ability.For example, maximum frequency max_freq=100tps (Transactions Per Second, thing that system B is provided
Number of being engaged in is per second), system A obtains the predetermined period interval=1s of data from database, and by 10 thread parallels from
Database obtains Transaction Information, then per thread once obtains quantity data_num=100t/s × 1s ÷ 10=of Transaction Information
10t (Transactions, number of transactions).It realizes and is controlled according to the maximum calling frequency that the system of being called provides every time from data
The Transaction Information amount that library is got, it is ensured that no more than the ability to bear of underlying system.So system A is in the affairs that ensure that acquisition
The frequency called is initiated it is necessary to further go to control to system B after ability to bear of the data volume no more than system B, makes calling amount
It is steady controllable, the calling amount between system A and system B was both made full use of, while to prevent the tune instantaneously initiated to system B
The excessively high phenomenon of dosage occurs.
For system A it needs to be determined that initiating the expection duration called every time, which represents what system A was initiated to system B
Time interval between calling twice.Therefore, system A is according to the number of threads thread_num and called system for initiating to call
It is maximum call frequency max_freq, determine the expection duration (time between calling twice that each thread initiates to call every time
Interval) expect_time=1 ÷ max_freq × thread_num.Since the system B maximum calling frequency provided is max_
Freq, then system A should be greater than to the time interval that system B initiates to call or be equal to 1 ÷ max_freq, if system A is using more
Thread parallel to system B initiate call, then per thread initiate call expection duration should be greater than or be equal to 1 ÷ max_freq ×
thread_num.For example, the maximum frequency max_freq=100tps that system B is provided, system A are by 10 thread parallels to being
The B that unites initiates to call, then per thread initiates the expection duration expect_time=1 ÷ 100tps × 10=100ms/t called,
That is minimum value of the system A per thread to the system B expection duration (initiating the time interval between calling twice) for initiating to call
It should be 100ms.If practical duration is less than the expection duration, illustrating that system A has exceeded to the frequency that system B initiates to call is
The endurance of system B, therefore next system A will be counted and be initiated the practical duration called to system B every time, to determine whether being more than
What system B was provided maximum calls frequency.
System A statistics initiates the method for the practical duration called as shown in figure 5, including the following steps every time.
In step S20, record starts to process the first moment when each Transaction Information.
Since the expection duration for initiating to call every time refers to the time interval between calling twice, hair every time is counted
It, be at the beginning system A including consumed duration calculation when acting the practical duration called system A processing Transaction Information
First moment is recorded when managing each Transaction Information, as the initial time for calculating practical duration.When system A uses multithreading simultaneously
When capable mode is initiated to call to system B, then the first moment when each thread starts to process each Transaction Information is recorded.
In the step s 21, system A handles Transaction Information.
In step S22, system A initiates far call to system B.
In step S23, the second moment when the far call of the complete paired systems B of system A is recorded.
Second moment is as the finish time for calculating practical duration.
In step s 24, it regard the difference that the second moment subtracted for the first moment as practical duration.
In step s 25, judge whether practical duration is less than expected duration.When length is less than expected duration when practical, hold
Row step S26;When length is greater than or equal to expected duration when practical, return step S20.
In step S26, system A enters dormant state, and the duration of the dormant state subtracts reality in expected duration
Within the scope of the maximum deviation of the difference of duration.
When practical duration is less than expected duration, current calling frequency is represented higher than the maximum of system B and calls frequency, system
The pressure of handling up of B can be excessive.In order to delay system A initiation to call next time, system A is forced to enter dormant state, to make up reality
Time difference between border duration and expected duration.When the duration of dormant state reaches the difference that expected duration subtracts practical duration
When, terminate the dormant state, starts statistics and initiate the practical duration called, i.e. return step S20 next time, record is opened next time
The first moment when the processing Transaction Information that begins.When practical duration is greater than or equal to expected duration, it is small to represent current calling frequency
Frequency is called in or equal to the maximum of system B, within the ability to bear in system B, can initiate to call next time immediately, this
When start statistics and initiate the practical duration called next time, i.e. return step S20, record is when starting to process Transaction Information next time
The first moment.
In one embodiment, after the dormant state in step S26 terminates, or reality is judged in step s 25
Before border duration needs return step S20 more than or equal to expected duration, as shown in fig. 6, further comprising the steps of.
In step s 27, system A judges whether the Transaction Information obtained is all disposed.When the Transaction Information of acquisition
When being all disposed, then terminate this process;When the Transaction Information of acquisition is not disposed all, return step S20.It is logical
The auxiliary of step S27 is crossed, system A can more accurately control the treatment process to the Transaction Information of acquisition, it is ensured that acquisition
Transaction Information can be handled in time, also guarantee the treatment effeciency of Transaction Information while the calling amount of held stationary.
It can prevent from shaking because of network transmission state or the data processing performance of itself using above-mentioned process flow
And there is instantaneous calling and measure excessively high situation.For example, it is no using above-mentioned process flow in the case where, system A and system B it
Between network transmission performance decline suddenly, system A can be made to initiate the time spent by far call to system B and increased, and when being
Network transmission performance between system A and system B restores suddenly again when, it may appear that system A is instantaneously initiating multiple call to system B
The case where, call frequency in the maximum calling frequency that can be instantaneously higher than system B offer, and above-mentioned process flow is used, energy
When there is above situation, calling frequency of the system A to system B is controlled within the ability to bear of system B.Similarly, when being
When the data processing performance of system A itself is shaken, it also can be avoided by above-mentioned process flow and system A occur to system B's
Call frequency in instantaneous excessively high situation.
Fig. 7 is the device that control remote service provided in an embodiment of the present invention calls frequency, comprising:
Determining module 30, for determining the expection duration for initiating to call every time;
Statistical module 31, for counting the practical duration for initiating to call every time;
First judgment module 32, for judging whether practical duration is less than expected duration;
Sleep block 33, for when practical it is long be less than expected duration when, into dormant state, dormant state it is lasting when
It grows within the scope of the maximum deviation for the difference that expected duration subtracts practical duration.
The determining module packet 30 comprises determining that submodule, for according to the number of threads and called system for initiating to call
It is maximum call frequency, determine expected duration.
Expection duration expect_time=1 ÷ max_freq × thread_num;Wherein, max_freq representative is adjusted
Maximum with system calls frequency, and thread_num represents the number of threads for initiating to call.
The statistical module 31 includes: record sub module, for record every time initiate call when the first moment and every time it is complete
At the second moment when calling;Submodule is handled, the difference for the second moment to be subtracted for the first moment is used as practical duration.
In one embodiment, the statistical module 31 is further used at the end of the dormant state, and statistics is next time
Initiate the practical duration called;When the practical duration is greater than or equal to the expected duration, statistics is initiated to call next time
Practical duration.
The device further includes obtaining module 34, for obtaining Transaction Information from database every predetermined period.The acquisition
Module 34 obtains quantity data_num=max_freq × interval ÷ thread_num of Transaction Information every time;Wherein,
Max_freq represents the maximum of called system and calls frequency, and thread_num represents the number of threads for initiating to call,
Interval represents the predetermined period.
In one embodiment, the device further include: the second judgment module 35, at the end of working as dormant state, or
When length is greater than or equal to expected duration when practical, judge whether the Transaction Information obtained is all disposed;
The then statistical module 31 is further used for when the Transaction Information of acquisition is not disposed all, and statistics is next time
Initiate the practical duration called.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net
Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or
The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flashRAM).Memory is showing for computer-readable medium
Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves
State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable
Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM),
Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or other magnetic storage devices
Or any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, it calculates
Machine readable medium does not include non-temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
As used some vocabulary to censure specific components in the specification and claims.Those skilled in the art answer
It is understood that hardware manufacturer may call the same component with different nouns.This specification and claims are not with name
The difference of title is as the mode for distinguishing component, but with the difference of component functionally as the criterion of differentiation.Such as logical
The "comprising" of piece specification and claim mentioned in is an open language, therefore should be construed to " include but do not limit
In "." substantially " refer within the acceptable error range, those skilled in the art can within a certain error range solve described in
Technical problem basically reaches the technical effect.In addition, " coupling " word includes any direct and indirect electric property coupling herein
Means.Therefore, if it is described herein that a first device is coupled to a second device, then representing the first device can directly electrical coupling
It is connected to the second device, or the second device indirectly electrically coupled through other devices or coupling means.Specification
Subsequent descriptions are to implement better embodiment of the invention, so the description be for the purpose of illustrating rule of the invention,
The range being not intended to limit the invention.Protection scope of the present invention is as defined by the appended claims.
It should also be noted that, the terms "include", "comprise" or its any other variant are intended to nonexcludability
Include, so that commodity or system including a series of elements not only include those elements, but also including not clear
The other element listed, or further include for this commodity or the intrinsic element of system.In the feelings not limited more
Under condition, the element that is limited by sentence "including a ...", it is not excluded that in the commodity or system for including the element also
There are other identical elements.
Several preferred embodiments of the invention have shown and described in above description, but as previously described, it should be understood that the present invention
Be not limited to forms disclosed herein, should not be regarded as an exclusion of other examples, and can be used for various other combinations,
Modification and environment, and the above teachings or related fields of technology or knowledge can be passed through within that scope of the inventive concept describe herein
It is modified.And changes and modifications made by those skilled in the art do not depart from the spirit and scope of the present invention, then it all should be in this hair
In the protection scope of bright appended claims.