Background technology
Point-to-point (P2P, Peer to Peer) technology is a focus of present International Computer Network technical field research, and more and more is subjected to people's approval, and it provides a kind of method of new shared resource.In the P2P network environment, computer connected to one another all is in the status of equity, every main frame be resource requestor be again resource provider, can make response to the request of other computer, resource and service are provided voluntarily, and therefore every computer all is called as the Peer peer node.
Relation according to topological structure can be divided into the P2P network topology structure 4 kinds of forms: centralization topology, full distributed destructuring topology, all distributed structure topological sum half distribution topology.Wherein, all distributed structure topology is also referred to as distributed hash table (DHT, Distributed Hash Table) network.
System compares with non-structural P 2 P, based on the structured P 2 P system structure of DHT can the self adaptation node dynamic adding/withdraw from, good extensibility, robustness and self organization ability are arranged.
Structured P 2 P system adopts the certainty topological structure, adopts DHT can find resource accurately, efficiently.The DHT basic thought is: at first for each node in the network distributes virtual address VID, also be node ID, represent the shared content that it provides with a keyword KEY simultaneously.Get a hash function H, this function can convert KEY to a hashed value H (KEY).The definition that node is adjacent in the network is that hashed value is adjacent.When node releases news just (KEY, VID) two tuples are published to and have node identical with H (KEY) or close virtual address and get on, wherein VID has pointed out the memory location of document.Resource location time, just can be fast according to H (KEY) to index deposit obtain on the node two tuples (KEY, VID), thereby the actual stored position of acquisition document.
Because stacking network has adopted the certainty topological structure, DHT can accurately find resource.But because node identifier (ID, identity) between distance be irregular, so the load of some node may be system's average load O (logN) doubly.The hypothesis node capacity is identical among the DHT, but in fact the node capacity in the P2P network is widely different, and node capacity comprises CPU disposal ability, memory space, bandwidth etc.Caused the unbalanced problem of load like this, i.e. the ability of load of node and node does not conform to.In addition, have content very popular or that the frequency of occurrences is higher in the network, in these perhaps its index can deliver on the node of correspondence, cause some node overload; Because some supports the design of similar inquiry, cause the offered load inequality in addition.Therefore need carry out load balancing to system.
To guarantee that in the DHT network " Chord_AScalable Peer-to-peer Lookup Protocol for Internet Applications " document discloses a kind of node ID generation method into each node distributes a unique identifier:
The essence of structured P 2 P network is framework one deck Overlay network on physical network, in network topology, is the logic neighbouring relations between node; And the mode by self-organizing, set up routing table according to corresponding neighbouring relations.ID is obtained, is shown below by node Internet protocol (IP, Internet Protocol) address Hash usually:
ID=hash(IP)
These ID generating modes produce a random number exactly, and its benefit is that randomness is more intense, and can not conflict.What use among the Chord is that the SHA-1 hash function carries out Hash, and what use among the pastry is the MD5 hash function.
But these ID generation method final purpose all just generate a unduplicated random number, and only Hash are carried out in the IP address and handle, and may cause the ID of the contiguous node of IP not contiguous, so can not well be applicable to load balancing.
Number of patent application is 200510126321.7, and name is called and discloses a kind of load-balancing method in the patent documentation of " distributed load equalizing method of structured P 2 P system ":
Node is collected partial load information information cycle according to adjacent node, the overload node by heuristic to non-overload node transferring load.This method has been utilized the proximity relations of node on physical network, makes load shift between the less node of link delay as far as possible, saves the network bandwidth.
But said method is to utilize the proximity relations of node on physical network on existing DHT basis, wherein mention by " immediate neighbor " and collect partial load information, but in structurized P2P network, neighbours define at the overlay layer, there is not " immediate neighbor " this notion in major part, because node route list is only stored neighbours or other nodal information of overlay layer, then there is not record as for node contiguous on the geographical position, so the unactual using value of this method.
Embodiment
The invention provides node identifier generation method and load-balancing method and device, be used to improve the load balancing effect.
Node identifier is made of two parts among the present invention, a preceding part is the contiguous physically total identifier of node, a back part is the unique identifier of node, so just can inquire node contiguous on the physical network and carry out load transfer when load balancing.
See also Fig. 1, node identifier generation method first embodiment of the present invention comprises:
101, obtain the local ip address of node;
102, obtain the first identifier parameter and the second identifier parameter according to described local ip address;
103, with the node identifier of the synthetic described node of the described first identifier parameter and the second identifier parameter group.
Wherein, if the first identifier parameter is that 10, the second identifier parameters are 20, then the node identifier of combination back formation can be 1020, be understandable that, can adopt other compound mode equally, the node identifier that only need embody final formation is divided into two parts and gets final product.
Wherein, step 102 is obtained the corresponding first identifier parameter and the second identifier parameter according to the different situations of local ip address, describes in detail among concrete acquisition process second embodiment below.
Wherein, step 102 can also replace with:
The public network IP address of node is carried out Hash to be handled and obtains the first identifier parameter; A unduplicated random number is set as the second identifier parameter.
Above-mentioned replacement is to be the situation of privately owned address at the IP address, and concrete flow process describes in detail equally in a second embodiment.
In addition, step 102 is specially: according to the corresponding meshed network information of the type of described local ip address inquiry, and described meshed network information handled obtain the first identifier parameter and the second identifier parameter.
Wherein, the type of meshed network information and local ip address is relevant, is specially:
When local ip address was privately owned address, meshed network information comprised the public network IP address and the private IP address of this node;
When local ip address was C class address, meshed network information comprised the network number and the host number of this node;
When local ip address was category-A or category-B address, meshed network information comprised the subnet number and the host number of this node.
See also Fig. 2, node identifier generation method second embodiment of the present invention comprises:
201, obtain local ip address;
202, judge whether described IP address has privately owned address, if then execution in step 203, if not, then execution in step 207;
Wherein, if local IP at 10.0.0.0~10.255.255.255,172.16.0.0~172.31.255.255 among 192.168.0.0~192.168.255.255, then can be judged as privately owned address.
203, inquiry public network IP;
Wherein, the gateway under described IP address is inquired about its public network IP address.
204, select random number;
205, public network IP address is carried out Hash and connects random number;
Wherein, public network IP address is carried out Hash handle,, random number as the second identifier parameter, is connected Hash result and random number as the first identifier parameter.
206, judge whether random number repeats, if repeat, then execution in step 204, if do not repeat, then execution in step 211;
Wherein, have with other node and conflict if add in the structured network its ID at node, then this random number repetition is selected a random number, more again till node ID is unique.
207, judge whether described IP address is C class address, if then execution in step 209, if not, then execution in step 208;
208, subnet number is carried out Hash;
Wherein, 1677214 main frames are arranged at most in the network of category-A address, the category-B address has 65534 main frames at most, and the network size of category-A address and category-B address correspondence is bigger, so category-A address and category-B address are divided into many subnets usually again.Main frame in the common local area network (LAN) is in a subnet, that is: its network prefix is identical.Subnet number is that the AND operation acquisition is carried out in IP address and mask.So its subnet number is carried out Hash as the first identifier parameter.
209, network number is carried out Hash;
Wherein, because the class c network scope is less, have only 254 computers at most, in general be separated by can be too not far away for physical location, so can directly carry out Hash as the first identifier parameter to its network number.
210, host number is carried out Hash;
Wherein, host number is carried out Hash as the second identifier parameter,
211, generate node identifier.
Wherein, connect the first identifier parameter and the second identifier parameter and form node identifier.
In the above-described embodiments, step 204 selects random number to be obtained by the Hash of private ip, so just need not judge whether repetition, because the privately owned address in the subnet is unduplicated.
In addition, the space of the node identifier that generates can change to some extent, and for example the ID space is 160 bits in chord, and the ID space that obtains by this new ID generation method is 320 bits so, ID among the same pastry is 128 bits, with the ID of this class methods generation 256 bits of ascending the throne.Can certainly do a little restrictions to the ID space,, make it be no more than 80 bits or the like such as the latter part of length of ID is intercepted.
The main purpose of above-mentioned node identifier generation method is to improve effect of load balance, below the load-balancing method that the present invention is based on above-mentioned node identifier generation method is described in detail, see also Fig. 3, load-balancing method embodiment of the present invention comprises:
301, generate node identifier;
Wherein, obtain the first identifier parameter and the second identifier parameter according to the node Internet protocol address and be connected the described first identifier parameter and the second identifier parameter forms described node identifier.
302, select neighbor node;
Wherein, when certain node becomes the overload node, trigger load transfer, at first need to select neighbor node according to node identifier, characteristic by structural P 2 P, can be by existing list item in the routing table, select the contiguous node of logic, such as the direct precursor that logical layer is just arranged in circuluses such as chord and follow-up, but in pastry and tapstry, there is not direct precursor and follow-up, so select leaf node in the routing table as neighbor node because leaf node be with the contiguous a certain scope of overload node ID in node.
Wherein, need determine the scope of selection according to ID space size and network density parameter, in general, under different practical situations, ID space size is all inequality with the network density parameter.Suppose to have 5 nodes, ID is respectively 1010,1030,1040,1050 and 1090, the preceding part of ID all is 10, illustrate that they belong to same subnet, a back part is a unique identifier, if ID is 1030 node overload, can be 1010 at ID then, select one or more neighbor nodes to carry out load transfer in 1040 and 1050 the node, if ID is the overload of 1050 node, then can in being 1030,1040 and 1090 node, ID select one or more neighbor nodes to carry out load transfer.
303, whether judge neighbor node and overload node at the same area, if then execution in step 306, if not, then execution in step 304;
Wherein, whether in the neighbor node of selecting, judging earlier has a plurality of nodes to add P2P networks (or whether the close node of ID is at same subnet) in the same subnet, and whether the preceding part by its identifier of comparison identical can learning.
304, send detection packet;
Wherein, if neighbor node and overload node then send the round-trip delay detection packet to each node not at the same area.
305, select the little node of time delay;
Wherein, select the little node of time delay according to the feedback information of each node that receives.
306, transferring load and record.
Wherein, if neighbor node with the overload node at the same area, the load transfer of the node that then will overload is to neighbor node;
If neighbor node and overload node be not at the same area, the load transfer of the node that then will overload is to the little node of the time delay of selecting.
Below load balancing device of the present invention is described in detail, see also Fig. 4, load balancing device embodiment of the present invention comprises:
Identifier generation unit 401 and load transfer unit 402;
Described identifier generation unit 401 is used for obtaining the first identifier parameter and the second identifier parameter and being connected the described first identifier parameter and the second identifier parameter forms described node identifier according to the Internet protocol address of node;
Described load transfer unit 402 is used for selecting neighbor node to carry out load transfer according to described node identifier.
Wherein, described load transfer unit 402 comprises:
Selected cell 4021, judging unit 4022 and buanch unit 4023;
Described selected cell 4021 is used for selecting preset routing table and the contiguous node of overload node identifier, and the information of described node is sent to judging unit;
Described judging unit 4022 be used for according to the information of the node that receives judge described node whether with the overload node at the same area, and judged result is sent to performance element;
Described buanch unit 4023 is used for carrying out load transfer according to the judged result that receives.
Wherein, described buanch unit 4023 comprises:
Probe unit 40231 and performance element 40232;
When the node of selecting with the overload node during at the same area, will the overload load transfer node of described selection extremely of node of performance element 40232;
When the node of selecting with the overload node during not at the same area, probe unit 40231 sends the round-trip delay detection packet to each node, selects the little node of time delay and notifies performance element 40232 according to the response time of each node; Described performance element 40232 will overload the load transfer of node to the little node of described time delay.
Said method and device are applicable to A, B, all kinds of subnets of C and pass through the NAT network.
More than node identifier generation method that the embodiment of the invention provided and load-balancing method and device are described in detail, used specific case herein principle of the present invention and execution mode are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and device; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, the part that all can change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.