A kind of network flux fast distribution methodTechnical field
The present invention relates to a kind of method for allocating network flow, particularly about a kind of network flux fast distribution method based on URL (network universal resource address).
Background technology
Method for allocating network flow is also referred to as the load balancing strategy, is in the traffic management client's data traffic average mark to be flow to technical method on a plurality of background servers, and the method helps to make full use of the function of all background servers.Common load-balancing method has three kinds: 1, repeating query equilibrium, promptly the method for circulation will be each time distributed to concrete server in the cluster server successively from client's request in order.2, minimum linking number equilibrium, promptly transmit new client requests and carry out the server of minimum connection processing to those, in SLB (service load balance) software systems, each station server in the cluster server all has a record device, write down the number of processes that current this server is being handled, when new client requests, SLB always distributes to request the minimum server of current process number.3, disposal ability equilibrium, promptly divide into groups to Servers-all, to each group definition priority, client requests is distributed to the highest server group of priority, when the Setup of system, require the user to provide the configuring condition of each station server earlier, here mainly be CPU model, CPU quantity and the amount of memory that influences server handling ability, system is converted into disposal ability unit with it then, and SLB balancedly assigns the task to the highest server of performance according to the ability of each station server.
In Web used, data volume was huge, in order to take into account capacity and speed, usually high-speed servers (low capacity) and low-rate service device (big capacity) was used.High-speed servers is only preserved the most frequently used content recently, and performance is higher.The low-rate service device is preserved all the elements, but response speed is slow.Client's data traffic is general to be handled by high-speed servers earlier, but when following situation occurring, the low-rate service device will be used: 1, high-speed servers is unavailable.2, can not find corresponding data on high-speed servers, at this moment, high-speed servers can arrive first on the low-rate service device and fetch corresponding data, then client requests is made response.
Common load-balancing method divides timing solving as above the Web data traffic, have the following weak point: 1, above-mentioned three kinds of load balancing strategies all may be assigned to the visit of same content on the different high-speed servers, the result just causes a large amount of repeating datas of storage on all high-speed servers, greatly reduce the storage total capacity of high-speed servers, thereby cause service performance to descend.For example every high-speed servers has the capacity of 100G, and five high-speed servers capacity altogether should have 500G.But because the existence of redundant data, the different pieces of information that they comprised will be much smaller than 500G.The worst situation (promptly all data are all identical), five station servers are added up and are had only the 100G different pieces of information! In addition content all on the low-rate service device of reserve, need be read from the low-rate service device by high-speed servers temporarily.Have a strong impact on service rate so on the one hand, also do not had to make full use of simultaneously the capacity of many high-speed servers.2, after of short duration fault appears in a high-speed servers, above-mentioned load balancing strategy can forward the former flow of coming on it on other high-speed servers or the failover server to, but after this high-speed servers recovered, these flows sub-distribution were again returned.Lasting and the restorability of data traffic just can not get guaranteeing that the high-speed servers after recovering on the other hand will be difficult to normally participate in data processing, thereby reduce its utilization rate so on the one hand.3, the repeating query balance policy is suitable for the situation of average web access time relative equilibrium.But owing to visit the time difference that stops at Web each time might be very large, and therefore, along with the operating time lengthening, the process on each station server may produce great difference, and simple repeating query can not guarantee equilibrium truly.
Summary of the invention
At the problems referred to above, the purpose of this invention is to provide a kind of network flux fast distribution method based on URL, make network traffics to be evenly distributed on the multiple servers, and solve in the past data in server storage redundancy and the expendable disadvantage of obliterated data in the load balancing strategy.
For achieving the above object, the present invention takes following technical scheme: a kind of network flux fast distribution method, and it may further comprise the steps: 1) define several high-speed servers groups, and each high-speed servers group is inserted hash table with title ordering or designated order; 2) define one or more failover server groups; When 3) receiving client requests, therefrom extract URL; 4) use hashing algorithm,, calculate key value according to URL; 5) with hash table effectively a number key value delivery is found the corresponding server group according to the modulus that obtains then from hash table; 6) client requests is assigned in the server group that finds.
In execution in step 5) time, utilize following delivery formula: key%n=m, wherein n is an effectively number of hash table, m is the numbering of server.
In execution in step 4) time, regularly each high-speed servers group is carried out health examination, health examination is that load-balancing device will self be modeled as a virtual client, is interrupted to each high-speed servers group to send request, checks each high-speed servers group state.
Lost efficacy when health examination shows one of them high-speed servers group, then client requests was assigned to the failover server group.
Recovered normally when health examination shows described high-speed servers group, then client requests is re-assigned to described high-speed servers group.
Owing to adopted above technical scheme, the present invention has had following advantage: 1, the present invention utilizes the characteristic of intelligent hashing algorithm in load balancing, roughly the same many request or task amount on the probability are distributed to each station server, therefore guaranteed the uniform distribution of network traffics.2, the present invention compared to other string process method formula, has the advantages that rapidly and efficiently search by the use of intelligent hash function.3, the present invention can the maximum using server capacity, making each server group is different accessed content services, server in each server group will be stored diverse content, the content total amount that makes it possible to provide is each server pool-size sum, thus the utilization of fullest the data space of machine.4, the present invention is because the identical characteristic of key value (key) of utilizing intelligent hash function same URL to be obtained at every turn, therefore the data traffic that has guaranteed identical URL well can be assigned on the same station server in same group forever, has ensured the retentivity of service.5, the present invention matches with the failover server group, provides service by the failover server group when certain server group is unavailable; After this server group was recovered normally, original flow can return again, thereby has guaranteed the restorability of server group, made that the server recovery back of of short duration fault is used at once.
Description of drawings
Fig. 1 is a typical applied environment example schematic of the present invention
Embodiment
Basic ideas of the present invention are: 1, all high-speed servers and low-rate service device are divided into several server groups as required, each server group can comprise the server of one or more identical performances as required, comprises a failover server group in these server groups.2, the intelligent hash function in the use prior art calculates unique key value according to the URL of client access.3, adopt (in embodiment, will to elaborate) someway the key value and the server group of having numbered are mapped, send to purpose on the respective server thereby reach the request of data that to contain concrete URL.4, adopt network technology that the every station server in each server group is regularly done health examination, thereby grasp the information of server operating state in real time.5, when certain station server was considered to unavailable through health examination, the server in the failover server group will be called, thereby guaranteed that client requests at any time can be responded.The present invention for the content of URL, form etc. without any restriction and requirement.
Below in conjunction with drawings and Examples, the present invention is described in detail.
Basic ideas based on above-mentioned the present invention includes following steps:
1) as shown in Figure 1, define several high-speed servers groups and failover server group:
1. define several high-speed servers groups: present embodiment defines three high-speed servers groups altogether---and the 1st group, the 2nd group, the 3rd group, can comprise several high-speed servers in every group, and the server group inserted hash table, sort with Server Group Name, effective number of hash table is 3 in the present embodiment, and content is:
| 0 | 1 | 2 | 。。。 |
| The 1st group | The 2nd group | The 3rd group | 。。 |
2. define a failover server group: the failover server group also can comprise several servers.
2) receive client requests, select the server group fast according to the URL hash:
1. receive client HTTP request, therefrom extract the URL character string.A HTTP request all is made up of the plaintext character, and it is divided into two major parts: the front is a gauge outfit, and the back is data, and in gauge outfit, it is exactly URL (this is for as well known to those skilled in the art) that delegation's key-strings is arranged.For example the character string of a client HTTP request is:
GET/about/xrld.htm HTTP/1.0
Accept:image/gif.image/jpeg,*/*
Accept-Language:zh-cn
…………………………..
Then its URL character string is :/about/xrld.htm.
2. according to the URL that extracts, use intelligent hashing algorithm, calculate the key value.For example:
hash(URL)=key
Attention: for same URL, the key value that obtains is the same forever.Therefore it can distribute to each station server with roughly the same many request or task amount on the probability, thereby has guaranteed the uniform distribution of network traffics.
3. with hash table effectively a number key value delivery is found the corresponding server group according to the modulus that obtains then from hash table, the delivery formula is:
key%n=m
Wherein n is an effectively number of hash table, and m is the numbering of server.For example:
1, hash function hash ("/about/xrld.htm ")=101.
2, present embodiment has defined three server groups, and a hash table effectively number is 3, these three server groups be numbered 0,1,2.Modulo operation is: 101%3=2, so can being sent to, this client requests is numbered 2 server group, and the 2nd content is the 3rd group in the hash table herein, and then the 3rd group is corresponding with service device group.
The health examination of server group 4. of the present invention is that load-balancing device will self be modeled as a virtual client, is interrupted to the high-speed servers group to send request, checks high-speed servers group state, and selects the final server group of using.If the server group comes into force, then use this server group; If this server group lost efficacy, then use the failover server group.After this server group is recovered normally, original flow can return again, this is because the key value of obtaining according to intelligent hashing algorithm will be determined the server group by preferential the use, thereby has guaranteed the restorability of server group, makes that the server recovery back of of short duration fault is used at once.For example: 1, when the 1st group of server was effective, client requests was assigned to the 1st group of server.2, after the 1st group of server becomes inefficacy, the client requests of same URL can be assigned to the failover server group.3, after the 1st group of server comes into force once more, the client requests of same URL can be redistributed into the 1st group of server.
The foregoing description only is a preferred embodiment of the present invention, and in essence intention scope of the present invention, the algorithm that the present invention adopts can have many variations or replacement, and the variation of these algorithms or replacement should not got rid of outside protection scope of the present invention.