Load allocation method and equipment
Technical field
The present invention relates to virtual network service fields, and in particular to a kind of load allocation method and equipment.
Background technique
In existing virtual network service, different operating units is distributed into all loads.That is, will be to load
Service share on multiple operating units and executed, such as Web server, ftp server, enterprise's key application server
With other key task servers etc., to complete task jointly by multiple operating units.This extends server cluster
Bandwidth, the flexibility and availability that increase its handling capacity, strengthen network data processing ability, improving network.
It in the prior art, may be by certain client, category during different operation unit being distributed in multiple loads
Different servers is requested assignment in same session, thus may cause conversation.
Summary of the invention
In view of the above problems, the present invention is proposed in order to provide a kind of load distribution at least being partially solved the above problem
Method and apparatus.
According to one aspect of the present invention, a kind of load allocation method is provided, comprising:
Receive the session request from client;
According to the session request, the unique identifier of the client is obtained;And
The client is distributed to the particular server in all available servers based on the unique identifier.
Another aspect according to the present invention additionally provides a kind of load distributing apparatus, comprising:
First receiving module, for receiving the session request from client;
Module is obtained, for obtaining the unique identifier of the client according to the session request;And
Distribution module, for the client to be distributed to the spy in all available servers based on the unique identifier
Determine server.
The unique identifier of above-mentioned load allocation method and equipment utilization client of the invention establish client with it is specific
Mapping relations one by one between server, so as to protect during multiple client is distributed to different operation unit
Card by particular clients, belong to same session request assignment to same server, thus keep session.
The above description is only an overview of the technical scheme of the present invention, in order to better understand the technical means of the present invention,
And it can be implemented in accordance with the contents of the specification, and in order to allow above and other objects of the present invention, feature and advantage can
It is clearer and more comprehensible, the followings are specific embodiments of the present invention.
Detailed description of the invention
By reading the following detailed description of the preferred embodiment, various other advantages and benefits are common for this field
Technical staff will become clear.The drawings are only for the purpose of illustrating a preferred embodiment, and is not considered as to the present invention
Limitation.And throughout the drawings, the same reference numbers will be used to refer to the same parts.In the accompanying drawings:
Fig. 1 shows the schematic flow chart of load allocation method according to an embodiment of the invention;
Client is distributed to by particular server based on unique identifier Fig. 2 shows according to an embodiment of the invention
Process schematic flow chart;And
Fig. 3 shows the schematic block diagram of load distributing apparatus according to an embodiment of the invention.
Specific embodiment
Exemplary embodiments of the present disclosure are described in more detail below with reference to accompanying drawings.Although showing the disclosure in attached drawing
Exemplary embodiment, it being understood, however, that may be realized in various forms the disclosure without should be by embodiments set forth here
It is limited.On the contrary, these embodiments are provided to facilitate a more thoroughly understanding of the present invention, and can be by the scope of the present disclosure
It is fully disclosed to those skilled in the art.
In the prior art, when carrying out load distribution, the difference of the same session of certain load may be requested assignment to not
Same server, thus leads to conversation.In description herein, load can be client.For example, in certain client
On, user has input the username and password of login, is done shopping with logging in related web site.Login corresponding to the register
Request may be allocated to server A.Thus server A saves the session by the logging request.When user is following
When the related web site is done shopping, the corresponding request of shopping operation may be allocated to server B, and server B
There is no any information of the session.For server A, although saving the session, probably because predetermined at one
Any request is not received from client in the time limit of justice, leads to conversation.
In order to remain session when carrying out load distribution, according to an aspect of the present invention, a kind of load point is provided
Method of completing the square.Fig. 1 shows the schematic flow chart of load allocation method 100 according to an embodiment of the invention.Such as Fig. 1 institute
Show, load allocation method 100 includes step S110, step S130 and step S150.
In step s 110, the session request from client is received.
Session (session) is the sequence of the unbroken request and response between client and server.Client to
Server sends request.After server receives request, the response to request is sent to client.
The request for the first time that user end to server is sent is the request for needing to create session.This request to be asked to multiple for the first time
Ask the beginning counted in logic.It is requested for the first time according to this, server can obtain the special identifier symbol of client.That is,
Server starts to remember the request of the client He the client.For example, when user logs in or adds into shopping cart one
When commodity, a session is begun to.Server can identify client according to session, for example session level variable note can be used
The user name password that has inputted of record active user thus sends every time without user and requests all to re-enter, can be with
For recording some other information related with currently this time session.When client clearly terminates session or server one
Not from when client any request of reception in a predefined time limit, session just finishes.After conversation end, server is just forgotten
The client and the request of the client are remembered.
Specifically, user opens a browser, accesses some webpage (web) website, clicks in this web site more
A hyperlink accesses the multiple web resources of server, is then shut off browser, whole process can be referred to as a session.Once
Browser is closed, when reopening browser, cannot need to create a meeting again using last session
Words.In short, session is the primary call between client and server, such as to be realized in the way of browser.
As described above, a session may include multiple requests.In this step, it can receive belonging to from client
One request of special session.The received request of institute can be requests for the first time, may not be and requests for the first time.
In step s 130, according to session request, the unique identifier of client is obtained.
Each session request includes the information of the unique identifier about client.Server can be according to session as a result,
To determine client.According to the received session request of institute, the unique identifier of the available client of server.The specific identifier
Which client symbol identifies the session request from.
Optionally, unique identifier is address Internet protocol (IP) of client, such as 221.217.241.***.It is logical
It often, include the IP address of client in session request.The IP address of each client be it is relatively-stationary, can be used for identifying
Client.Be using IP address as the unique identifier of client it is very convenient and practical, can accurately identify visitor
Family end, to guarantee the smooth realization of scheme.
It is appreciated that unique identifier is also possible to the other identifier information of client, as long as the mark in addition to IP address
Information can uniquely identify client.
In some instances, client may access destination server by proxy server.Destination server is visitor
It is expected the server of session therewith in family end.In these examples, the session request of client can be transmitted to by proxy server
Destination server, thus destination server obtains the unique identifier of client via proxy server.
In step S150, client is distributed to the special services in all available servers based on unique identifier
Device.
The particular server is the server for the client service.The particular server can be the spy according to client
Determine determined by identifier.One client of each unique identifier unique identification, thus, it is possible to determine each client point
The specific server of dispensing.
In above-mentioned load allocation method 100 of the invention, using the unique identifier of client establish client with it is specific
Mapping relations one by one between server, so as to protect during multiple client is distributed to different operation unit
Card by particular clients, belong to same session request assignment to same server, thus keep session.
Optionally, unique identifier being based in the step S150 of above-mentioned load allocation method 100, client is distributed into institute
Have in the particular server in available server, unique identifier can be the IP address of client.It, can be in step S150
Client is distributed into particular server based on any information in IP address.For example, can according to IP address last
Position client is distributed into particular server.It can be that the client of even number distributes to server A by last of IP address,
It is that the client of odd number distributes to server B by last of IP address.
Optionally, in step S150, client is distributed to particular server by first three IP address-based section.IP address
First three section may include symbol " " between first three numeric string and these three numeric strings therein.Alternatively, before IP address
Three sections can also be including the symbol " " after first three numeric string.For IP address 221.217.241.***, first three section can
To be " 221.217.241 " or " 221.217.241. ".
Some clients, the individual client end that especially some operators's (such as China Unicom) are serviced, IP address
It may not be unalterable.Especially the 4th section of IP address is often variation.The 4th section of IP address may include it
In the last one numeric string.For IP address 221.217.241.***, the 4th section is * * *.Assuming that in a scene,
When client is distributed to particular server, it is contemplated that the 4th section of IP address.If the IP of client when distributing client
Address is changed, then will lead to the server that client is assigned to mistake, causes conversation.It is IP address-based
Client is distributed to particular server by first three section can guarantee each client distributing to particular server to a greater degree,
So that it is guaranteed that session is kept.
Optionally, client is distributed to particular server and is specifically included by first three IP address-based section in step S150
Step S151, step S152, step S153 and step S154.
In step S151, divisor is determined according to the number of all available servers.Firstly, determining whole available server
Total number.Divisor is determined according to the total number.For example, determining that the total number is divisor.Assuming that all available servers are in total
It is 10.Then it is determined that divisor is 10.Certainly, total number can also be more than or less than divisor.
In step S152, first three section of IP address is encoded, to obtain encoded radio.By the cataloged procedure, obtain
Obtain an encoded radio with IP address with mapping relations one by one.It, can be by it such as IP address 221.217.241.***
In first three section array at encoded radio 221217241.
In step S153, by encoded radio divided by divisor, to obtain remainder.That is modulus fortune is carried out to encoded radio
It calculates.For example, obtaining remainder is 1 by 221217241 divided by 10.
In step S154, particular server is determined based on remainder.It specifically, can in the example that total number is divisor
To be determined the 1st server in server as particular server according to remainder 1.It, can if being appreciated that remainder is 0
To determine that the 10th server is particular server in server.
The implementation of above-mentioned steps S150 is fairly simple, and each client can be mapped to one it is unique specific
Server, to guarantee that session is not interrupted.
Optionally, first three section of IP address encode and be specifically included by above-mentioned steps S152: according to first three of IP address
It is digitally generated encoded radio in section, to indicate the IP address.
As described above, in an example of the present invention, directly together by the digital jointing in first three section of IP address, shape
At a number using as encoded radio.For example, the encoded radio can be 221217241 for IP address 221.217.241.***.
In another of the invention example, first together by the digital jointing in first three section of IP address, then according to
Unalterable rules change the number in the number through splicing, to obtain encoded radio.Specifically includes the following steps: 1) by the 5th digit with
2nd digit reversing of position;2) the 3rd digit is added into particular value, such as 5.For IP address 221217241, exchange first therein
5th digit and the 2nd digit obtain number 221247211;Then the 3rd digit is added 5, thus to obtain encoded radio 221247711.
Optionally, first three section of IP address is carried out coding in above-mentioned steps S152 to specifically include: to first three of IP address
Duan Jinhang Hash operation, and determine that cryptographic Hash obtained is encoded radio.
The binary value of random length can be mapped as the binary value of shorter regular length by Hash operation, this is solid
The binary value of measured length is known as cryptographic Hash.For any one binary value, cryptographic Hash be one piece of data uniquely and extremely
Compact numerical value representation.So can be using the Hash operation result of first three section of IP address as encoded radio.Optionally,
Cryptographic Hash can be 12 to 16 binary values.
Hash operation can be regarded as a kind of cryptographic calculation.The Hash to first three section of IP address is executed in step S152
Operation can make load allocation method be not easy to be cracked by the bad personage such as hacker.That is, other people will be not easy to determine such as
Client is distributed to particular server by what, its attack to server system is avoided, to improve the safety of system.
Optionally, above-mentioned load allocation method 100 further comprises being according to processing capacity for each available server
It assigns respective weights.Wherein, the size of weight and the processing capacity of server are directly proportional.The processing capacity of available server can
With difference.Than if any server be configured with the processor compared with multicore, some is configured with the processor of less core, and some is matched
It is equipped with the processor compared with high primary frequency, some is configured with the processor of lower dominant frequency.Herein, the service that processing capacity can be given strong
Device assigns greater weight, and the weak server of processing capacity is given to assign smaller weight, with when loading distribution, by more client
The strong server of processing capacity is distributed to, less client is distributed into the weak server of processing capacity.
Determine that divisor can specifically include according to the number of all available servers in above-mentioned steps S151: according to each
The respective weights of available server and divisor is determined according to the number of all available servers.
In one example, the total number of available server is 10.Wherein the weight of the 10th server is 2, other
The weight of server is 1.Divisor can be determined as 11.In this example, divisor is greater than total number.As the IP of client
Client is respectively allocated to the 1st server to the 9th server when remainder is 1 to 9 to 11 modulus by the encoded radio of location.When
Client is distributed to the 10th server when remainder is 10 or 0 to 11 modulus by the encoded radio of the IP address of client.
In short, assigning different weights to the different server of processing capacity, the strong server of the processing capacity made is divided
With more clients, all available servers will be made to make the best use of everything, avoid computing resource waste.
Optionally, the step S150 of load allocation method 100 client distributed to based on unique identifier it is all
Before particular server in available server, method 100 further comprises: determining all available services based on server list
Device.Server in server cluster may break down, and causing can not be with client normal conversation.So in load point
With before, first determine available server, can guarantee server cluster preferably with client session.Determination operation can
To be based on server list, the identifier of all available servers can be listed in the server list.Server can be arranged
Table is stored on server administrators, to when needed, can take and determine all available services based on server list
Device.
Optionally, before determining all available servers based on server list, method 100 further comprises step
S101, step S102 and step S103.In step s101, message is sent to Servers-all.It can be by server administrators
Monitoring request message is sent to all servers, can currently be worked normally with monitoring server.In step s 102, it receives
The feedback message of the Servers-all.If any server failure, then it may not be able to correctly issue feedback message.By
This, will not receive the correct feedback message from failed server.In step s 103, according to the received feedback message of institute
Determine server list.Specifically, it can be determined that whether had received the feedback message from each server.Then, exist
In all feedback messages, determine correct feedback message therein from server.Finally, according to correctly feedback is sent
The identifier of the server of message generates above-mentioned server list.
Pass through transmission monitoring request message and receive feedback message to determine the working condition of server, it is accurate to compare
Ground obtains the work state information of server, and then guarantees client distributing to the server that can be worked normally, and ensure that
The session of client and server is gone on smoothly.
Another aspect according to the present invention, provides a kind of load distributing apparatus.Fig. 3 shows an implementation according to the present invention
The schematic block diagram of the load distributing apparatus 300 of example.As shown in figure 3, load distributing apparatus 300 include the first receiving module 310,
Obtain module 330 and distribution module 350.
First receiving module 310 is for receiving the session request from client.Module 330 is obtained for asking according to session
It asks, obtains the unique identifier of client.Distribution module 350 is used to distribute to client based on unique identifier all available
Particular server in server.
Optionally, above-mentioned unique identifier is the IP address of client.
Optionally, above-mentioned distribution module 350 specifically includes distribution sub module, is used for first three IP address-based section for client
Distribute to particular server in end.
Optionally, above-mentioned distribution sub module specifically includes: divisor determination unit, coding unit, divider and server
Determination unit.Divisor determination unit is used to determine divisor according to the number of all available servers.Coding unit is for by IP
First three section of location is encoded, to obtain encoded radio.Divider is used for encoded radio divided by divisor, to obtain remainder.Service
Device determination unit is used to determine particular server based on remainder.
Optionally, above-mentioned coding unit specifically includes the first subelement, raw for number in first three section according to IP address
At encoded radio.
Optionally, above-mentioned coding unit specifically includes the second subelement, carries out Hash fortune for first three section to IP address
It calculates, and determines that cryptographic Hash obtained is encoded radio.
Optionally, above-mentioned load distributing apparatus 300 further comprises assigning weight unit, for for each available service
Device assigns respective weights according to processing capacity for it.And divisor determination unit specifically includes divisor and determines subelement, is used for root
According to the respective weights of each available server and divisor is determined according to the number of all available servers.
Optionally, above-mentioned load distributing apparatus 300 further comprises available server determining module, for being based on server
List determines all available servers.
Optionally, above-mentioned load distributing apparatus 300 further comprises that sending module, the second receiving module and list generate mould
Block.Sending module is used to send message to Servers-all.Second receiving module is used to receive the feedback of the Servers-all
Message.List Generating Module is used to generate server list according to the feedback message.
Those of ordinary skill in the art are by reading the detailed description above for load allocation method 100, it is to be understood that
Structure, realization and the advantage of above-mentioned load distributing apparatus 300, therefore which is not described herein again.
Algorithm and display are not inherently related to any particular computer, virtual system, or other device provided herein.
Various general-purpose systems can also be used together with teachings based herein.As described above, it constructs required by this kind of system
Structure be obvious.In addition, the present invention is also not directed to any particular programming language.It should be understood that can use various
Programming language realizes summary of the invention described herein, and the description done above to language-specific is to disclose this hair
Bright preferred forms.
In the instructions provided here, numerous specific details are set forth.It is to be appreciated, however, that implementation of the invention
Example can be practiced without these specific details.In some instances, well known method, structure is not been shown in detail
And technology, so as not to obscure the understanding of this specification.
Similarly, it should be understood that in order to simplify the disclosure and help to understand one or more of the various inventive aspects,
Above in the description of exemplary embodiment of the present invention, each feature of the invention is grouped together into single implementation sometimes
In example, figure or descriptions thereof.However, the disclosed method should not be interpreted as reflecting the following intention: i.e. required to protect
Shield the present invention claims features more more than feature expressly recited in each claim.More precisely, as following
Claims reflect as, inventive aspect is all features less than single embodiment disclosed above.Therefore,
Thus the claims for following specific embodiment are expressly incorporated in the specific embodiment, wherein each claim itself
All as a separate embodiment of the present invention.
Those skilled in the art will understand that can be carried out adaptively to the module in the equipment in embodiment
Change and they are arranged in one or more devices different from this embodiment.It can be the module or list in embodiment
Member or component are combined into a module or unit or component, and furthermore they can be divided into multiple submodule or subelement or
Sub-component.Other than such feature and/or at least some of process or unit exclude each other, it can use any
Combination is to all features disclosed in this specification (including adjoint claim, abstract and attached drawing) and so disclosed
All process or units of what method or apparatus are combined.Unless expressly stated otherwise, this specification is (including adjoint power
Benefit require, abstract and attached drawing) disclosed in each feature can carry out generation with an alternative feature that provides the same, equivalent, or similar purpose
It replaces.
In addition, it will be appreciated by those of skill in the art that although some embodiments described herein include other embodiments
In included certain features rather than other feature, but the combination of the feature of different embodiments mean it is of the invention
Within the scope of and form different embodiments.For example, in the following claims, embodiment claimed is appointed
Meaning one of can in any combination mode come using.
Various component embodiments of the invention can be implemented in hardware, or to run on one or more processors
Software module realize, or be implemented in a combination thereof.It will be understood by those of skill in the art that can be used in practice
Microprocessor or digital signal processor (DSP) come realize some in load distributing apparatus according to an embodiment of the present invention or
The some or all functions of person's whole component.The present invention is also implemented as one for executing method as described herein
Point or whole device or device programs (for example, computer program and computer program product).Such this hair of realization
Bright program can store on a computer-readable medium, or may be in the form of one or more signals.It is such
Signal can be downloaded from an internet website to obtain, and is perhaps provided on the carrier signal or is provided in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and ability
Field technique personnel can be designed alternative embodiment without departing from the scope of the appended claims.In the claims,
Any reference symbol between parentheses should not be configured to limitations on claims.Word "comprising" does not exclude the presence of not
Element or step listed in the claims.Word "a" or "an" located in front of the element does not exclude the presence of multiple such
Element.The present invention can be by means of including the hardware of several different elements and being come by means of properly programmed computer real
It is existing.In the unit claims listing several devices, several in these devices can be through the same hardware branch
To embody.The use of word first, second, and third does not indicate any sequence.These words can be explained and be run after fame
Claim.
The embodiment of the invention discloses A1, a kind of load allocation method, comprising:
Receive the session request from client;
According to the session request, the unique identifier of the client is obtained;And
The client is distributed to the particular server in all available servers based on the unique identifier.
A2, load allocation method as described in a1, the unique identifier are the Internet protocol addresses of the client.
A3, as described in A2 load allocation method, it is described that the client is distributed to by institute based on the unique identifier
There is the particular server in available server to specifically include:
The client is distributed to the particular server by first three section based on the Internet protocol address.
A4, the load allocation method as described in A3, it is described based on first three section of the Internet protocol address by the visitor
It distributes to the particular server and specifically includes in family end:
Divisor is determined according to the number of all available servers;
First three section of the Internet protocol address is encoded, to obtain encoded radio;
By the encoded radio divided by the divisor, to obtain remainder;And
The particular server is determined based on the remainder.
A5, the load allocation method as described in A4, it is described that first three section of the Internet protocol address is subjected to coding tool
Body includes:
The encoded radio is digitally generated according in first three section of the Internet protocol address.
A6, the load allocation method as described in A4, it is described that first three section of the Internet protocol address is subjected to coding tool
Body includes:
Hash operation is carried out to first three section of the Internet protocol address, and determines that cryptographic Hash obtained is the volume
Code value.
A7, such as A4 to the described in any item load allocation methods of A6, the method further includes:
For each available server, respective weights are assigned for it according to processing capacity, wherein the respective weights and institute
It is directly proportional to state processing capacity;
The number according to all available servers determines that divisor specifically includes:
Described in being determined according to the respective weights of each available server and according to the number of all available servers
Divisor.
A8, such as A1 are based on the unique identifier for the visitor described to the described in any item load allocation methods of A7
Before the particular server in all available servers is distributed at family end, the method further includes:
All available servers are determined based on server list.
A9, the load allocation method as described in A8, it is described all available servers are determined based on server list before,
The method further includes:
Message is sent to Servers-all;
Receive the feedback message of the Servers-all;And
The server list is determined according to the feedback message.
The embodiment of the invention also discloses B10, a kind of load distributing apparatus, comprising:
First receiving module, for receiving the session request from client;
Module is obtained, for obtaining the unique identifier of the client according to the session request;And
Distribution module, for the client to be distributed to the spy in all available servers based on the unique identifier
Determine server.
B11, the load distributing apparatus as described in B10, the unique identifier are the Internet protocols of the client
Location.
B12, load distributing apparatus as described in b11, the distribution module specifically include:
The client is distributed to the spy for first three section based on the Internet protocol address by distribution sub module
Determine server.
B13, as described in B12 load distributing apparatus, the distribution sub module specifically include:
Divisor determination unit, for determining divisor according to the number of all available servers;
Coding unit, for encoding first three section of the Internet protocol address, to obtain encoded radio;
Divider is used for the encoded radio divided by the divisor, to obtain remainder;And
Server determination unit, for determining the particular server based on the remainder.
B14, the load distributing apparatus as described in B13, the coding unit specifically include:
First subelement, for being digitally generated the encoded radio in first three section according to the Internet protocol address.
B15, the load distributing apparatus as described in B13, the coding unit specifically include:
Second subelement carries out Hash operation for first three section to the Internet protocol address, and determination is obtained
Cryptographic Hash be the encoded radio.
To the described in any item load distributing apparatus of B15, the equipment further comprises by B16, such as B13:
Weight unit is assigned, for assigning respective weights according to processing capacity for it, wherein institute for each available server
It is directly proportional to the processing capacity to state respective weights;
The divisor determination unit specifically includes:
Divisor determines subelement, for the respective weights according to each available server and according to all available clothes
The number of business device determines the divisor.
To the described in any item load distributing apparatus of B16, the equipment further comprises by B17, such as B10:
Available server determining module, for determining all available servers based on server list.
B18, the load distributing apparatus as described in B17, the equipment further comprises:
Sending module, for sending message to Servers-all;
Second receiving module, for receiving the feedback message of the Servers-all;And
List Generating Module, for generating server list according to the feedback message.