Summary of the invention
The embodiment of the present invention is designed to provide a kind of service shunting method based on load balancing, service distributing dressIt sets, electronic equipment and computer readable storage medium, and then overcomes the limitation due to the relevant technologies at least to a certain extentWith one or more problem caused by defect.
According to a first aspect of the embodiments of the present invention, a kind of service shunting method based on load balancing is provided, comprising:Obtain the current connection number of the maximum number of connections of each server and the client of each server currently connected;It willThe maximum number of connections of each server and the ratio of current connection number are as the power being polled to each serverWeight;The weight based on each server is ranked up the sequence of the poll of each server;It is receivingWhen the access request of client, the access request is distributed to by way of poll by each clothes based on the result of sequenceBusiness device.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the power based on each serverThe sequence of the poll of each server is ranked up again, comprising: the weight based on each server usesWeighted polling operation generates server series;Based on the server series to the sequence of the weighted polling of each serverIt is ranked up.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service shunting method further include: twoWhen the size of the weight of a server is identical, when obtaining response of described two servers to a upper access request respectivelyBetween;It is ranked up based on sequence of the response time to the poll of described two servers.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service shunting method further include: in instituteAfter stating server and the client successful connection, the maximum number of connections of the server is updated with predetermined time interval dynamicWith the ratio of current connection number;It is adjusted based on sequence of the result of update to the poll of each server.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service shunting method further include: in instituteWhen stating the weight of server less than predetermined threshold, the off-capacity of the server is determined;The client is linked by limitationThe server.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service shunting method further include: according toWhole portfolio and the average size of server dynamic adjust the quantity of the server.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service shunting method further include: recordAverage response time of each server to each access request;It is sent out when the average response time is more than predetermined thresholdIt alerts out.
According to a second aspect of the embodiments of the present invention, a kind of service distributing device based on load balancing is provided, comprising: evenSeveral acquiring units are connect, for obtaining the maximum number of connections of each server in rear end and currently connecting for each serverThe current connection number of client;Weight determining unit, for by the maximum number of connections of each server and current connection numberRatio as the weight being polled to each server;Sequencing unit, for the institute based on each serverWeight is stated to be ranked up the sequence of the poll of each server;Allocation unit, in the access for receiving clientWhen request, the access request is distributed to by way of poll by each server based on the sequence.
According to a third aspect of the embodiments of the present invention, a kind of electronic equipment is provided, comprising: processor;And memory, instituteIt states and is stored with computer-readable instruction on memory, realize when the computer-readable instruction is executed by the processor as above-mentionedService shunting method described in first aspect.
According to a fourth aspect of the embodiments of the present invention, a kind of computer readable storage medium is provided, calculating is stored thereon withMachine program realizes the service shunting method as described in above-mentioned first aspect when the computer program is executed by processor.
In the technical solution provided by some embodiments of the present invention, on the one hand, connect the maximum of each serverSeveral and current connection number ratio can be held as the weight being polled to each server based on the free time of each serverThe size of amount determines the weight being polled to each server;On the other hand, the weight based on each server is to each clothesThe sequence of the poll of business device is ranked up, and in the access request for receiving client, the result based on sequence passes through pollAccess request is distributed to each server by mode, can be according to the size of server free capacity in order by access request pointThe biggish server of dispensing idle capacity, can be avoided server and blocks, so as to stability and high efficiency to clientUser provides service.
It should be understood that above general description and following detailed description be only it is exemplary and explanatory, notIt can the limitation present invention.
Specific embodiment
Example embodiment is described more fully with reference to the drawings.However, example embodiment can be real in a variety of formsIt applies, and is not understood as limited to embodiment set forth herein;On the contrary, thesing embodiments are provided so that the present invention will be comprehensively and completeIt is whole, and the design of example embodiment is comprehensively communicated to those skilled in the art.Identical appended drawing reference indicates in figureSame or similar part, thus repetition thereof will be omitted.
In addition, described feature, structure or characteristic can be incorporated in one or more implementations in any suitable mannerIn example.In the following description, many details are provided to provide and fully understand to the embodiment of the present invention.However,It will be appreciated by persons skilled in the art that technical solution of the present invention can be practiced without one or more in specific detail,Or it can be using other methods, constituent element, device, step etc..In other cases, it is not shown in detail or describes known sideMethod, device, realization or operation are to avoid fuzzy each aspect of the present invention.
Block diagram shown in the drawings is only functional entity, not necessarily must be corresponding with physically separate entity.I.e., it is possible to realize these functional entitys using software form, or realized in one or more hardware modules or integrated circuitThese functional entitys, or these functional entitys are realized in heterogeneous networks and/or processor device and/or microcontroller device.
Flow chart shown in the drawings is merely illustrative, it is not necessary to including all content and operation/step,It is not required to execute by described sequence.For example, some operation/steps can also decompose, and some operation/steps can closeAnd or part merge, therefore the sequence actually executed is possible to change according to the actual situation.
Fig. 1 shows the flow diagram of service shunting method according to some embodiments of the present invention, the service distributingMethod is applied to server end.The service shunting method may include step S110 to step S140, below to the business of Fig. 1 pointStream method is described in detail.
Shown in referring to Fig.1, in step s 110, the maximum number of connections and each server of each server are obtainedThe client currently connected current connection number.
In the exemplary embodiment, can be arranged according to the size of the performance of the processor of each server, memory, hard disk everyThe maximum number of connections of the client that can be connected of a server.Each clothes are recorded on the server admin platform of server endBe engaged in device the client currently connected quantity, receiving the access request of new client and client and server connectsWhen being connected into function, the current connection number for the client of the server recorded on server admin platform currently connected is updated.
In the step s 120, using the ratio of the maximum number of connections of each server and current connection number as to eachThe weight that the server is polled.
In the exemplary embodiment, the maximum number of connections of each server and the ratio of current connection number can indicate serverIdle capacity size, such as the maximum number of connections of a server and the ratio of current connection number it is bigger, show the serviceThe idle capacity of device is bigger;Maximum number of connections and the ratio of current connection number are smaller, show that the idle capacity of the server is smaller.It, can using the maximum number of connections of each server and the ratio of current connection number as the weight being polled to each serverConvenient for being polled according to the size of the idle capacity of server to each server.
In step s 130, the sequence of the weight based on each server to the poll of each serverIt is ranked up.
In the exemplary embodiment, it is carried out according to sequence of the size of the weight of each server to the poll of each serverSequence.For example, setting rear end there are three server, such as server A, server B, server C, the weight of server A is 1, takesThe weight 3 that the weight of business device B is 2, server C, the sequence after being ranked up to server A, server B and server C areThe big server of weight is come front, at first the maximum server of poll weight by { server C, server B, server A },The bigger server of weight indicates that the idle capacity of server is more, and therefore, the data-handling capacity of the server is stronger, thusIt can be improved data-handling efficiency.
In step S140, in the access request for receiving client, based on the result of sequence by way of pollThe access request is distributed into each server.
In the exemplary embodiment, in the access request of received server-side to client, the result based on sequence passes throughThe access request is distributed to each server by the mode of poll.For example, being { server C, server B, server for sequenceA } sequence, be repeated in polling server C, server B and server A for access request and distribute to corresponding server.
In the example embodiment of Fig. 1, on the one hand, by the ratio of the maximum number of connections of each server and current connection numberAs the weight being polled to each server, can be determined based on the size of the idle capacity of each server to each clothesThe weight that business device is polled;On the other hand, the weight based on each server carries out the sequence of the poll of each serverSequence, in the access request for receiving client, the result based on sequence is distributed to access request by way of pollAccess request can be distributed to the biggish clothes of idle capacity in order according to the size of server free capacity by each serverBusiness device, can be avoided server and blocks, and provide service to the user of client so as to stability and high efficiency.
Further, in the exemplary embodiment, the access request of client is being distributed into server, and server withAfter client successful connection, it can be updated with such as 30 seconds dynamics of predetermined time interval by the maximum number of connections of each serverWith the ratio of current connection number, and based on update result the sequence of the weighted polling of each server is adjusted.
In addition, in the exemplary embodiment, when the weight of server is less than predetermined threshold, determining the capacity of the server notFoot, and limit client and be linked into the server.In the off-capacity for determining server, will be asked by Reverse ProxyThe client for accessing the server is asked to be diverted on the biggish server of weight.In the exemplary embodiment, predetermined threshold can rootIt is arranged according to the size of the performance of the processor of each server, memory, hard disk.
In some exemplary embodiments, it in the off-capacity for determining server, issues and holds to server admin platformMeasure insufficient warning information.
In addition, in the exemplary embodiment, service management platform can be according to whole portfolio, server average size dynamicAdjust the back-end server quantity to come into operation, the server that less input when whole portfolio is lower, so as to saveCost;More back-end servers are accessed when portfolio is uprushed, and so as to ensure to provide stable service, realize rear end clothesThe purpose of business device dynamic capacity reducing and dilatation.
In addition, in the exemplary embodiment, service management platform can record the average response time of service request and concurrentThe data such as amount give a warning when the response time being more than preset threshold.Further, it is also possible to combine the data of management platform to exceptionRequest is analyzed, if it is confirmed that the correlation function existing defects of the access request, can set this in server admin platform and connectThe concurrency for entering request is 0, limits the exception request and is sent to back-end server, further avoids server blocking.
Fig. 2 shows an exemplary embodiment of the present invention to be arranged based on sequence of the server series to weighted pollingThe flow diagram of sequence.
Referring to shown in Fig. 2, in step S210, the weight based on each server uses weighted polling operationGenerate server series.
In the exemplary embodiment, if there are three server, such as server A, server B, server C, server As for rear endWeight be 1, the weight of server B is 2, the weight 3 of server C, using Weighted Round Robin generate a server series{ C, C, C, B, B, A }.
In step S220, arranged based on sequence of the server series to the weighted polling of each serverSequence.
In the exemplary embodiment, the access request of 7 clients is often received, server A can be transmitted to 1 therein,It is transmitted to server B 2 therein, is transmitted to server C 3 therein.When receiving the 7th request, again from describedServer series start poll.
Fig. 3 is shown to be carried out based on sequence of the response time to two server polls according to example embodiment of the present inventionThe flow diagram of sequence.
Referring to shown in Fig. 3, in step s310, when the size of the weight of two servers is identical, obtain respectivelyResponse time of described two servers to a upper access request.
In the exemplary embodiment, server can reflect the current idle capacity of server to the response time of access requestSize and process performance, the response time is shorter, and the current spare capacity for indicating server is bigger, and the process performance of server is stronger.When the size of the weight of two servers is identical, response time of two servers all to a upper access request is obtained.
In step s 320, it is ranked up based on sequence of the response time to the poll of described two servers.
In the exemplary embodiment, the sequence of response time short server is come into front, access is asked according to serverThe size order for the response time asked handles access request.It can make the server priority processing client that process performance is strongThe access request at end, so as to further increase data-handling efficiency.
In addition, in an embodiment of the present invention, additionally providing a kind of service distributing device.Referring to shown in Fig. 4, the business pointFlowing device 400 may include: connection number acquiring unit 410, weight determining unit 420, sequencing unit 430 and allocation unit440.Wherein, connection number acquiring unit 410 be used for obtain each server in rear end maximum number of connections and each serviceThe current connection number for the client of device currently connected;Weight determining unit 420 is used for the most Dalian of each serverSeveral and current connection number ratio is connect as the weight being polled to each server;Sequencing unit 430 is for being based onThe weight of each server is ranked up the sequence of the poll of each server;Allocation unit 440 is used forIn the access request for receiving client, the access request is distributed to by way of poll based on the sequence eachThe server.
In some exemplary embodiments of the invention, aforementioned schemes are based on, sequencing unit 430 includes: server seriesGeneration unit generates server series using weighted polling operation for the weight based on each server;FirstSequencing unit, for being ranked up based on sequence of the server series to the weighted polling of each server.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service distributing device 400 further include:Response time acquiring unit obtains described two services when the size for the weight in two servers is identical respectivelyResponse time of the device to a upper access request;Second sequencing unit, for being based on the response time to described two serversThe sequence of poll be ranked up.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service distributing device 400 further include:Dynamic update unit, for being updated with predetermined time interval dynamic after the server and the client successful connectionThe ratio of the maximum number of connections of the server and current connection number;Adjustment unit, for the result based on update to each instituteThe sequence for stating the poll of server is adjusted.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service distributing device further include: capacityDetermination unit determines the off-capacity of the server when being less than predetermined threshold for the weight in the server;Limitation connectsEnter unit, the client is linked into the server for limiting.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service distributing device 400 further include:Server adjustment unit, for adjusting the server according to whole portfolio and the average size of server dynamicQuantity.
In some exemplary embodiments of the invention, it is based on aforementioned schemes, the service distributing device 400 further include:Recording unit, for recording each server to the average response time of each access request;Warning unit, in instituteIt is given a warning when stating average response time more than predetermined threshold.
In the example embodiment of Fig. 4, on the one hand, by the ratio of the maximum number of connections of each server and current connection numberAs the weight being polled to each server, can be determined based on the size of the idle capacity of each server to each clothesThe weight that business device is polled;On the other hand, the weight based on each server carries out the sequence of the poll of each serverSequence, in the access request for receiving client, the result based on sequence is distributed to access request by way of pollAccess request can be distributed to the biggish clothes of idle capacity in order according to the size of server free capacity by each serverBusiness device, can be avoided server and blocks, and provide service to the user of client so as to stability and high efficiency.
Each functional module and above-mentioned service distributing side due to the service distributing device 400 of example embodiments of the present inventionThe step of example embodiment of method, is corresponding, therefore details are not described herein.
In an exemplary embodiment of the present invention, a kind of electronic equipment that can be realized the above method is additionally provided.
Below with reference to Fig. 5, it illustrates the computer systems 500 for the electronic equipment for being suitable for being used to realize the embodiment of the present inventionStructural schematic diagram.The computer system 500 of electronic equipment shown in Fig. 5 is only an example, should not be to the embodiment of the present inventionFunction and use scope bring any restrictions.
As shown in figure 5, computer system 500 includes central processing unit (CPU) 501, it can be read-only according to being stored inProgram in memory (ROM) 502 or be loaded into the program in random access storage device (RAM) 503 from storage section 508 andExecute various movements appropriate and processing.In RAM 503, it is also stored with various programs and data needed for system operatio.CPU501, ROM 502 and RAM 503 is connected with each other by bus 504.Input/output (I/O) interface 505 is also connected to bus504。
I/O interface 505 is connected to lower component: the importation 506 including keyboard, mouse etc.;It is penetrated including such as cathodeThe output par, c 507 of spool (CRT), liquid crystal display (LCD) etc. and loudspeaker etc.;Storage section 508 including hard disk etc.;And the communications portion 509 of the network interface card including LAN card, modem etc..Communications portion 509 via such as becauseThe network of spy's net executes communication process.Driver 510 is also connected to I/O interface 505 as needed.Detachable media 511, such asDisk, CD, magneto-optic disk, semiconductor memory etc. are mounted on as needed on driver 510, in order to read from thereonComputer program be mounted into storage section 508 as needed.
Particularly, according to an embodiment of the invention, may be implemented as computer above with reference to the process of flow chart descriptionSoftware program.For example, the embodiment of the present invention includes a kind of computer program product comprising be carried on computer-readable mediumOn computer program, which includes the program code for method shown in execution flow chart.In such realityIt applies in example, which can be downloaded and installed from network by communications portion 509, and/or from detachable media511 are mounted.When the computer program is executed by central processing unit (CPU) 501, executes and limited in the system of the applicationAbove-mentioned function.
It should be noted that computer-readable medium shown in the present invention can be computer-readable signal media or meterCalculation machine readable storage medium storing program for executing either the two any combination.Computer readable storage medium for example can be --- but notBe limited to --- electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor system, device or device, or any above combination.MeterThe more specific example of calculation machine readable storage medium storing program for executing can include but is not limited to: have the electrical connection, just of one or more conducting wiresTaking formula computer disk, hard disk, random access storage device (RAM), read-only memory (ROM), erasable type may be programmed read-only storageDevice (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), light storage device, magnetic memory device,Or above-mentioned any appropriate combination.In the present invention, computer readable storage medium can be it is any include or storage journeyThe tangible medium of sequence, the program can be commanded execution system, device or device use or in connection.And at thisIn invention, computer-readable signal media may include in a base band or as carrier wave a part propagate data-signal,Wherein carry computer-readable program code.The data-signal of this propagation can take various forms, including but unlimitedIn electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be that computer canAny computer-readable medium other than storage medium is read, which can send, propagates or transmit and be used forBy the use of instruction execution system, device or device or program in connection.Include on computer-readable mediumProgram code can transmit with any suitable medium, including but not limited to: wireless, electric wire, optical cable, RF etc. are above-mentionedAny appropriate combination.
Flow chart and block diagram in attached drawing are illustrated according to the system of various embodiments of the invention, method and computer journeyThe architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generationA part of one module, program segment or code of table, a part of above-mentioned module, program segment or code include one or moreExecutable instruction for implementing the specified logical function.It should also be noted that in some implementations as replacements, institute in boxThe function of mark can also occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated are practicalOn can be basically executed in parallel, they can also be executed in the opposite order sometimes, and this depends on the function involved.Also it wantsIt is noted that the combination of each box in block diagram or flow chart and the box in block diagram or flow chart, can use and execute ruleThe dedicated hardware based systems of fixed functions or operations is realized, or can use the group of specialized hardware and computer instructionIt closes to realize.
Being described in unit involved in the embodiment of the present invention can be realized by way of software, can also be by hardThe mode of part realizes that described unit also can be set in the processor.Wherein, the title of these units is in certain situationUnder do not constitute restriction to the unit itself.
As on the other hand, present invention also provides a kind of computer-readable medium, which be can beIncluded in electronic equipment described in above-described embodiment;It is also possible to individualism, and without in the supplying electronic equipment.Above-mentioned computer-readable medium carries one or more program, when the electronics is set by one for said one or multiple programsWhen standby execution, so that the electronic equipment realizes such as above-mentioned service shunting method as described in the examples.
For example, the electronic equipment may be implemented as shown in Figure 1: step S110 obtains the maximum of each serverThe current connection number of connection number and the client of each server currently connected;Step S120, by each clothesThe maximum number of connections of business device and the ratio of current connection number are as the weight being polled to each server;StepS130, the weight based on each server are ranked up the sequence of the poll of each server;StepS140, in the access request for receiving client, based on the result of sequence by the access request point by way of pollThe each server of dispensing.
It should be noted that although being referred to several modules for acting the device executed in the above detailed descriptionOr unit, but this division is not enforceable.In fact, embodiment according to the present invention, above-described twoOr more the feature and function of module or unit can be embodied in a module or unit.Conversely, above-describedOne module or the feature and function of unit can be to be embodied by multiple modules or unit with further division.
Through the above description of the embodiments, those skilled in the art is it can be readily appreciated that example described herein is implementedMode can also be realized by software realization in such a way that software is in conjunction with necessary hardware.Therefore, according to the present inventionThe technical solution of embodiment can be embodied in the form of software products, which can store non-volatile at oneProperty storage medium (can be CD-ROM, USB flash disk, mobile hard disk etc.) in or network on, including some instructions are so that a calculatingEquipment (can be personal computer, server, touch control terminal or network equipment etc.) executes embodiment according to the present inventionMethod.
Those skilled in the art after considering the specification and implementing the invention disclosed here, will readily occur to of the invention itsIts embodiment.This application is intended to cover any variations, uses, or adaptations of the invention, these modifications, purposes orPerson's adaptive change follows general principle of the invention and including the undocumented common knowledge in the art of the present inventionOr conventional techniques.The description and examples are only to be considered as illustrative, and true scope and spirit of the invention are by followingClaim is pointed out.
It should be understood that the present invention is not limited to the precise structure already described above and shown in the accompanying drawings, andAnd various modifications and changes may be made without departing from the scope thereof.The scope of the present invention is limited only by the attached claims.