CN110213316A - Method for routing and device - Google Patents

Method for routing and device Download PDF

Info

Publication number
CN110213316A
CN110213316A CN201810557033.4A CN201810557033A CN110213316A CN 110213316 A CN110213316 A CN 110213316A CN 201810557033 A CN201810557033 A CN 201810557033A CN 110213316 A CN110213316 A CN 110213316A
Authority
CN
China
Prior art keywords
address
key value
server
value
key
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201810557033.4A
Other languages
Chinese (zh)
Other versions
CN110213316B (en
Inventor
许沛豪
廖理
刘远宏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201810557033.4A priority Critical patent/CN110213316B/en
Publication of CN110213316A publication Critical patent/CN110213316A/en
Application granted granted Critical
Publication of CN110213316B publication Critical patent/CN110213316B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/745Address table lookup; Address filtering
    • H04L45/7453Address table lookup; Address filtering using hashing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • H04L67/1023Server selection for load balancing based on a hash applied to IP addresses or costs

Abstract

The invention discloses a kind of method for routing and devices, belong to field of communication technology.Method includes:, according to the user identifier and default equalization algorithm carried in service request, to obtain the corresponding first key Key value of user identifier when receiving the service request of terminal;According to the first Key value, from the IP address of multiple servers of server cluster, the corresponding IP address of the first Key value is obtained;By the corresponding IP address of the first Key value, IP address is sent to terminal as a purpose.By the present invention in that being allocated with default equalization algorithm to the user identifier carried in service request, since obtained Key value is random, and the probability for obtaining each Key value is identical, and each Key value corresponds to the IP address of a server, the probability for being mapped the IP address of each server is average, enable the request amount of each server balanced, to realize load balancing, improves whole treatment effeciency and reliability of service.

Description

Method for routing and device
Technical field
The present invention relates to field of communication technology more particularly to a kind of method for routing and device.
Background technique
Universal with terminal with the development of internet, more and more users' using terminal accesses internet.User exists The service request initiated in terminal can be assigned to corresponding underlying services device by top service device and be handled.
Currently, top service device is in the service request for receiving terminal, the available service request of top service device The user identifier (Identification, ID) of middle carrying, is then calculated the user identifier by consistency hash algorithm Corresponding Key (key) value, and then according to the mapping relations between the Key value and Key value and the IP address of underlying services device, it obtains IP (Internet Protocol, network protocol) address of the corresponding underlying services device of the Key value is taken, and returning to terminal should The IP address of underlying services device.Terminal after obtaining the IP address, can by the IP address, IP address is routed as a purpose, So that the service that the accessible underlying services device of terminal provides.
In the implementation of the present invention, inventor find the relevant technologies the prior art has at least the following problems:
Above-mentioned technology using consistency hash algorithm to user identifier carry out Hash operation, obtained Key value be it is fixed, Instantly when stratum server is less, it is possible that the case where Key value of most of user identifier is mapped to the same IP address, leads Cause the amount of access of some underlying services devices more, load too high, and the amount of access of other underlying services devices is less, loads Low, to the problem of load imbalance occur, so that whole treatment effeciency is low, reliability of service is poor.
Summary of the invention
The embodiment of the invention provides a kind of method for routing and devices, can solve the relevant technologies load imbalance, so that Whole treatment effeciency is low, the problem of reliability of service difference.The technical solution is as follows:
On the one hand, a kind of method for routing is provided, which comprises
When receiving the service request of terminal, accounted according to the user identifier carried in the service request with default Method obtains the corresponding first key Key value of the user identifier, and the default equalization algorithm for generating at random according to user identifier Any Key value in the first Key value set and probability for generating any Key value according to each user identifier is identical, described first Each Key value corresponds to the network protocol IP address of a server in server cluster in Key value set;
According to the first Key value, from the IP address of multiple servers of the server cluster, described first is obtained The corresponding IP address of Key value;
By the corresponding IP address of the first Key value, IP address is sent to the terminal as a purpose, the destination IP Location is routed for the terminal.
On the one hand, a kind of route device is provided, described device includes:
Module is obtained, for being marked according to the user carried in the service request when receiving the service request of terminal Know and default equalization algorithm, obtain the corresponding first key Key value of the user identifier, the default equalization algorithm be used for according to Probability family mark the random any Key value generated in the first Key value set and generate any Key value according to each user identifier Identical, each Key value corresponds to the network protocol IP of a server in server cluster in the first Key value set Location;
The acquisition module is also used to according to the first Key value, from the IP of multiple servers of the server cluster In address, the corresponding IP address of the first Key value is obtained;
Sending module, for by the corresponding IP address of the first Key value, IP address to be sent to the terminal as a purpose, The destination IP address is routed for the terminal.
On the one hand, a kind of computer equipment is provided, the computer equipment includes processor and memory, the storage At least one instruction, at least a Duan Chengxu, code set or instruction set, at least one instruction, at least one section are stored in device Program, code set or instruction set are loaded as the processor and are executed to realize operation performed by above-mentioned method for routing.
On the one hand, provide a kind of computer readable storage medium, be stored in the computer readable storage medium to Few an instruction, at least a Duan Chengxu, code set or instruction set, at least one instruction, an at least Duan Chengxu, code set or Instruction set is loaded as processor and is executed to realize the operation as performed by above-mentioned method for routing.
Technical solution provided in an embodiment of the present invention has the benefit that
By being carried out to the user identifier carried in service request using default equalization algorithm when receiving service request Distribution, since obtained Key value is random, and the probability for obtaining each Key value is identical, and each Key value corresponds to one The IP address of server, so that the probability that the IP address of each server is mapped be it is average, so as to avoid industry The problem of business request is mapped to the IP address of the same server by concentration enables the request amount of each server balanced, To realize load balancing, whole treatment effeciency and reliability of service are improved.
Detailed description of the invention
To describe the technical solutions in the embodiments of the present invention more clearly, make required in being described below to embodiment Attached drawing is briefly described, it should be apparent that, drawings in the following description are only some embodiments of the invention, for For those of ordinary skill in the art, without creative efforts, it can also be obtained according to these attached drawings other Attached drawing.
Fig. 1 is a kind of implementation environment schematic diagram of method for routing provided in an embodiment of the present invention;
Fig. 2 is a kind of flow chart of method for routing provided in an embodiment of the present invention;
Fig. 3 is a kind of flow chart of method for routing provided in an embodiment of the present invention;
Fig. 4 is a kind of flow chart of method for routing provided in an embodiment of the present invention;
Fig. 5 is a kind of structural schematic diagram of route device provided in an embodiment of the present invention;
Fig. 6 is a kind of structural schematic diagram of route device provided in an embodiment of the present invention;
Fig. 7 is a kind of structural block diagram of computer equipment 700 provided in an embodiment of the present invention.
Specific embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with attached drawing to embodiment party of the present invention Formula is described in further detail.
Fig. 1 is a kind of implementation environment schematic diagram of method for routing provided in an embodiment of the present invention, referring to Fig. 1, the implementation ring It may include: at least one terminal 101, at least one computer equipment 102 and at least one server 103 in border.
Wherein, terminal 101 can be mobile phone, tablet computer, PC (Personal) etc., and user can grasp at the terminal Make, triggering terminal 101 is used as requesting party, service request is sent to computer equipment 102, by computer equipment 102 by the business Request is assigned to corresponding server and is handled.
Computer equipment 102 can be top service device or other are used for using default equalization algorithm service request equilibrium The equipment for being assigned to each server 103, computer equipment can be used as after called side goes the IP address for obtaining server 103 and return Back to terminal 101;
Server 103 can be underlying services device, and for providing service for terminal 101, server 103 can be used as and be adjusted With side, the service request of processing terminal 101.In addition, the server 103 can be configured at least one database, such as user Database etc., the customer data base are used to store user name, password and the customer relationship for the user that the server 103 is serviced The personal data such as chain.
Fig. 2 is a kind of flow chart of method for routing provided in an embodiment of the present invention.Referring to fig. 2, this method comprises:
201, computer equipment receives the service request of terminal, carries user identifier in the service request.
In the embodiment of the present invention, user can operate at the terminal, such as show the button on webpage (as propped up terminal Pay button) or link (such as video link) progress clicking operation, corresponding service request is generated with triggering terminal, as payment is asked Ask, video playing request etc., user identifier can be carried in the service request, the format of the user identifier can be character string lattice Formula.In turn, terminal can send the service request to computer equipment, so that computer equipment receives the service request.
202, computer equipment obtains the corresponding target value of the user identifier, which is less than the first present count Purpose natural number, first preset number are used to indicate the number of server cluster, include second pre- in each server cluster If number destination server.
It, can be in order to provide reliable service, in entire service system in view of the quantity of service request may be very much Multiple server clusters are deployed with, each server cluster may include multiple servers, and computer equipment can send out terminal The service request equilibrium assignment sent is handled to each server.
In the embodiment of the present invention, computer equipment carries in the available service request when receiving service request String format user identifier, and obtain the corresponding target value of the user identifier.In a kind of possible implementation, meter Calculating machine equipment and obtaining the corresponding target value of the user identifier may include: to turn the user identifier according to transfer algorithm is preset It is changed to corresponding integer value, which is used to the user identifier of string format being converted to integer value;It is whole to this Offset and first preset number carry out modulo operation, obtain the target value.
Wherein, default transfer algorithm can be the calculation of CRC (Cyclic Redundancy Check, cyclic redundancy check) 32 The user identifier of string format can be converted to uint64 integer, then be pressed by method, computer equipment by CRC32 algorithm Modulus is carried out according to the number (the first preset number) of the server cluster of deployment, obtains target value, which is less than The natural number of first preset number, for example, when the first preset number be 4 when, the value range of the target value be [0,4), i.e., The value of the target value can be 0,1,2 or 3.By carrying out CRC32 operation according to user identifier, the user identifier pair is obtained The target value answered, the first Key value that computer equipment is generated at random by step 203.
203, computer equipment presets equalization algorithm and the target value according to this, obtains user identifier corresponding first Key value, the default equalization algorithm be used to be generated at random according to user identifier any first Key value in the first Key value set and The probability for generating any first Key value according to each user identifier is identical, each first Key value pair in the first Key value set Should in server cluster a server IP address.
Wherein, the number of the first Key value can be equal to the number of server in the first Key value set, for example, server A total of 28, then in the first Key value set the range of the first Key value can be [0,28), i.e., the first Key value set can Be 0,1,2 ..., 27.
In the embodiment of the present invention, the corresponding relationship in the first Key value and server cluster between the IP address of server can It is configured with being preset in computer equipment by related technical personnel.Computer equipment can generate at random according to user identifier One corresponding first Key value, since the probability for generating the first Key value of each of the first Key value set at random is identical, and it is every A first Key value corresponds to a server in the server cluster being previously mentioned in step 202, to realize user identifier Purpose on Mean mapping to each server.
In a kind of possible implementation, computer equipment presets equalization algorithm and the target value according to this, and obtaining should Any first Key value in first Key value set, comprising: according to default random function and the second preset number, generate random Number, the random number are the natural number less than second preset number, which is based on the default equalization algorithm construction; Obtain the product of first preset number and the random number;The target value and the sum of products are retrieved as the first Key value Any first Key value in set.Wherein, the calculating formula for presetting equalization algorithm can be such that
UidKey=setId+m* (rand () %n)
Wherein, any first Key value in uidKey i.e. the first Key value set;SetId is the corresponding target of user identifier Numerical value;M is natural number, indicates the number of server cluster, i.e. the first preset number (such as 4), n is natural number, indicates each clothes The number of the server contained in business device cluster, i.e. the second preset number (such as 7);Rand () be generate one of random number with Machine function, rand () %n are random numbers to modulo n, the numberical range of modulus result be [0, n), i.e., modulus result may be 0, 1,2……n-1;* multiplying is indicated.
Such as: n 7, then the result of rand () %n may be 0,1,2 ..., 6.When the first preset number is 4, second When preset number is 7, the value of setId can be 0,1,2 or 3, then the value range of uidKey be [0,28), i.e. uidKey's Value can be 0,1,2 ..., 27.
User identifier is calculated by default equalization algorithm, the first obtained Key value is random, and according to user The probability that mark generates each first Key value is identical, i.e. the probability that each first Key value is hit in the first Key value set is flat , so that the probability that each server is acquired is average, to realize load balancing.The load balancing is referred to user Service request be distributed to different background servers so that the obtained request amount of every background server in cluster is close to flat , to rationally utilize server, the peak performance of cluster is played.By presetting equalization algorithm, to consistency hash algorithm As a result it optimizes, compensates for consistency hash algorithm in number of nodes situation on the low side the problem of load imbalance.
Above-mentioned steps 201 to step 203 is when receiving the service request of terminal, and computer equipment is asked according to the business The user identifier and default equalization algorithm, the one kind for obtaining the corresponding first Key value of the user identifier for asking middle carrying can be able to achieve Mode.The is generated at random by the way that the user identifier of string format is converted to target value, and then by default equalization algorithm Any first Key value in one Key value set, since the probability for generating any first Key value according to each user identifier is identical, And each first Key value corresponds to a server, therefore can guarantee that the probability that each server is hit is average, to realize Load balancing.
204, computer equipment is obtained from the IP address of multiple servers of the server cluster according to the first Key value Take the IP address of the corresponding server of the first Key value.
In the embodiment of the present invention, due to the IP address of a server in any first Key value corresponding server cluster, because This, computer equipment after generating a first Key value at random, can according to the first Key value and the IP address of server it Between corresponding relationship, obtain the IP address of the corresponding server of the first Key value.
205, by the IP address of the corresponding server of the first Key value, IP address is sent to the terminal as a purpose, the mesh IP address routed for the terminal, terminate.
In the embodiment of the present invention, what the first Key value was randomly generated, due to computer equipment according to each user identifier with The probability that machine generates any first Key value is identical, and each first Key value corresponds to a server, therefore, computer equipment Directly by the IP address of the corresponding server of the first Key value IP address as a purpose, that is, it can guarantee that each server is hit Probability it is average, to realize load balancing.
It should be noted that above-mentioned steps 204 and step 205 are according to the first Key value, from the more of the server cluster In the IP address of a server, obtain the corresponding IP address of the first Key value, using the corresponding IP address of the first Key value as Purpose IP address is sent to a kind of possible implementation of the terminal, and in which, the corresponding IP address of the first Key value is first The IP address of the corresponding server of Key value.
206, computer equipment obtains the 2nd Key value according to the IP address of the corresponding server of the first Key value.
Wherein, the 2nd Key value is the Key value of consistency hash algorithm.The consistency hash algorithm can be MurmurHash algorithm, consistency hash algorithm is a kind of special hash algorithm, after using consistency hash algorithm, Hash The change of table number of slots (size) is average only to be needed to remap to K/n keyword, wherein K and n is natural number, and K is crucial The quantity of word, n are slot position quantity.However in traditional hash algorithm, almost needing to institute for a slot position is added or deleted There is keyword to remap.Even if increasing new server, or existing server is deleted, it only can be to individual server Mapping relations change, and are highly suitable for demands that has certain requirements such as data landings.It can guarantee key value and service The stability of the mapping relations one by one of device, this point are that common model taking method can not be accomplished.
It is a kind of schematic diagram of consistency Hash ring provided in an embodiment of the present invention referring to Fig. 3, Fig. 3.As shown in figure 3, one There are server 1, server 2 and server 3 clockwise on cause property Hash ring, if between server 1 and server 2 Increase new server, then there are some Key values in the Key value of mapping relations to weigh with the IP address of server 2 originally New mappings are to the IP address for increasing server newly, but the IP address of server 1 and server 3 and the mapping relations of Key value will not be sent out Changing.If deleting the server 2 between server 1 and server 3, exists originally with the IP address of server 2 and map The Key value of relationship can be remapped to the IP address of server 3, but the mapping relations of the IP address of server 1 and Key value will not It changes.Computer equipment only needs to obtain the IP address of each server and reflecting for Key value by consistency hash algorithm Relationship is penetrated, and then the route balance of each machine IP may be implemented by presetting equalization algorithm.
In a kind of possible implementation, computer equipment can according to the IP of the corresponding server of the first Key value Location carries out reversed deduce by murmurHash algorithm and obtains the 2nd Key value, specifically includes shown in following steps a and step b Hash collision process:
Step a, according to the number of server in server cluster, the 2nd Key value set, the 2nd Key value set are obtained The number of middle Key value is the integral multiple of the number of the server.
Wherein, the number of server can be the product of the first preset number and the second preset number in step 203, The sum for the server that i.e. all server clusters contain.
For example, the first preset number is 4, the second preset number is 7, then the number of server is 28, if the 2nd Key value The number of Key value is 5 times of the number of the server in set, then the number of Key value is 140, second in the 2nd Key value set In Key value set the value range of Key value can be [0,139), i.e. the 2nd Key value set can be 0,1,2 ..., 139}。
Step b, each Key value in the 2nd Key value set, one Key value of every selection, then by consistent are successively chosen Property hash algorithm characteristic value is calculated, when inquiring default mapping relations according to this feature value, export corresponding with the first Key value Server IP address when, any Key value of the selection is retrieved as the 2nd Key value.
Wherein, which refers to the mapping relations between characteristic value and the IP address of server, each feature Value can correspond to the IP address of one or more servers, which can phase It is adjacent.When inquiring default mapping relations according to this feature value, the IP address of first server of output can be defaulted, other services The IP address of device alternately IP address.
It should be noted that the default mapping relations are not unalterable, for example, computer equipment can be according to default Period inquires the health degree of each server on consistency Hash ring, if the health degree of some server is less than preset threshold When, then the server can be extractd from consistency Hash ring, and the IP address of the server can also be preset in mapping relations from this It deletes, then the characteristic value for being mapped to the IP address of the server originally may be re-mapped to the IP of other servers Location.It therefore,, still can be with when inquiring default mapping relations according to characteristic value even if some server occurs after delay machine picked-off Export the IP address of another server.
For example, the Key value of selection then can be passed through consistency hash algorithm with one Key value of every selection by computer equipment (such as murmurHash algorithm) calculates, and obtains a characteristic value, then inquires mapping relations, if it is possible to export the first Key value The IP address of corresponding server, then using the Key value currently chosen as the 2nd Key value.
It should be noted that the embodiment of the present invention is to be marked with receiving service request according to the user in service request Know after obtaining the first Key value, computer equipment obtains the 2nd Key value set, and is illustrated for the 2nd Key value of acquisition, real On border, the 2nd Key value set can also be obtained, that is, step a can be in step before step 203 in advance by calculating equipment Execute after 203, can also execute before step 203, for example, computer equipment can before receiving service request, The 2nd Key value set is obtained, is then receiving service request, the first Key value is obtained according to the user identifier in service request Afterwards, then directly from the 2nd Key value set the 2nd Key value is obtained.
207, computer equipment calculates the 2nd Key value by consistency hash algorithm, obtains characteristic value.
In the embodiment of the present invention, computer equipment can use consistency hash algorithm after getting the 2nd Key value, Hash operation is carried out to the 2nd Key value, obtains characteristic value.
208, computer equipment inquires default mapping relations according to this feature value, exports the first IP address.
In the embodiment of the present invention, when computer equipment inquires default mapping relations according to this feature value, one can be exported The IP address is known as the first IP address by IP address.
209, when the corresponding server of first IP address works normally, computer equipment using first IP address as Purpose IP address is sent to the terminal.
In the embodiment of the present invention, in order to guarantee that service request is normally processed, computer equipment can choose normal work Server carry out the distribution of service request, and the IP address of the server of normal work is returned into terminal, so that terminal can To be routed according to the IP address received, the server of the normal work is accessed, by the server to the business of the terminal Request is handled.
Wherein, normal work, which refers to, currently can handle service request, and whether server, which works normally, can use health degree It measures, for example, the server that health degree is greater than or equal to preset threshold is considered as normals work, health degree is less than preset threshold Server, which is considered as, not to be worked normally.
Correspondingly, just whether the health degree of the available server of computer equipment determine server by health degree Often work.For example, computer equipment can inquire shared drive, the health degree of the corresponding server of the first IP address is obtained, When the health degree of the server is greater than or equal to preset threshold, computer equipment can be confirmed that the server works normally, because And computer equipment can be by first IP address IP address as a purpose.Wherein, shared drive is for recording each server Health degree.Health degree is used to indicate the operating status of server, such as load and the free memory etc. of server.Health degree can To be indicated with numerical value, the size of numerical value is used to indicate the fine or not degree of operation condition of server.
It should be noted that above-mentioned steps 206 to step 209 is according to the first Key value, from the more of the server cluster In the IP address of a server, obtain the corresponding IP address of the first Key value, using the corresponding IP address of the first Key value as Purpose IP address is sent to a kind of possible implementation of the terminal.Which is that the corresponding IP address of the first Key value is first The case where IP address, the corresponding server of first IP address works normally, in alternatively possible implementation, the first IP The corresponding server in address may also non-normal working, in this case, execute subsequent step 210, to select purpose IP address.
210, when the corresponding server of the first IP address does not work normally, computer equipment using the second IP address as Purpose IP address is sent to the terminal, which is the corresponding server of the first IP address on consistency Hash ring The IP address of next server.
Similarly with step 209, when the health degree of the server is less than preset threshold, the clothes are can be confirmed in computer equipment Business device does not work normally, thus, the IP address of the server of the available next normal work of computer equipment is as a purpose IP address.
In the embodiment of the present invention, if server breaks down and the health degree of server is made to be less than preset threshold, Computer equipment can extract the server from consistency Hash ring, and obtain consistency Hash ring clockwise The IP address of next server of the server returns to terminal.Certainly, if next server does not also work normally, Such as health degree of next server is again smaller than preset threshold, then computer equipment can be by the next of next server The IP address of a server returns to terminal, and so on, until the IP address of the server of a normal work is got, it will IP address returns to terminal to the IP address of the server of the normal work as a purpose.
Strategy is extractd by using automatic, under normal circumstances, the IP for the server that the 2nd Key value maps out can be returned Location successively takes next server to replace after the server, which goes wrong, to be picked-off.By returning to the clothes worked normally to terminal The IP address of business device, allows terminal to be normally carried out routing according to the IP address received.Wherein, strategy is extractd automatically to refer to When certain server, or the server of entire computer room, in addition entire region server fail when, called side can be one Corresponding server is extractd on cause property Hash ring, and the IP address of the failed server in Hash table is deleted, it is then obtained The IP address of his computer room or other servers of other regions, returns to requesting party for the IP address of other servers, thus The service request for guaranteeing that requesting party initiates normally is serviced.
By whether being worked normally according to the corresponding server of the first IP address, to decide whether that the first IP address is selected to make For purpose IP address, since the server of normal work can handle service request, thus terminal can be guaranteed according to this in this way When purpose IP address is routed, service request can be normally processed.
Scheme provided in an embodiment of the present invention can be in any server delay machine on consistency Hash ring, to initiate industry The IP address of the server of another normal work of the terminal distribution of request of being engaged in, enables service request to be normally processed, protects The redundancy ability of entire service system is demonstrate,proved.
211, computer equipment is according to the selection result server pair corresponding with first IP address of the purpose IP address The handling duration of service request determines the health degree of the server.
Wherein, the selection result of purpose IP address can be the first IP address of selection IP address as a purpose, or selection the Two IP address IP address as a purpose.
In a kind of possible implementation, computer equipment can determine rule according to preset health degree, determine first The health degree of the corresponding server of IP address, for example, the health degree determines that rule may include: to select the first IP address as mesh IP address when health degree be greater than the second IP address of selection as a purpose IP address when health degree, that is, being successfully selected the The health degree determined when one IP address is greater than the health degree determined when failing the first IP address of selection.
In addition, the health degree determines that rule can also include: when selection the first IP address IP address and service as a purpose Device is longer to the handling duration of service request, then the health degree of the server is smaller;When selecting the first IP address IP as a purpose Address and server is shorter to the handling duration of service request, then the health degree of the server is bigger.As it can be seen that the handling duration can Only to consider in the case where selecting the first IP address IP address as a purpose.The embodiment of the present invention determines rule not to health degree It is specifically limited.
It should be noted that the embodiment of the present invention only for determining the health degree of the corresponding server of the first IP address into Row explanation, in fact, IP address is returned as a purpose if computer equipment is by the IP address of the corresponding server of the second IP address Back to terminal, then computer equipment can also determine the health degree of the corresponding server of the second IP address, the embodiment of the present invention pair This is without limitation.
212, the health degree of the server is reported to the machine agency by computer equipment, and the machine agency is shared for updating The health degree of the server in memory, the shared drive are used to record the health degree of each server.
In the embodiment of the present invention, which can be reported to by computer equipment after determining the health degree of server The machine agency, the machine agency can be used as an application software deployment on the computer device, be also possible to an independence Equipment, it is not limited in the embodiment of the present invention.The machine agency can update meter after the health degree for obtaining the server Calculate the shared drive that health degree is recorded in machine equipment.
It should be noted that computer equipment can receive service request, by the user identifier in the service request When being mapped to the IP address of some server, if it is determined that the server does not work normally, then by server from consistency Hash It is extractd on ring.In fact, computer equipment can also periodically detect server, to determine the health degree of server, It determines whether to be extractd, it is not limited in the embodiment of the present invention.
For the server of excision, computer equipment can also restore its IP address using automatic recovery policy. For example, the machine agency can count the health degree of every server according to predetermined period (such as one minute).Meanwhile using automatic Recovery policy, the machine agency can also be every prefixed time intervals (such as 100ms) to server (such as step of delay machine before The server of off working state is in 210) detection packet is initiated, and detection result is reported into Hash table.Wherein, restore plan automatically Slightly refer to the server for picked-offing, the machine agency can periodically send detection packet, it is found that the failed server of some cluster is extensive When multiple normal, the IP address of the server is restored in Hash table.
For example, detection result is that server is resumed work shape if receiving server to the response message of detection packet State, thus the IP address of the server can be rejoined into Hash table;If not receiving response of the server to detection packet Message, then detection result can be server still in off working state, then Hash will not be added in the IP address of the server Table.
It should be noted that above-mentioned steps 211 to step 212 is optional step, it can be to service by the optional step The health degree of device is updated, and the health degree by counting each server in predetermined period, comes whether decision changes Kazakhstan Uncommon table, so that routing is switched to other servers from a server.It can guarantee that the IP address in Hash table is in this way State variation, when delay machine occurs for some server, when being less than preset threshold such as the health degree of server, consistency Hash ring On the server can picked-off, the IP address of the server of the delay machine can be deleted in the Hash table.When the server reaches The requirement of recovery, when being greater than preset threshold such as the health degree of server, which can be re-mapped to consistency Hash ring On, the IP address of the server can also be rejoined the Hash table, realized and gone out from visibly moved.Automatic disaster tolerance refers to before The health degree situation of one each machine of measurement period calculates the weight that every machine is accessed to, when the performance of machine is poor When, reduce the weight or extract machine automatically that machine is accessed to;When monitor machine performance restore it is normal when, by machine into Row restores.
Computer equipment is after executing the step 212, if receiving service request again, can re-execute above-mentioned Routing plan realizes the processing to the service request.Referring to fig. 4, Fig. 4 is a kind of method for routing provided in an embodiment of the present invention Flow chart, the Fig. 4 are a specific example of method for routing.
As shown in figure 4, after computer equipment receives service request, according to uid's in service request (user identifier) CRC32 value calculates setId (target value), carries out default equalization algorithm to setId value and obtains uidKey value (the first Key value), The Key value (the 2nd Key value) that consistency Hash is conversed according to uidKey value, for example, according to the first Key in above-mentioned steps 206 It is worth the IP address of corresponding server to obtain the 2nd Key value, is then gone to obtain corresponding server with the Key value of consistency Hash IP address.In turn, computer equipment may determine that whether the server works normally, if worked normally, return to the clothes The IP address of business device returns to the IP address of the server of another normal work if the server is hung.In addition, meter The health degree of server can also be fed back to the machine agency by calculating machine equipment, by the health in the machine agent update computer equipment Degree.When receiving next service request, computer equipment can handle next request by identical method.Above-mentioned mistake Journey provides a kind of automatic Disaster Tolerant Scheme of the route balance based on consistency Hash, can be used for cross-region or across computer room deployment System, realize system self feed back disaster tolerance and self detection restore function, guarantee the robustness of system, while guaranteeing system Load balancing plays the maximum performance of system.It may be implemented by introducing the default equalization algorithm that this method is mentioned even if saving Count it is on the low side in the case where, load is still balanced.The entirety ability of server can be improved in this method, more reasonably Utilize the performance of server.
Method provided in an embodiment of the present invention, by when receiving service request, using default equalization algorithm to business The user identifier carried in request is allocated, and since obtained Key value is random, and obtains the probability phase of each Key value Together, each Key value correspond to a server, so that the probability that each server is mapped be it is average, so as to The problem of being mapped to the same server is concentrated to avoid service request, enables the request amount of each server balanced, To realize load balancing, whole treatment effeciency and reliability of service are improved.
Fig. 5 is a kind of structural schematic diagram of route device provided in an embodiment of the present invention.Referring to Fig. 5, which includes:
Module 501 is obtained, for being marked according to the user carried in the service request when receiving the service request of terminal Knowledge and default equalization algorithm, obtain the corresponding first key Key value of the user identifier, and the default equalization algorithm according to user for marking The probability phase known the random any Key value generated in the first Key value set and generate any Key value according to each user identifier Together, network protocol IP address of each Key value corresponding to a server in server cluster in the first Key value set;
The acquisition module 501, is also used to according to the first Key value, from the IP of multiple servers of the server cluster In location, the corresponding IP address of the first Key value is obtained;
Sending module 502, for by the corresponding IP address of the first Key value, IP address to be sent to the terminal as a purpose, The purpose IP address is routed for the terminal.
In one embodiment, acquisition module 501, for obtaining the corresponding target value of the user identifier, the target Numerical value is the natural number less than the first preset number, which is used to indicate the number of server cluster, each clothes It is engaged in including the second present count destination server in device cluster;Preset equalization algorithm and the target value according to this, obtain this first Key value.
In one embodiment, acquisition module 501, for according to transfer algorithm is preset, which to be converted to Corresponding integer value, the default transfer algorithm are used to the user identifier of string format being converted to integer value;To the integer value Modulo operation is carried out with first preset number, obtains the target value.
In one embodiment, acquisition module 501, for according to default random function and second preset number, life At random number, which is the natural number less than second preset number, which is preset based on this accounts Method construction;
Obtain the product of first preset number and the random number;
The target value and the sum of products are retrieved as the first Key value.
In one embodiment, which is used for:
The first Key value is obtained from the IP address of multiple servers of the server cluster according to the first Key value The IP address of corresponding server;
Using the IP address of the corresponding server of the first Key value as the corresponding IP address of the first Key value;Or,
According to the IP address of the corresponding server of the first Key value, obtains the 2nd Key value and obtained according to the 2nd Key value Take the corresponding IP address of the first Key value.
In one embodiment, which is used for:
According to the number of server in the server cluster, the 2nd Key value set, Key in the 2nd Key value set are obtained The number of value is the integral multiple of the number of the server;
Each Key value in the 2nd Key value set is successively chosen, one Key value of every selection then passes through consistency Hash Characteristic value is calculated in algorithm;
When inquiring default mapping relations according to this feature value, the IP address of server corresponding with the first Key value is exported When, any Key value of the selection is retrieved as the 2nd Key value.
In one embodiment, which is used for:
2nd Key value is calculated by consistency hash algorithm, obtains characteristic value;
Default mapping relations are inquired according to this feature value, export the first IP address;
When the corresponding server of first IP address works normally, using first IP address as the first Key value pair The IP address answered.
In one embodiment, which is also used to when the abnormal work of the corresponding server of the first IP address When making, using the second IP address as the corresponding IP address of the first Key value, second IP address be on consistency Hash ring this The IP address of next server of the corresponding server of one IP address.
In one embodiment, referring to Fig. 6, the device further include:
Determining module 603, for the selection result server corresponding with first IP address according to the purpose IP address To the handling duration of service request, the health degree of the server is determined;
Sending module 602 is also used to for the health degree of the server being reported to the machine agency, which acts on behalf of for updating The health degree of the server in shared drive, the shared drive are used to record the health degree of each server.
Device provided in an embodiment of the present invention, by when receiving service request, using default equalization algorithm to business The user identifier carried in request is allocated, and since obtained Key value is random, and obtains the probability phase of each Key value Together, each Key value corresponds to the IP address of a server, so that the probability that the IP address of each server is mapped Be it is average, so as to avoid the problem that service request is concentrated the IP address for being mapped to the same server, so that each The request amount of server can be balanced, to realize load balancing, improves whole treatment effeciency and reliability of service.
It should be understood that route device provided by the above embodiment routing when, only with above-mentioned each functional module draw Divide and be illustrated, in practical application, can according to need and be completed by different functional modules above-mentioned function distribution, i.e., The internal structure of equipment is divided into different functional modules, to complete all or part of the functions described above.On in addition, The embodiment of the method for the route device and routing of stating embodiment offer belongs to same design, and specific implementation process is detailed in method reality Example is applied, which is not described herein again.
Fig. 7 is a kind of structural block diagram of computer equipment 700 provided in an embodiment of the present invention, which can Bigger difference is generated because configuration or performance are different, may include one or more processors (Central Processing Units, CPU) 701 and one or more memory 702, wherein it is stored in the memory 702 At least one instruction, at least a Duan Chengxu, code set or instruction set, at least one instruction, an at least Duan Chengxu, code set or Instruction set is loaded by the processor 701 and is executed the method for routing to realize above-mentioned each embodiment of the method offer.Certainly, the meter The components such as wired or wireless network interface, keyboard and input/output interface can also be had by calculating machine equipment 700, defeated to carry out Enter output, which can also include other for realizing the component of functions of the equipments, and this will not be repeated here.
In the exemplary embodiment, a kind of computer readable storage medium is additionally provided, instructed for example including at least one, At least memory of a Duan Chengxu, code set or instruction set, above-mentioned at least one instruction at least a Duan Chengxu, code set or refer to Enable collection that can be loaded and be executed by processor to complete the method for routing in above-described embodiment.For example, computer readable storage medium Can be read-only memory (Read-Only Memory, ROM), random access memory (Random-Access Memory, RAM), CD-ROM (Compact Disc Read-Only Memory, CD-ROM), tape, floppy disk and optical data storage devices Deng.
Those of ordinary skill in the art will appreciate that realizing that all or part of the steps of above-described embodiment can pass through hardware It completes, relevant hardware can also be instructed to complete by program, which can store in a kind of computer-readable storage In medium, storage medium mentioned above can be read-only memory, disk or CD etc..
The foregoing is merely a prefered embodiment of the invention, is not intended to limit the invention, all in the spirit and principles in the present invention Within, any modification, equivalent replacement, improvement and so on should all be included in the protection scope of the present invention.

