The content of the invention
The present invention solves the technical problem of the offer a kind of service load balancing method and device of distributed system,
Make it possible to judge more rationally, exactly the busy extent of Services in Distributed System, the generation of effective control system overload is general
Rate, and all hardware resource in distributed system can be more effectively utilized, realize to the spirit between each service on server
Deployment living.
In order to solve the above-mentioned technical problem, the invention provides a kind of service load balancing method of distributed system, it is
Each service is distributed in each server of different industrial networks in system, and a service is distributed on multiple servers, by multiple clothes
Business device provides same services, carries out Backup service, service based on one of them service, and remaining is backup services, each service pair
Multiple network interfaces are answered, network backup are carried out, the method includes the steps of:
Each service is preserved with the corresponding relation between the resource object that service is used and respectively servicing corresponding network interface;
The load of server where the load of main service exceeds pre-determined threshold, or main service is corresponding beyond pre-determined threshold, or main service
At least n network interface flow is less than at least m network interface flow in minimum normal value, or the corresponding each network interface of main service and surpassed in each network interface
When going out maximum limit value, active-standby switch is carried out with active service to the main service, wherein, m, n are more than or equal to 1, less than or equal to this
Service corresponding all network interface quantity;
When receiving the service request from client, service name and resource object title in request are found
Current corresponding main service, to this it is main service corresponding each network interface flow and select, multiple idle network interfaces are therefrom selected, by sky
The corresponding access address of not busy network interface returns to client;Client obtains asked service from access address.
As the improvement of above-mentioned technical proposal, the service load can include:The number of threads of service;The server load
It can include:Cpu load, and/or memory usage.
As the improvement of above-mentioned technical proposal, before the step of carrying out active-standby switch with active service to the main service, also
It can comprise the steps of:The information on load of server where the information on load of each main service of timing acquisition, the main service and should
It is main to service corresponding each network interface flow.
As the improvement of above-mentioned technical proposal, service name and resource object title in request, it is current right to find
Before the main service answered, the step of selecting the corresponding each network interface flow of main service, can also further it include following
Step:
Each service in system is registered, the corresponding relation between the resource object that service and the service are used is preserved,
Service the corresponding relation between network interface, service is with institute's corresponding relation between servers, main information on services in respectively servicing;
Service name and resource object title in request, find current corresponding main service, to the main service pair
In the step of each network interface flow answered is selected, currently requested main service is found according to the corresponding relation of registration and should
It is main to service corresponding network interface.
As the improvement of above-mentioned technical proposal, after the step of carrying out active-standby switch with active service to the main service, bag
Containing following steps:The main information on services after switching is updated in log-on message.
As the improvement of above-mentioned technical proposal, each network interface flow corresponding to the main service is selected, and therefrom selection is more
In the step of individual idle network interface, one primary idle network interface of selection and a standby idle network interface;
In the step of corresponding access address of the network interface is returned into client, the access address of return at least includes:Clothes
Business name, primary network interface IP address+port numbers, the IP address of standby network interface.
Present invention also offers a kind of service load balancing device of distributed system, each service is distributed in difference in system
In each server of industrial network, a service is distributed on multiple servers, and same services are provided by multiple servers, is carried out
Backup service, is serviced based on one of service, remaining is backup services, the multiple network interfaces of each service correspondence, carries out network standby
Part, the device is included:
Memory module, for preserving corresponding relation and each service between the resource object that each service and service are used
Corresponding network interface;Active-standby switch module, for carrying out active-standby switch between main service and active service;Monitoring module, is used for
The load of server where the load of main service exceeds pre-determined threshold, or main service exceeds pre-determined threshold, or main service correspondence
Each network interface at least n network interface flow be less than at least m network interface flow in minimum normal value, or the corresponding each network interface of main service
During beyond maximum limit value, indicate that active-standby switch module carries out active-standby switch to the main service with active service, wherein, m, n are big
In equal to 1, all network interface quantity corresponding less than or equal to the service;Network interface selecting module, for receiving from client
During service request, service name and resource object title in request find current corresponding main service, to the main service
Corresponding each network interface flow is selected, and therefrom selects multiple idle network interfaces;Entrance returns to module, for by network interface selecting module
The corresponding access address of idle network interface of selection returns to client, indicates that client obtains asked clothes from access address
Business.
As the improvement of above-mentioned technical proposal, service load can include:The number of threads of service;And server load can
With including:Cpu load, and/or memory usage.
As the improvement of above-mentioned technical proposal, the device can also be included:Data obtaining module, for each master of timing acquisition
The information on load of server where the information on load of service, the main service and the corresponding each network interface flow of the main service.
As the improvement of above-mentioned technical proposal, the device can also be included further:Registering modules, for each in system
Service is registered, and will service corresponding relation between the resource object that uses of the service, service with it is corresponding between network interface
Relation, service and institute's corresponding relation between servers, main information on services is stored in the memory module in respectively servicing;
Network interface selecting module finds the corresponding main clothes of currently requested service according to the corresponding relation preserved in memory module
Business and the corresponding network interface of main service.
As the improvement of above-mentioned technical proposal, Registering modules are additionally operable to after active-standby switch module carries out active-standby switch, more
Main information on services after new switching, and the main information on services after updating is preserved in a storage module.
As the improvement of above-mentioned technical proposal, following submodule is further included in network interface selecting module:
Select the submodule of a primary idle network interface;
Select the submodule of a standby idle network interface;
The access address that entrance returns to module return can include:It is Service name, primary network interface IP address+port numbers, standby
The IP address of network interface.
Compared with prior art, the main distinction and its effect are embodiment of the present invention:In a distributed system, will be each
Service is distributed in each server of different industrial networks, and a service is distributed on multiple servers, is carried by multiple servers
For same services, Backup service is carried out, is serviced based on one of them service, remaining is backup services, each service is corresponding multiple
Network interface, for carrying out network backup.And the load of server surpasses where the load of main service exceeds pre-determined threshold, or main service
Go out pre-determined threshold, or the flow of the corresponding each network interface of main service is less than minimum normal value, or the main stream for servicing corresponding each network interface
When amount exceeds maximum limit value, active-standby switch is carried out with active service to the main service.Please in the service from client that receives
When asking, service name and resource object title in request find current corresponding main service, corresponding to the main service
Each network interface flow is selected, and therefrom selects multiple idle network interfaces, and the corresponding access address of idle network interface is returned into client,
Client obtains asked service from access address.Load balancing is carried out according only to network interface flow relative to prior art, this
Invention embodiment is synthetically considering the load condition of service, the load condition of server and the service pair where the service
After each network interface flow answered, the busy extent of the service is just determined, judges whether to be adapted to be continuing with the service, and according to judgement
As a result the switching of principal and subordinate's service is carried out, so as to be effectively prevented from because determining service or server only by uninterrupted
One-sidedness caused by availability, prevents from interacting partial information less but calculating the erroneous judgement of complicated service, and can be more accurate
Ground judges busy, the appropriate of service, the probability of happening of effective control system overload.Also, prior art is generally basede on clothes
Business device carries out load balancing, i.e., integrally carry out active-standby switch to server during load balancing, but in practical application,
The operation load respectively serviced on synchronization, server is differed, if carrying out overall switching based on server, then can be by
All normal or extra-heavy service is switched on another server on the server, easily causes another server
It is busy, also, one in synchronization only enables active/standby server, do not make full use of existing hardware resource.And
In embodiment of the present invention, all extra-heavy main services on server are only subjected to active-standby switch with active service, so as to
Enough ensure more effectively to utilize all hardware resource, and flexible deployment preferably can be carried out to each service on server.
Embodiment
To make the object, technical solutions and advantages of the present invention clearer, the implementation below in conjunction with accompanying drawing to the present invention
Mode is described in further detail.
First embodiment of the invention is related to a kind of service load balancing method of distributed system, in distributed system
In, each service is distributed in each server of different industrial networks, and a service is distributed on multiple servers, by multiple services
Device provides same services, carries out Backup service, is serviced based on one of them service, remaining is backup services, and each service is corresponding
Multiple network interfaces, for carrying out network backup.
Each service needs to be registered in distributed system, when carrying out service registry, it is necessary to preserve service and the service
Corresponding relation between the resource object used, service the corresponding relation between network interface, service with pair between servers
It should be related to, and main information on services in each service, it can all be stored in registration table.The preservation of main information on services can have various shapes
Formula, such as comes service based on the service i.e. of foremost in the corresponding relation.
The service load balancing method of specific distributed system includes active and standby service and judges switching and service network interface selection
Two parts, wherein judgement and the switching flow of active and standby service, as shown in Figure 1.
In a step 101, the information on load of server where the information on load of each main service of timing acquisition, the main service,
With the corresponding each network interface flow of main service.
Wherein, the mode of each information of the main service of timing acquisition can have a variety of, such as:Can be in each main service active
Report;It can also actively be asked for from the server of carry out load balancing to each main service;Or, a service operation can also be set
Platform(For management service), timed collection service operation state, and regularly report.This several reporting schemes does not influence this reality
Apply the final effect of mode.
The load of main service can include:The information such as the number of threads of service.Specifically, service load balancing device can
Load is determined with the number of threads reported according to the service.For example, real-time data base can determine to bear according to subscription
Lotus amount.And server load can include:The information such as cpu load, memory usage.For example, each main service is every very
The information such as the cpu load and memory usage of server where clock just reports this service.
The information that service load balancing device is reported according to each main service, load in real time to each main service, main service institute
It is monitored in the corresponding each network interface flow of the load of server and main service, as shown in step 102 to step 105.
In a step 102, judge whether the load of main service exceeds pre-determined threshold.If the load of main service is beyond default
Thresholding, then into step 106;If the load of main service is without departing from pre-determined threshold, into step 103.The load of main service
It can be included beyond pre-determined threshold:The number of threads of main service is beyond pre-determined threshold etc..
In step 103, whether the load of server where judging main service exceeds pre-determined threshold.If where main service
The load of server exceeds pre-determined threshold, then into step 106;If the load of server is without departing from pre- gating where main service
Limit, then into step 104.
Specifically, server load can include:Cpu load and memory usage.And the server where main service
Load can also include a variety of situations beyond pre-determined threshold, such as the cpu load of server where main service exceed pre-determined threshold;
The memory usage of server is beyond pre-determined threshold etc. where main service.Wherein, when server meets any of the above-described situation, quilt
The load for regarding as the server exceeds pre-determined threshold.
At step 104, judge whether main service is having at least n network interface flow less than minimum just in corresponding each network interface
Whether constant value, i.e. network are obstructed.If main service in corresponding each network interface has more than n(Containing n)Individual network interface flow is less than minimum
Normal value, then judge network failure, into step 106;If flow is normal less than minimum in the corresponding each network interface of main service
The network interface quantity of value is less than n, then judges that network is normal, into step 105.Wherein n can be set according to actual conditions, and n is big
In equal to 1, all network interface quantity corresponding less than or equal to the service.Assuming that n is 1, as long as then in the corresponding each network interface of main service
There is a network interface flow to be less than minimum normal value, that is, its network failure is thought, into step 106;Otherwise it is assumed that network is normal, enter
Enter step 105.
In step 105, judge whether main service has at least m network interface flow to be limited beyond highest in corresponding each network interface
Whether value processed, i.e. network are excessively busy.If more than m(Containing m)Individual network interface flow exceeds maximum limit value, then illustrates that network is excessively busy,
Be not suitable for being further added by new service, into step 106;If the network interface quantity in each network interface beyond maximum limit value is less than m,
Think that network is normal, return to step 101, server is negative where information on load again in real time to each main service, the main service
Lotus information and the corresponding each network interface flow of the main service carry out circularly monitoring.Wherein m can be set according to actual conditions, and m is more than
Equal to 1, all network interface quantity corresponding less than or equal to the service.Assuming that m is 3, then have in the corresponding each network interface of main service 3 with
On(Containing 3)Network interface flow exceeds maximum limit value, just thinks that the server network is excessively busy, into step 106;Otherwise it is assumed that net
Network is normal, return to step 101.
In step 106, active and standby service is carried out to the main service and active service to switch.Active-standby switch is being carried out to service
Afterwards, the main information on services after switching is updated in log-on message.Step 101 is then returned to, each main service is born in real time again
The information on load of server where lotus information, the main service and the corresponding each network interface flow of the main service continue cycling through monitoring.
It can be seen that, by above-mentioned flow, when the service of some in system or the server where it go wrong, service is negative
Carrying balancing equipment can automatically be detected and respective service is switched into active service, stop service request being distributed to the event
The service of barrier, and continue to provide the service by other services working properly.
Load balancing is carried out according only to network interface flow relative to prior art, present embodiment is synthetically considering service
Load condition, after load condition each network interface flow corresponding with the service of server where the service, just determine the service
Busy extent, judge whether to be adapted to be continuing with the service, and the switching of principal and subordinate's service is carried out according to judged result.So as to
It can be effectively prevented from, because of one-sidedness caused by the availability for determining service only by uninterrupted, preventing from handing over partial information
Mutually less but the erroneous judgement of complicated service is calculated, and can more precisely judge busy, the appropriate of service, effective control system
The probability of happening of overload.And prior art is generally basede on server and carries out load balancing, i.e., to service during load balancing
Device integrally carries out active-standby switch, and present embodiment is based on service and carries out active-standby switch, only by all overburdens on server(Bag
Include service overburden, server overburden, service that corresponding network interface flow is excessive or suspension)Main service and active service carry out
Active-standby switch, the former server where before service switching still can provide other not extra-heavy services, so as to ensure
All hardware resource is more effectively utilized, the flexible deployment to respectively being serviced on server is realized.
The selection that network interface is serviced in service load balancing is illustrated below:
When receiving the service request from client, service name and resource object title in request are found
Current corresponding main service, each network interface flow corresponding to the main service is selected, therefrom selection free time network interface, by idle net
The corresponding access address of mouth returns to client, and client obtains asked service from the access address.It is specific distributed
The selection flow of network interface is serviced in the service load balancing method of system, as shown in Figure 2.
In step 201, the service request from client is received.
In step 202., in the service request service name and resource object title, and preserved in registration table
Corresponding relation, finds the corresponding main service of requested service and the corresponding each network interface of the main service.
In step 203, the corresponding each network interface flow of main service is judged, and therefrom selection free time network interface.
Specifically, a threshold value can be pre-set, when a network interface flow is less than this threshold value, the network interface is quilt
Regard as idle network interface.Multiple idle network interfaces are determined according to this threshold value, and therefrom one primary idle network interface of selection and one standby
Idle network interface.
In step 204, the corresponding access address of the network interface is returned into client.Wherein, the access address of return can
With including:Service name, primary network interface IP address+port numbers, IP address of standby network interface etc..Afterwards, client can connect from this
Enter the service that address acquisition is asked.
Second embodiment of the invention is related to a kind of service load balancing device of distributed system, as shown in figure 3, system
In each service be distributed in each server of different industrial networks, a service is distributed on multiple servers, by multiple services
Device provides same services, carries out Backup service, is serviced based on one of them service, remaining is backup services, and each service is corresponding
Multiple network interfaces, carry out network backup, and the device is included:
Memory module, for preserving corresponding relation and each service between the resource object that each service and service are used
Corresponding network interface;Active-standby switch module, for carrying out active-standby switch between main service and active service;Monitoring module, is used for
The load of server where the load of main service exceeds pre-determined threshold, or main service exceeds pre-determined threshold, or main service correspondence
Each network interface at least n network interface flow be less than at least m network interface flow in minimum normal value, or the corresponding each network interface of main service
During beyond maximum limit value, active-standby switch is carried out with active service to the main service, wherein, m, n are more than or equal to 1, are less than or equal to
The corresponding all network interface quantity of the service;Network interface selecting module, for when receiving the service request from client, according to please
Service name and resource object title in asking, find current corresponding main service, and main corresponding each network interface flow is serviced to this
Selected, therefrom select multiple idle network interfaces;Entrance returns to module, for the idle network interface pair for selecting network interface selecting module
The access address answered returns to client, indicates that client obtains asked service from access address.
As a further improvement, service load can include:The number of threads of service;And server load can include:
Cpu load, and/or memory usage.
As a further improvement, the device can also be included:Data obtaining module, for the negative of each main service of timing acquisition
The information on load of server where lotus information, the main service and the corresponding each network interface flow of the main service.Registering modules, are used for
Each service in system is registered, and the corresponding relation between the resource object that service and the service are used, service and net
Corresponding relation between mouthful, service and institute's corresponding relation between servers, main information on services is stored in storage mould in respectively servicing
In block;Network interface selecting module according to the corresponding relation preserved in memory module find it is currently requested service it is corresponding it is main service,
With the corresponding network interface of main service.
As a further improvement, Registering modules are additionally operable to after active-standby switch module carries out active-standby switch, update after switching
Main information on services, and the main information on services after updating is preserved in a storage module.
As a further improvement, can further include following submodule in network interface selecting module:Select a primary free time
The submodule of network interface;Select the submodule of a standby idle network interface;Wherein, the access address that entrance return module is returned includes:
Service name, primary network interface IP address+port numbers, the IP address of standby network interface.
In summary, in present embodiment, the server where the load of main service exceeds pre-determined threshold, or main service
Load exceeds pre-determined threshold, or the flow of the corresponding each network interface of main service is less than minimum normal value, or the corresponding each net of main service
When the flow of mouth exceeds maximum limit value, then active-standby switch is carried out with active service to the main service.Receiving from client
Service request when, service name and resource object title in request find current corresponding main service, to the main clothes
Corresponding each network interface flow of being engaged in is selected, and therefrom selects multiple idle network interfaces, and the corresponding access address of idle network interface is returned
To client, client obtains asked service from access address.Born relative to prior art according only to network interface flow
Carry balanced, present embodiment is synthetically considering the load condition of service, the load condition of server where the service and should
Service after corresponding each network interface flow, just determine the busy extent of the service, judge whether to be adapted to be continuing with the service, and root
It is judged that result carries out the switching of principal and subordinate's service, so as to being effectively prevented from because determining to service only by uninterrupted or taking
One-sidedness caused by the availability of device of being engaged in, prevents from interacting partial information less but calculating the erroneous judgement of complicated service, and can be more
Adequately judge busy, the appropriate of service, the probability of happening of effective control system overload.Also, prior art is general
Load balancing is carried out based on server, i.e., integrally carries out active-standby switch to server during load balancing, but reality should
In, the operation load respectively serviced on synchronization, server is differed, if carrying out overall cut based on server
Change, then all normal on the server or extra-heavy service can be switched on another server, easily caused another
Platform server it is busy, also, only enable one therein of active/standby server in synchronization, do not make full use of existing hard
Part resource.And in the present embodiment, all extra-heavy main services on server and active service are only subjected to active-standby switch,
So as to ensure more effectively to utilize all hardware resource, the flexible deployment to respectively being serviced on server is realized.
Although by referring to some of the preferred embodiment of the invention, being shown and described to the present invention,
It will be understood by those skilled in the art that can to it, various changes can be made in the form and details, without departing from this hair
Bright spirit and scope.