Claims (15)

1. a kind of method for routing, which is characterized in that the described method includes:
When receiving the service request of terminal, according to the user identifier and default equalization algorithm carried in the service request, Obtain the corresponding first key Key value of the user identifier, the default equalization algorithm for generating the according to user identifier at random Any Key value in the one Key value set and probability for generating any Key value according to each user identifier is identical, the first Key Each Key value corresponds to the network protocol IP address of a server in server cluster in value set;
According to the first Key value, from the IP address of multiple servers of the server cluster, the first Key is obtained It is worth corresponding IP address;
By the corresponding IP address of the first Key value, IP address is sent to the terminal as a purpose, and the destination IP address is used It is routed in the terminal.
2. the method according to claim 1, wherein described according to the user identifier carried in the service request With default equalization algorithm, the corresponding first key Key value of the user identifier is obtained, comprising:
The corresponding target value of the user identifier is obtained, the target value is the natural number less than the first preset number, institute The number that the first preset number is used to indicate server cluster is stated, includes the service of the second preset number in each server cluster Device;
According to the default equalization algorithm and the target value, the first Key value is obtained.
3. according to the method described in claim 2, it is characterized in that, described obtain the corresponding target value of the user identifier, Include:
According to default transfer algorithm, the user identifier is converted into corresponding integer value, the default transfer algorithm is used for will The user identifier of string format is converted to integer value;
Modulo operation is carried out to the integer value and first preset number, obtains the target value.
4. according to the method described in claim 2, it is characterized in that, described according to the default equalization algorithm and the number of targets Value obtains the first Key value, comprising:
According to default random function and second preset number, random number is generated, the random number is pre- less than described second If the natural number of number, the default random function is based on the default equalization algorithm construction;
Obtain the product of first preset number and the random number;
The target value and the sum of products are retrieved as the first Key value.
5. the method according to claim 1, wherein described according to the first Key value, from the server set In the IP address of multiple servers of group, the corresponding IP address of the first Key value is obtained, comprising:
According to the first Key value, from the IP address of multiple servers of the server cluster, the first Key is obtained It is worth the IP address of corresponding server;
Using the IP address of the corresponding server of the first Key value as the corresponding IP address of the first Key value;Or,
According to the IP address of the corresponding server of the first Key value, obtains the 2nd Key value and obtained according to the 2nd Key value Take the corresponding IP address of the first Key value.
6. according to the method described in claim 5, it is characterized in that, described according to the corresponding server of the first Key value IP address obtains the 2nd Key value, comprising:
According to the number of server in the server cluster, the 2nd Key value set, Key in the 2nd Key value set are obtained The number of value is the integral multiple of the number of the server;
Each Key value in the 2nd Key value set is successively chosen, one Key value of every selection is then calculated by consistency Hash Characteristic value is calculated in method;
When inquiring default mapping relations according to the characteristic value, the IP address of server corresponding with the first Key value is exported When, any Key value of the selection is retrieved as the 2nd Key value.
7. according to the method described in claim 5, it is characterized in that, described according to the 2nd Key value, acquisition described first The corresponding IP address of Key value, comprising:
The 2nd Key value is calculated by consistency hash algorithm, obtains characteristic value;
Default mapping relations are inquired according to the characteristic value, export the first IP address;
When the corresponding server of first IP address works normally, using first IP address as the first Key value Corresponding IP address.
8. the method according to the description of claim 7 is characterized in that described inquire default mapping relations according to the characteristic value, After exporting the first IP address, the method also includes:
When the corresponding server of first IP address does not work normally, using the second IP address as the first Key value pair The IP address answered, second IP address are next clothes of the corresponding server of first IP address on consistency Hash ring The IP address of business device.
9. the method according to the description of claim 7 is characterized in that it is described using the corresponding IP address of the first Key value as Purpose IP address is sent to after the terminal, the method also includes:
Processing according to the selection result of the destination IP address and the corresponding server of first IP address to service request Duration determines the health degree of the server;
The health degree of the server is reported to the machine agency, the machine agency is for updating service described in shared drive The health degree of device, the shared drive are used to record the health degree of each server.
10. a kind of route device, which is characterized in that described device includes:
Obtain module, for when receiving the service request of terminal, according to the user identifier carried in the service request and Default equalization algorithm obtains the corresponding first key Key value of the user identifier, and the default equalization algorithm according to user for marking The probability phase known the random any Key value generated in the first Key value set and generate any Key value according to each user identifier Together, network protocol IP address of each Key value corresponding to a server in server cluster in the first Key value set;
The acquisition module is also used to according to the first Key value, from the IP address of multiple servers of the server cluster In, obtain the corresponding IP address of the first Key value;
Sending module, it is described for by the corresponding IP address of the first Key value, IP address to be sent to the terminal as a purpose Purpose IP address is routed for the terminal.
11. device according to claim 10, which is characterized in that the acquisition module is used for:
According to the first Key value, from the IP address of multiple servers of the server cluster, the first Key is obtained It is worth the IP address of corresponding server;
Using the IP address of the corresponding server of the first Key value as the corresponding IP address of the first Key value;Or,
According to the IP address of the corresponding server of the first Key value, obtains the 2nd Key value and obtained according to the 2nd Key value Take the corresponding IP address of the first Key value.
12. device according to claim 11, which is characterized in that the acquisition module is used for:
According to the number of server in the server cluster, the 2nd Key value set, Key in the 2nd Key value set are obtained The number of value is the integral multiple of the number of the server;
Each Key value in the 2nd Key value set is successively chosen, one Key value of every selection is then calculated by consistency Hash Characteristic value is calculated in method;
When inquiring default mapping relations according to the characteristic value, the IP address of server corresponding with the first Key value is exported When, any Key value of the selection is retrieved as the 2nd Key value.
13. device according to claim 11, which is characterized in that the acquisition module is used for:
The 2nd Key value is calculated by consistency hash algorithm, obtains characteristic value;
Default mapping relations are inquired according to the characteristic value, export the first IP address;
When the corresponding server of first IP address works normally, using first IP address as the first Key value Corresponding IP address.
14. a kind of computer equipment, which is characterized in that the computer equipment includes processor and memory, the memory In be stored at least one instruction, at least a Duan Chengxu, code set or instruction set, at least one instruction, an at least Duan Cheng Sequence, code set or instruction set are loaded by the processor and are executed to realize routing side as described in any one of claim 1 to 9 Method.
15. a kind of computer readable storage medium, which is characterized in that be stored at least one in the computer readable storage medium Item instruction, at least a Duan Chengxu, code set or instruction set, at least one instruction, an at least Duan Chengxu, code set or instruction Collection is loaded by processor and is executed to realize method for routing as described in any one of claim 1 to 9.
CN201810557033.4A 2018-06-01 2018-06-01 Routing method and device Active CN110213316B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810557033.4A CN110213316B (en) 2018-06-01 2018-06-01 Routing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810557033.4A CN110213316B (en) 2018-06-01 2018-06-01 Routing method and device

Publications (2)

Publication Number Publication Date
CN110213316A true CN110213316A (en) 2019-09-06
CN110213316B CN110213316B (en) 2021-09-03

Family

ID=67778841

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810557033.4A Active CN110213316B (en) 2018-06-01 2018-06-01 Routing method and device

Country Status (1)

Country Link
CN (1) CN110213316B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111541766A (en) * 2020-04-21 2020-08-14 西安电子科技大学 Multi-server communication connection method
CN112965818A (en) * 2021-02-26 2021-06-15 平安普惠企业管理有限公司 Service cluster unitized grouping method, device, equipment and medium
CN113010224A (en) * 2021-03-03 2021-06-22 南方电网数字电网研究院有限公司 Front-end micro-service method, device, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070053334A1 (en) * 2005-09-02 2007-03-08 Noriyuki Sueyoshi Packet forwarding apparatus for connecting mobile terminal to ISP network
CN101489260A (en) * 2008-12-31 2009-07-22 华为技术有限公司 Method, apparatus and system for communication service processing
CN104852934A (en) * 2014-02-13 2015-08-19 阿里巴巴集团控股有限公司 Method for realizing flow distribution based on front-end scheduling, device and system thereof
CN107070989A (en) * 2017-03-06 2017-08-18 北京潘达互娱科技有限公司 Communication means and system
CN107733991A (en) * 2017-09-19 2018-02-23 大唐网络有限公司 One kind provides load balancing service implementation method based on OpenStack frameworks

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070053334A1 (en) * 2005-09-02 2007-03-08 Noriyuki Sueyoshi Packet forwarding apparatus for connecting mobile terminal to ISP network
CN101489260A (en) * 2008-12-31 2009-07-22 华为技术有限公司 Method, apparatus and system for communication service processing
CN104852934A (en) * 2014-02-13 2015-08-19 阿里巴巴集团控股有限公司 Method for realizing flow distribution based on front-end scheduling, device and system thereof
CN107070989A (en) * 2017-03-06 2017-08-18 北京潘达互娱科技有限公司 Communication means and system
CN107733991A (en) * 2017-09-19 2018-02-23 大唐网络有限公司 One kind provides load balancing service implementation method based on OpenStack frameworks

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111541766A (en) * 2020-04-21 2020-08-14 西安电子科技大学 Multi-server communication connection method
CN112965818A (en) * 2021-02-26 2021-06-15 平安普惠企业管理有限公司 Service cluster unitized grouping method, device, equipment and medium
CN112965818B (en) * 2021-02-26 2022-08-26 平安普惠企业管理有限公司 Service cluster unitized grouping method, device, equipment and medium
CN113010224A (en) * 2021-03-03 2021-06-22 南方电网数字电网研究院有限公司 Front-end micro-service method, device, computer equipment and storage medium
CN113010224B (en) * 2021-03-03 2024-01-30 南方电网数字平台科技(广东)有限公司 Front-end micro-servitization method, front-end micro-servitization device, computer equipment and storage medium

Also Published As

Publication number Publication date
CN110213316B (en) 2021-09-03

Similar Documents

Publication Publication Date Title
US7543069B2 (en) Dynamically updating session state affinity
CN106097107B (en) Systems and methods for social graph data analysis to determine connectivity within a community
CN108920272A (en) A kind of data processing method, device, computer equipment and storage medium
US11637889B2 (en) Configuration recommendation for a microservice architecture
JP2022501752A (en) How to assign electronic bill identifiers, how to generate electronic bills, their devices and systems, as well as storage media and computer programs.
US8364163B2 (en) Method, system and apparatus for connecting a plurality of client machines to a plurality of servers
CN111405019B (en) Data processing method, data processing device, computer equipment and storage medium
US11553014B2 (en) Downloading of server-based content through peer-to-peer networks
US20070121490A1 (en) Cluster system, load balancer, node reassigning method and recording medium storing node reassigning program
CN110213316A (en) Method for routing and device
JP4190455B2 (en) Load balancing apparatus and program
CN113077259A (en) Block chain-based evidence storing method and device and electronic equipment
US20110153826A1 (en) Fault tolerant and scalable load distribution of resources
CN107249038A (en) Business datum retransmission method and system
JP5154313B2 (en) SIP message distribution method and SIP message distribution apparatus
CN113315825A (en) Distributed request processing method, device, equipment and storage medium
CN109981476A (en) A kind of load-balancing method and device
US7711780B1 (en) Method for distributed end-to-end dynamic horizontal scalability
US10715608B2 (en) Automatic server cluster discovery
US11442632B2 (en) Rebalancing of user accounts among partitions of a storage service
WO2017167129A1 (en) Method and device for distributing data center data to user
CN107046503A (en) A kind of message transmitting method, system and its apparatus
EP3977709A1 (en) System and method of facilitating data communication between an internet of things device and a cloud-based computer system
JP2005141644A (en) Information processing apparatus for managing data storage, data management method, program, and recording medium
CN112559460B (en) File storage method, device, equipment and storage medium based on artificial intelligence

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant