WO2019200714A1 - 服务器连接方法、计算机可读存储介质、终端设备及装置 - Google Patents

服务器连接方法、计算机可读存储介质、终端设备及装置 Download PDF

Info

Publication number
WO2019200714A1
WO2019200714A1 PCT/CN2018/093342 CN2018093342W WO2019200714A1 WO 2019200714 A1 WO2019200714 A1 WO 2019200714A1 CN 2018093342 W CN2018093342 W CN 2018093342W WO 2019200714 A1 WO2019200714 A1 WO 2019200714A1
Authority
WO
WIPO (PCT)
Prior art keywords
hash
function
server
hashvt
candidate
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.)
Ceased
Application number
PCT/CN2018/093342
Other languages
English (en)
French (fr)
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.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An 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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Publication of WO2019200714A1 publication Critical patent/WO2019200714A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/55Push-based network services
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
    • 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

Definitions

  • the present application belongs to the field of computer technologies, and in particular, to a server connection method, a computer readable storage medium, a terminal device, and a device.
  • the basics of message push need to maintain a long connection between the user's terminal device and the server. As the number of user terminals increases, the long connection server also needs to be scaled horizontally at any time. Currently, a long connection is established by the user's terminal device randomly requesting a server to maintain a long connection. In this case, when the message is pushed, the message needs to be distributed to each server, and the server that keeps the long connection is pushed to the user's terminal device, which not only causes waste of server resources, but also increases the probability of message retransmission. .
  • the embodiment of the present application provides a server connection method, a computer readable storage medium, a terminal device, and a device, to solve a waste of server resources caused by a user terminal device randomly requesting a server to maintain a long connection.
  • a first aspect of the embodiment of the present application provides a server connection method, which may include:
  • each reference node on the hash ring where each reference node is a node corresponding to one server on the hash ring;
  • a second aspect of embodiments of the present application provides a computer readable storage medium storing computer readable instructions, the steps of implementing the server connection method when executed by a processor .
  • a third aspect of an embodiment of the present application provides a server connection terminal device including a memory, a processor, and computer readable instructions stored in the memory and executable on the processor, the processor executing the The steps of the above server connection method are implemented when the computer readable instructions are described.
  • a fourth aspect of the embodiments of the present application provides a server connection apparatus, which may include a module for implementing the steps of the server connection method described above.
  • FIG. 1 is a flowchart of an embodiment of a server connection method according to an embodiment of the present application
  • FIG. 2 is a schematic diagram of a hash ring
  • FIG. 3 is a schematic diagram of a hash value of a terminal device mapped to a node of a hash ring;
  • FIG. 7 is a schematic block diagram of a server connection terminal device according to an embodiment of the present application.
  • an embodiment of a server connection method in an embodiment of the present application may include:
  • Step S101 Acquire an identity identifier of the terminal device.
  • the identity of the terminal device may refer to the International Mobile Equipment Identity (IMEI) of the terminal, and the international mobile device identity code is an electronic serial number consisting of 15 digits, which corresponds to each terminal device one by one. And the code is the only one in the world.
  • IMEI International Mobile Equipment Identity
  • Each terminal device will be assigned a globally unique number after assembly, and this number will be recorded by the manufacturer of the manufacturing from production to delivery.
  • Step S102 Perform a hash operation on the identity identifier by using a preset first hash function to obtain a hash value of the terminal device.
  • All hash functions have one of the following basic properties: If the two hash values are not identical (based on the same hash function), the original input of the two hash values is also different. This feature gives the hash function a deterministic result. On the other hand, the input and output of the hash function are not unique. If the two hash values are the same, the two input values are likely to be the same, but they may be different. This case is called a "hash collision.” "This is usually two different input values, deliberately calculating the same output value.” However, for the hash function commonly used in the prior art, the probability of collision is extremely low, almost negligible, inputting some data to calculate a hash value, and then partially changing the input value, a hash with strong confusion characteristics. The function produces a completely different hash value.
  • the first hash function in this embodiment may include, but is not limited to, a hash function commonly used in the prior art such as MD4, MD5, and SHA1.
  • the identifiers of the obtained terminal devices are respectively represented as: IMEI 1 , IMEI 2 , IMEI 3 , . . . , IMEI m , . . . , IMEI M , where IMEI m is the identity of the mth terminal device, 1 ⁇ m ⁇ M, M is the total number of terminal devices.
  • HashFunc1 is the first hash function
  • Key m is the hash value of the mth terminal device.
  • Step S103 Map the hash value of the terminal device to the first node of the hash ring.
  • Step S104 Acquire each reference node on the hash ring.
  • Each of the reference nodes is a node corresponding to one server on the hash ring.
  • the setting process of the reference node includes:
  • each of the reference nodes is obtained.
  • the identifier of the server may be an IP address of the server, and the identifiers of the obtained servers are respectively represented as: IP 1 , IP 2 , IP 3 , . . . , IP m′ , . . . , IP M′ , where IP m' is the identity of the mth server, 1 ⁇ m' ⁇ M', and M' is the total number of servers.
  • HashFunc2 is the second hash function
  • Key' m' is the hash value of the mth server. It is particularly noted that the value range of the second hash function and the first hash function are The values are consistent, so that both can be mapped to the same hash ring.
  • Figure 4 shows the case where the hash values of the seven servers are mapped to the nodes of the hash ring, respectively, Key' 1 , Key' 2 , Key' 3 , Key' 4 , Key' 5 , Key' 6 , Key'
  • the node corresponding to 7 is the reference node.
  • Step S105 Find the reference node clockwise or counterclockwise from the first node, and determine the server corresponding to the first reference node that is found as a preferred server.
  • the corresponding IMEI 1 Key for example, from its corresponding node, i.e. the node starts to find the reference node clockwise, to find the first reference node Key '1
  • the server with the address IP 1 is determined as the preferred server of the IMEI 1 .
  • the server whose address is IP 4 is determined to be the preferred server of IMEI 3
  • the server whose address is IP 6 is determined to be the preferred server of IMEI 4 .
  • the server whose address is IP 7 is determined to be the preferred server of IMEI 1
  • the server whose address is IP 2 is determined to be the preferred server of IMEI 2
  • the server whose address is IP 3 is determined as The preferred server of the IMEI 3 and the server of the IP 5 are determined as the preferred servers of the IMEI 4 .
  • Step S106 Establish a communication connection between the terminal device and the preferred server.
  • the number of different mapping locations may be set for different servers according to the processing capability of the server.
  • the server processing power from high to low is: server 1, server 2, server 3. Then, the mapping position of the server 1 is set to three, the mapping position of the server 2 is set to two, and the mapping position of the server 1 is set to one.
  • IP address IP 1 of the server 1 is expanded to three virtual IPs: IP 1_1 , IP 1_2 , IP 1_3
  • IP address IP 2 of the server 2 is expanded to two virtual IPs: IP 2_1 , IP 2_2 , IP 1_3
  • IP address IP 3 of the server 3 is kept unchanged, and the corresponding node of each IP hash value on the hash ring is as shown in FIG. 5 .
  • the reference node in step S104 can also be set by the following process:
  • m is the serial number of the server, 1 ⁇ m ⁇ M, M is the total number of servers, ServerIDm is the identity of the mth server, n is the serial number of the extended identity, and the extended identity can be the aforementioned virtual IP , 1 ⁇ n ⁇ Nm, Nm is the total number of extended identity identifiers of the mth server, Nm is positively correlated with the frequency of the central processor of the mth server, and is positively correlated with the memory capacity of the mth server, that is, the central The higher the main frequency of the processor and the larger the memory capacity, the larger the total number of extended identities. Conversely, the lower the main frequency of the central processing unit and the smaller the memory capacity, the smaller the total number of extended identities. .
  • ExtFunc is a preset function.
  • the servers corresponding to the three virtual IP nodes of the server 1 in FIG. 5 are both the server 1, and the servers corresponding to the two virtual IP nodes of the server 2 are the servers 2.
  • a setting method of the second hash function may include:
  • a hash function is arbitrarily selected from the preset hash function set as a candidate function, and the hash function set includes more than one hash function.
  • the candidate function is used to hash the extended identity of each server to obtain a hash value of each server.
  • HashValueSetT is a collection of hash values from each server.
  • the uniformity of the candidate function is calculated according to the following formula:
  • HashMax is the maximum function value of the candidate function
  • EvenDeg is the uniformity of the candidate function
  • the candidate function is determined as a second hash function.
  • Another setting method of the second hash function may include:
  • a hash function is arbitrarily selected from the preset hash function set as a candidate function, and the hash function set includes more than one hash function.
  • the candidate function is used to hash the extended identity of each server to obtain a hash value of each server.
  • HashArrayT (hashvt 1 , hashvt 2 , ..., hashvt tn , ..., hashvt TN )
  • TN is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • the uniformity of the candidate function is calculated according to the following formula:
  • HashMax is the maximum function value of the candidate function
  • is a preset proportional coefficient
  • EvenDeg is the uniformity of the candidate function.
  • the candidate function is determined as a second hash function.
  • the embodiment of the present application sets a hash ring formed by sequentially connecting all the function values of the first hash function in a clockwise or counterclockwise order from small to large, and the server and the terminal device are both Mapping to the hash ring, establishing a spatial correspondence between the server and the terminal device, and determining the preferred server corresponding to the terminal device by clockwise or counterclockwise searching, the probability of collision due to hash operation It is almost negligible, so the preferred server determined in this way can be regarded as unique, which reduces the waste of server resources and greatly reduces the chance of message retransmission.
  • FIG. 6 is a structural diagram of an embodiment of a server connection apparatus according to an embodiment of the present application.
  • a server connection device may include:
  • the terminal identifier obtaining module 601 is configured to acquire an identity identifier of the terminal device.
  • the first hash operation module 602 is configured to perform hash operation on the identity identifier by using a preset first hash function to obtain a hash value of the terminal device.
  • a first mapping module 603 configured to map a hash value of the terminal device to a first node of a hash ring, where the hash ring is a function of all functions of the first hash function from small to large Arranging the formed rings sequentially in a clockwise or counterclockwise manner, each node is a function value constituting the hash ring, and the first node is any one of the nodes on the hash ring;
  • a reference node obtaining module 604 configured to acquire each reference node on the hash ring, where each reference node is a node corresponding to one server on the hash ring;
  • a server determining module 605 configured to search the reference node clockwise or counterclockwise from the first node, and determine a server corresponding to the first reference node that is found as a preferred server;
  • the communication connection establishing module 606 is configured to establish a communication connection between the terminal device and the preferred server.
  • the server connection device may further include:
  • a server identifier obtaining module configured to acquire an identity of each server
  • a second hash operation module configured to hash the identity of each server by using a preset second hash function, to obtain a hash value of each server, and a value field of the second hash function
  • the value range of the first hash function is consistent
  • the server connection device may further include:
  • An identity extension module for calculating an extended identity of each server according to the following formula:
  • n is the serial number of the extended identity
  • 1 ⁇ n ⁇ Nm is the total number of servers
  • ServerIDm is the identity of the mth server
  • n is the serial number of the extended identity
  • 1 ⁇ n ⁇ Nm is the mth server
  • Nm is the mth server
  • the total number of extended identities, Nm is positively correlated with the frequency of the central processor of the mth server, and is positively related to the memory capacity of the mth server
  • ExtFunc is the default function
  • Ext_ServerIDm is the mth server The nth extended identity.
  • the server connection device may further include:
  • a candidate function selection module configured to arbitrarily select one hash function from the preset hash function set as a candidate function, the hash function set includes one or more hash functions;
  • a hash operation module configured to hash the extended identity of each server by using the candidate function, to obtain a hash value of each server
  • the first sequence construction module is configured to construct a sequence of hash values according to the following formula:
  • HashArrayT (hashvt 1 , hashvt 2 , ..., hashvt tn , ..., hashvt TN )
  • HashValueSetT is a set consisting of hash values of the respective servers
  • a first uniformity calculation module configured to calculate a uniformity of the candidate function according to the following formula:
  • HashMax is the maximum function value of the candidate function
  • EvenDeg is the uniformity of the candidate function
  • a candidate function deleting module configured to delete the candidate function from the hash function set if a uniformity of the candidate function is greater than a preset uniformity threshold
  • the function determining module is configured to determine the candidate function as the second hash function if the uniformity of the candidate function is less than or equal to a preset uniformity threshold.
  • the server connection device may further include:
  • the second sequence construction module is configured to construct each hash value sequence according to the following formula:
  • HashArrayT (hashvt 1 , hashvt 2 , ..., hashvt tn , ..., hashvt TN )
  • TN is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • Hashvt tn is the total number of hash values of each server
  • a second uniformity calculation module configured to calculate a uniformity of the candidate function according to the following formula:
  • HashMax is the maximum function value of the candidate function
  • is a preset proportional coefficient
  • EvenDeg is the uniformity of the candidate function.
  • FIG. 7 is a schematic block diagram of a server connection terminal device provided by an embodiment of the present application. For convenience of description, only parts related to the embodiment of the present application are shown.
  • the server connection terminal device 7 may be a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server.
  • the server connection terminal device 7 may include a processor 70, a memory 71, and computer readable instructions 72 stored in the memory 71 and operable on the processor 70, such as a computer executing the server connection method described above. Read the instruction.
  • the processor 70 executes the computer readable instructions 72, the steps in the above embodiments of the respective server connection methods are implemented.
  • the functional units in the various embodiments of the present application may be stored in a computer readable storage medium if implemented in the form of a software functional unit and sold or used as a separate product. Based on such understanding, the technical solution of the present application, in essence or the contribution to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium. A number of computer readable instructions are included to cause a computer device to perform all or part of the steps of the methods described in various embodiments of the present application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

本申请属于计算机技术领域,尤其涉及一种服务器连接方法、计算机可读存储介质、终端设备及装置。所述方法本申请实施例获取终端设备的身份标识;使用预设的第一哈希函数对所述身份标识进行哈希运算,得到所述终端设备的哈希值;将所述终端设备的哈希值映射至哈希环的第一节点;获取所述哈希环上的各个基准节点;从所述第一节点开始顺时针或者逆时针查找所述基准节点,并将查找到的第一个基准节点所对应的服务器确定为优选服务器;建立所述终端设备与所述优选服务器之间的通信连接。减少了服务器资源的浪费,也大大降低了消息重发的几率。

Description

服务器连接方法、计算机可读存储介质、终端设备及装置
本申请要求于2018年4月17日提交中国专利局、申请号为201810341964.0、发明名称为“一种服务器连接方法、计算机可读存储介质及终端设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请属于计算机技术领域,尤其涉及一种服务器连接方法、计算机可读存储介质、终端设备及装置。
背景技术
消息推送的基础需要保持用户的终端设备与服务器建立的长连接。随着用户的终端设备数量不断增加,长连接服务器也需要随时横向扩容。目前建立长连接的方式是由用户的终端设备随机请求某台服务器来保持长连接。这种情况下,推送消息时就需要将消息分发给每一台服务器,由保持长连接的那一台服务器推送至用户的终端设备,不仅造成服务器资源的浪费,也增大消息重发的几率。
技术问题
有鉴于此,本申请实施例提供了一种服务器连接方法、计算机可读存储介质、终端设备及装置,以解决由用户的终端设备随机请求某台服务器来保持长连接所造成的服务器资源浪费以及消息重发几率增大的问题。
技术解决方案
本申请实施例的第一方面提供了一种服务器连接方法,可以包括:
获取终端设备的身份标识;
使用预设的第一哈希函数对所述身份标识进行哈希运算,得到所述终端设备的哈希值;
将所述终端设备的哈希值映射至哈希环的第一节点,所述哈希环为由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的圆环,每个节点均为构成所述哈希环的一个函数值,所述第一节点为所述哈希环上的任意一个节点;
获取所述哈希环上的各个基准节点,其中,每个基准节点均为所述哈希环上与一个服务器对应的节点;
从所述第一节点开始顺时针或者逆时针查找所述基准节点,并将查找到的第一个基准节点所对应的服务器确定为优选服务器;
建立所述终端设备与所述优选服务器之间的通信连接。
本申请实施例的第二方面提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可读指令,所述计算机可读指令被处理器执行时实现上述服务器连接方法的步骤。
本申请实施例的第三方面提供了一种服务器连接终端设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,所述处理器执行所述计算机可读指令时实现上述服务器连接方法的步骤。
本申请实施例的第四方面提供了一种服务器连接装置,可以包括用于实现上述服务器连接方法的步骤的模块。
有益效果
本申请实施例与现有技术相比存在的有益效果是:本申请实施例通过设置一个由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的哈希环,将服务器以及终端设备均映射至哈希环上,建立起了服务器与终端设备之间的空间对应关系,通过顺时针或者逆时针查找的方式即可确定出与终端设备对应的优选服务器,由于哈希运算发生碰撞的概率几乎可以忽略不计,因此通过这种方式确定出的优选服务器可视为是唯一的,从而减少了服务器资源的浪费,也大大降低了消息重发的几率。
附图说明
图1为本申请实施例中一种服务器连接方法的一个实施例流程图;
图2为哈希环的示意图;
图3为终端设备的哈希值映射至哈希环的节点上的示意图;
图4为服务器的哈希值映射至哈希环的节点上的一种示意图;
图5为服务器的哈希值映射至哈希环的节点上的另一种示意图;
图6为本申请实施例中一种服务器连接装置的示意框图。
图7为本申请实施例中一种服务器连接终端设备的示意框图。
本发明的实施方式
请参阅图1,本申请实施例中一种服务器连接方法的一个实施例可以包括:
步骤S101、获取终端设备的身份标识。
终端设备的身份标识可以是指终端的国际移动设备身份码(International Mobile Equipment Identity,IMEI),国际移动设备身份码是由15位数字组成的电子串号,它与每个终端设备一一对应,而且该码是全世界唯一的。每一个终端设备在组装完成后都将被赋予一个全球唯一的号码,这个号码从生产到交付使用都将被制造生产的厂商所记录。
步骤S102、使用预设的第一哈希函数对所述身份标识进行哈希运算,得到所述终端设备的哈希值。
所有的哈希函数都有如下一个基本特性:如果两个哈希值是不相同的(根据同一哈希函数),那么这两个哈希值的原始输入也是不相同的。这个特性使哈希函数具有确定性的结果。但另一方面,哈希函数的输入和输出不是唯一对应关系的,如果两个哈希值相同,两个输入值很可能是相同的,但也可能不同,这种情况称为“哈希碰撞”,这通常是两个不同的输入值,刻意计算出相同的输出值。但对于现有技术中常用的哈希函数而言,其发生碰撞的概率极低,几乎可以忽略不计,输入一些数据计算出哈希值,然后部分改变输入值,一个具有强混淆特性的哈希函数会产生一个完全不同的哈希值。
本实施例中的第一哈希函数可以包括但不限于MD4、MD5、SHA1等任意一个现有技术中常用的哈希函数。
将获取到的终端设备的身份标识分别表示为:IMEI 1、IMEI 2、IMEI 3、……、IMEI m、……、IMEI M,其中,IMEI m为第m个终端设备的身份标识,1≤m≤M,M为终端设备的总个数。
然后,计算各个终端设备的哈希值:
Key m=HashFunc1(IMEI m)
其中,HashFunc1为第一哈希函数,Key m为第m个终端设备的哈希值。
步骤S103、将所述终端设备的哈希值映射至哈希环的第一节点。
所述哈希环为由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的圆环,每个节点均为构成所述哈希环的一个函数值,若第一哈希函数的值域为[0,N],且以顺时针的顺序排列,则可构成如图2所示的哈希环。
所述第一节点为所述哈希环上的任意一个节点,其取值即为所述终端设备的哈希值。图3所示为4个终端设备的哈希值分别映射至哈希环的节点上的情形。
步骤S104、获取所述哈希环上的各个基准节点。
其中,每个基准节点均为所述哈希环上与一个服务器对应的节点。所述基准节点的设置过程包括:
获取各个服务器的身份标识,使用预设的第二哈希函数分别对各个服务器的身份标识进行哈希运算,得到各个服务器的哈希值,将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
其中,服务器的身份标识可以为服务器的IP地址,将获取到的服务器的身份标识分别表示为:IP 1、IP 2、IP 3、……、IP m′、……、IP M′,其中,IP m′为第m′个服务器的 身份标识,1≤m′≤M′,M′为服务器的总个数。
使用下式计算各个服务器的哈希值:
Key′ m′=HashFunc2(IP m′)
其中,HashFunc2为第二哈希函数,Key′ m′为第m′个服务器的哈希值,特别需要注意的是,所述第二哈希函数的值域与所述第一哈希函数的值域一致,以此保证两者可以映射到同一个哈希环上。
图4所示为7个服务器的哈希值分别映射至哈希环的节点上的情形,Key′ 1、Key′ 2、Key′ 3、Key′ 4、Key′ 5、Key′ 6、Key′ 7所对应的节点即为所述基准节点。
步骤S105、从所述第一节点开始顺时针或者逆时针查找所述基准节点,并将查找到的第一个基准节点所对应的服务器确定为优选服务器。
以图4中IMEI 1所对应的Key 1为例,从其所对应的节点,也即所述第一节点开始顺时针查找所述基准节点,查找到的第一个基准节点为Key′ 1,则将地址为IP 1的服务器确定为IMEI 1的优选服务器。使用同样的方法,可以确定地址为IP 3的服务器确定为IMEI 2的优选服务器、地址为IP 4的服务器确定为IMEI 3的优选服务器、地址为IP 6的服务器确定为IMEI 4的优选服务器。
类似地,若采用逆时针查找的方法,则可以确定地址为IP 7的服务器确定为IMEI 1的优选服务器、地址为IP 2的服务器确定为IMEI 2的优选服务器、地址为IP 3的服务器确定为IMEI 3的优选服务器、地址为IP 5的服务器确定为IMEI 4的优选服务器。
步骤S106、建立所述终端设备与所述优选服务器之间的通信连接。
当建立了两者之间的通信连接之后,推送消息时就无需将消息分发给每一台服务器,而是只将消息发送给目标终端设备的优选服务器,由优选服务器将消息推送至目标终端设备,从而减少了服务器资源的浪费,也大大降低了消息重发的几率。
进一步地,考虑到不同的服务器的处理能力是不同的,可以根据服务器的处理能力为不同的服务器设置不同的映射位置的个数。例如,服务器处理能力由高到低依次为:服务器1、服务器2、服务器3。则将服务器1的映射位置设置为3个,将服务器2的映射位置设置为2个,将服务器1的映射位置设置为1个。具体地,将服务器1的IP地址IP 1扩展为3个虚拟IP:IP 1_1、IP 1_2、IP 1_3,将服务器2的IP地址IP 2扩展为2个虚拟IP:IP 2_1、IP 2_2、IP 1_3,将服务器3的IP地址IP 3保持不变,则各个IP哈希值在哈希环上对应的节点如图5所示。
根据这一思路,步骤S104中的所述基准节点还可以通过以下过程进行设置:
首先,获取各个服务器的身份标识。
然后,根据下式计算各个服务器的扩展身份标识:
Ext_ServerIDm,n=ExtFunc(ServerIDm,n)
其中,m为服务器的序号,1≤m≤M,M为服务器的总数,ServerIDm为第m个服务器的身份标识,n为扩展身份标识的序号,所述扩展身份标识即可为前述的虚拟IP,1≤n≤Nm,Nm为第m个服务器的扩展身份标识的总数,Nm与第m个服务器的中央处理器的主频正相关,且与第m个服务器的内存容量正相关,即中央处理器的主频越高,且内存容量越大,则扩展身份标识的总数也越大,反之,中央处理器的主频越低,且内存容量越小,则扩展身份标识的总数也越小。ExtFunc为预设的函数,在其中的一种实现中,ExtFunc(ServerIDm,n)=ServerIDm∪.n,即在ServerIDm之后再加入一个.n后缀,若ServerIDm=120.132.55.7,则ExtFunc(ServerIDm,1)=120.132.55.7.1,Ext_ServerIDm,n为第m个服务器的第n个扩展身份标识;
再使用预设的第二哈希函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致。
最后,将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
此时,需要注意,图5中服务器1的3个虚拟IP节点对应的服务器均为服务器1,服务器2的2个虚拟IP节点对应的服务器均为服务器2。
进一步地,所述第二哈希函数的一种设置方法可以包括:
从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数。
使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值。
根据下式构造哈希值序列:
HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
Figure PCTCN2018093342-appb-000001
hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合。
根据下式计算所述候选函数的均匀度:
Figure PCTCN2018093342-appb-000002
其中,HashMax为所述候选函数的最大函数值,EvenDeg为所述候选函数的均匀度。
若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希 函数集合中删除,然后返回执行所述从预设的哈希函数集合中任意选取一个哈希函数作为候选函数的步骤;
若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
进一步地,所述第二哈希函数的另一种设置方法可以包括:
从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数。
使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值。
根据下式构造各个哈希值序列:
HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
Figure PCTCN2018093342-appb-000003
其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
Figure PCTCN2018093342-appb-000004
hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合,hashv m,n∈HashValueSet m,且hashv m,n≤hashv m,n+1,HashValueSet m为由第m个服务器的哈希值组成的集合。
根据下式计算所述候选函数的均匀度:
Figure PCTCN2018093342-appb-000005
其中,HashMax为所述候选函数的最大函数值,η为预设的比例系数,EvenDeg为所述候选函数的均匀度。
若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希函数集合中删除,然后返回执行所述从预设的哈希函数集合中任意选取一个哈希函数作为候选函数的步骤;
若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
综上所述,本申请实施例通过设置一个由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的哈希环,将服务器以及终端设备均映射至哈希环上,建立起了服务器与终端设备之间的空间对应关系,通过顺时针或者 逆时针查找的方式即可确定出与终端设备对应的优选服务器,由于哈希运算发生碰撞的概率几乎可以忽略不计,因此通过这种方式确定出的优选服务器可视为是唯一的,从而减少了服务器资源的浪费,也大大降低了消息重发的几率。
对应于上文实施例所述的一种服务器连接方法,图6示出了本申请实施例提供的一种服务器连接装置的一个实施例结构图。
本实施例中,一种服务器连接装置可以包括:
终端标识获取模块601,用于获取终端设备的身份标识;
第一哈希运算模块602,用于使用预设的第一哈希函数对所述身份标识进行哈希运算,得到所述终端设备的哈希值;
第一映射模块603,用于将所述终端设备的哈希值映射至哈希环的第一节点,所述哈希环为由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的圆环,每个节点均为构成所述哈希环的一个函数值,所述第一节点为所述哈希环上的任意一个节点;
基准节点获取模块604,用于获取所述哈希环上的各个基准节点,其中,每个基准节点均为所述哈希环上与一个服务器对应的节点;
优选服务器确定模块605,用于从所述第一节点开始顺时针或者逆时针查找所述基准节点,并将查找到的第一个基准节点所对应的服务器确定为优选服务器;
通信连接建立模块606,用于建立所述终端设备与所述优选服务器之间的通信连接。
可选地,所述服务器连接装置还可以包括:
服务器标识获取模块,用于获取各个服务器的身份标识;
第二哈希运算模块,用于使用预设的第二哈希函数分别对各个服务器的身份标识进行哈希运算,得到各个服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致;
第二映射模块,用于将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
可选地,所述服务器连接装置还可以包括:
身份标识扩展模块,用于根据下式计算各个服务器的扩展身份标识:
Ext_ServerIDm,n=ExtFunc(ServerIDm,n)
其中,m为服务器的序号,1≤m≤M,M为服务器的总数,ServerIDm为第m个服务器的身份标识,n为扩展身份标识的序号,1≤n≤Nm,Nm为第m个服务器的扩 展身份标识的总数,Nm与第m个服务器的中央处理器的主频正相关,且与第m个服务器的内存容量正相关,ExtFunc为预设的函数,Ext_ServerIDm,n为第m个服务器的第n个扩展身份标识。
可选地,所述服务器连接装置还可以包括:
候选函数选取模块,用于从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数;
哈希运算模块,用于使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值;
第一序列构造模块,用于根据下式构造哈希值序列:
HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
Figure PCTCN2018093342-appb-000006
hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合;
第一均匀度计算模块,用于根据下式计算所述候选函数的均匀度:
Figure PCTCN2018093342-appb-000007
其中,HashMax为所述候选函数的最大函数值,EvenDeg为所述候选函数的均匀度;
候选函数删除模块,用于若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希函数集合中删除;
函数确定模块,用于若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
可选地,所述服务器连接装置还可以包括:
第二序列构造模块,用于根据下式构造各个哈希值序列:
HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
Figure PCTCN2018093342-appb-000008
其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
Figure PCTCN2018093342-appb-000009
hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合,hashv m,n∈HashValueSet m,且hashv m,n≤hashv m,n+1,HashValueSet m为由第m个服务器的哈希值组成的集合;
第二均匀度计算模块,用于根据下式计算所述候选函数的均匀度:
Figure PCTCN2018093342-appb-000010
其中,HashMax为所述候选函数的最大函数值,η为预设的比例系数,EvenDeg为所述候选函数的均匀度。
图7示出了本申请实施例提供的一种服务器连接终端设备的示意框图,为了便于说明,仅示出了与本申请实施例相关的部分。
在本实施例中,所述服务器连接终端设备7可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。该服务器连接终端设备7可包括:处理器70、存储器71以及存储在所述存储器71中并可在所述处理器70上运行的计算机可读指令72,例如执行上述的服务器连接方法的计算机可读指令。所述处理器70执行所述计算机可读指令72时实现上述各个服务器连接方法实施例中的步骤。
在本申请各个实施例中的各功能单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干计算机可读指令用以使得一台计算机设备执行本申请各个实施例所述方法的全部或部分步骤。

Claims (20)

  1. 一种服务器连接方法,其特征在于,包括:
    获取终端设备的身份标识;
    使用预设的第一哈希函数对所述身份标识进行哈希运算,得到所述终端设备的哈希值;
    将所述终端设备的哈希值映射至哈希环的第一节点,所述哈希环为由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的圆环,每个节点均为构成所述哈希环的一个函数值,所述第一节点为所述哈希环上的任意一个节点;
    获取所述哈希环上的各个基准节点,其中,每个基准节点均为所述哈希环上与一个服务器对应的节点;
    从所述第一节点开始顺时针或者逆时针查找所述基准节点,并将查找到的第一个基准节点所对应的服务器确定为优选服务器;
    建立所述终端设备与所述优选服务器之间的通信连接。
  2. 根据权利要求1所述的服务器连接方法,其特征在于,所述基准节点的设置过程包括:
    获取各个服务器的身份标识;
    使用预设的第二哈希函数分别对各个服务器的身份标识进行哈希运算,得到各个服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致;
    将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
  3. 根据权利要求1所述的服务器连接方法,其特征在于,所述基准节点的设置过程包括:
    获取各个服务器的身份标识;
    根据下式计算各个服务器的扩展身份标识:
    Ext_ServerIDm,n=ExtFunc(ServerIDm,n)
    其中,m为服务器的序号,1≤m≤M,M为服务器的总数,ServerIDm为第m个服务器的身份标识,n为扩展身份标识的序号,1≤n≤Nm,Nm为第m个服务器的扩展身份标识的总数,Nm与第m个服务器的中央处理器的主频正相关,且与第m个服务器的内存容量正相关,ExtFunc为预设的函数,Ext_ServerIDm,n为第m个服务器的第n个扩展身份标识;
    使用预设的第二哈希函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致;
    将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
  4. 根据权利要求3所述的服务器连接方法,其特征在于,所述第二哈希函数的设置过程包括:
    从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数;
    使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值;
    根据下式构造哈希值序列:
    HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
    其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
    Figure PCTCN2018093342-appb-100001
    hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合;
    根据下式计算所述候选函数的均匀度:
    Figure PCTCN2018093342-appb-100002
    其中,HashMax为所述候选函数的最大函数值,EvenDeg为所述候选函数的均匀度;
    若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希函数集合中删除,然后返回执行所述从预设的哈希函数集合中任意选取一个哈希函数作为候选函数的步骤;
    若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
  5. 根据权利要求3所述的服务器连接方法,其特征在于,所述第二哈希函数的设置过程包括:
    从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数;
    使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值;
    根据下式构造各个哈希值序列:
    HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
    Figure PCTCN2018093342-appb-100003
    其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
    Figure PCTCN2018093342-appb-100004
    hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合,hashv m,n∈HashValueSet m,且hashv m,n≤hashv m,n+1,HashValueSet m为由第m个服务器的哈希值组成的集合;
    根据下式计算所述候选函数的均匀度:
    Figure PCTCN2018093342-appb-100005
    其中,HashMax为所述候选函数的最大函数值,η为预设的比例系数,EvenDeg为所述候选函数的均匀度;
    若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希函数集合中删除,然后返回执行所述从预设的哈希函数集合中任意选取一个哈希函数作为候选函数的步骤;
    若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
  6. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机可读指令,其特征在于,所述计算机可读指令被处理器执行时实现如下步骤:
    获取终端设备的身份标识;
    使用预设的第一哈希函数对所述身份标识进行哈希运算,得到所述终端设备的哈希值;
    将所述终端设备的哈希值映射至哈希环的第一节点,所述哈希环为由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的圆环,每个节点均为构成所述哈希环的一个函数值,所述第一节点为所述哈希环上的任意一个节点;
    获取所述哈希环上的各个基准节点,其中,每个基准节点均为所述哈希环上与一个服务器对应的节点;
    从所述第一节点开始顺时针或者逆时针查找所述基准节点,并将查找到的第一个基准节点所对应的服务器确定为优选服务器;
    建立所述终端设备与所述优选服务器之间的通信连接。
  7. 根据权利要求6所述的计算机可读存储介质,其特征在于,所述基准节点的设置过程包括:
    获取各个服务器的身份标识;
    使用预设的第二哈希函数分别对各个服务器的身份标识进行哈希运算,得到各个服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致;
    将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
  8. 根据权利要求6所述的计算机可读存储介质,其特征在于,所述基准节点的设置过程包括:
    获取各个服务器的身份标识;
    根据下式计算各个服务器的扩展身份标识:
    Ext_ServerIDm,n=ExtFunc(ServerIDm,n)
    其中,m为服务器的序号,1≤m≤M,M为服务器的总数,ServerIDm为第m个服务器的身份标识,n为扩展身份标识的序号,1≤n≤Nm,Nm为第m个服务器的扩展身份标识的总数,Nm与第m个服务器的中央处理器的主频正相关,且与第m个服务器的内存容量正相关,ExtFunc为预设的函数,Ext_ServerIDm,n为第m个服务器的第n个扩展身份标识;
    使用预设的第二哈希函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致;
    将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
  9. 根据权利要求8所述的计算机可读存储介质,其特征在于,所述第二哈希函数的设置过程包括:
    从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数;
    使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值;
    根据下式构造哈希值序列:
    HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
    其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
    Figure PCTCN2018093342-appb-100006
    hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合;
    根据下式计算所述候选函数的均匀度:
    Figure PCTCN2018093342-appb-100007
    其中,HashMax为所述候选函数的最大函数值,EvenDeg为所述候选函数的均匀度;
    若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希函数集合中删除,然后返回执行所述从预设的哈希函数集合中任意选取一个哈希函数作为候选函数的步骤;
    若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
  10. 根据权利要求8所述的计算机可读存储介质,其特征在于,所述第二哈希函数的设置过程包括:
    从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数;
    使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值;
    根据下式构造各个哈希值序列:
    HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
    Figure PCTCN2018093342-appb-100008
    其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
    Figure PCTCN2018093342-appb-100009
    hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合,hashv m,n∈HashValueSet m,且hashv m,n≤hashv m,n+1,HashValueSet m为由第m个服务器的哈希值组成的集合;
    根据下式计算所述候选函数的均匀度:
    Figure PCTCN2018093342-appb-100010
    其中,HashMax为所述候选函数的最大函数值,η为预设的比例系数,EvenDeg为所述候选函数的均匀度;
    若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希函数集合中删除,然后返回执行所述从预设的哈希函数集合中任意选取一个哈希函数作为候选函数的步骤;
    若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
  11. 一种服务器连接终端设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,其特征在于,所述处理器执行所述计算机可读指令时实现如下步骤:
    获取终端设备的身份标识;
    使用预设的第一哈希函数对所述身份标识进行哈希运算,得到所述终端设备的哈希值;
    将所述终端设备的哈希值映射至哈希环的第一节点,所述哈希环为由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的圆环,每个节点均为构成所述哈希环的一个函数值,所述第一节点为所述哈希环上的任意一个节点;
    获取所述哈希环上的各个基准节点,其中,每个基准节点均为所述哈希环上与一个服务器对应的节点;
    从所述第一节点开始顺时针或者逆时针查找所述基准节点,并将查找到的第一个基准节点所对应的服务器确定为优选服务器;
    建立所述终端设备与所述优选服务器之间的通信连接。
  12. 根据权利要求11所述的服务器连接终端设备,其特征在于,所述基准节点的设置过程包括:
    获取各个服务器的身份标识;
    使用预设的第二哈希函数分别对各个服务器的身份标识进行哈希运算,得到各个 服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致;
    将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
  13. 根据权利要求12所述的服务器连接终端设备,其特征在于,所述基准节点的设置过程包括:
    获取各个服务器的身份标识;
    根据下式计算各个服务器的扩展身份标识:
    Ext_ServerIDm,n=ExtFunc(ServerIDm,n)
    其中,m为服务器的序号,1≤m≤M,M为服务器的总数,ServerIDm为第m个服务器的身份标识,n为扩展身份标识的序号,1≤n≤Nm,Nm为第m个服务器的扩展身份标识的总数,Nm与第m个服务器的中央处理器的主频正相关,且与第m个服务器的内存容量正相关,ExtFunc为预设的函数,Ext_ServerIDm,n为第m个服务器的第n个扩展身份标识;
    使用预设的第二哈希函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致;
    将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
  14. 根据权利要求13所述的服务器连接终端设备,其特征在于,所述第二哈希函数的设置过程包括:
    从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数;
    使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值;
    根据下式构造哈希值序列:
    HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
    其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
    Figure PCTCN2018093342-appb-100011
    hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合;
    根据下式计算所述候选函数的均匀度:
    Figure PCTCN2018093342-appb-100012
    其中,HashMax为所述候选函数的最大函数值,EvenDeg为所述候选函数的均匀度;
    若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希函数集合中删除,然后返回执行所述从预设的哈希函数集合中任意选取一个哈希函数作为候选函数的步骤;
    若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
  15. 根据权利要求13所述的服务器连接终端设备,其特征在于,所述第二哈希函数的设置过程包括:
    从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数;
    使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值;
    根据下式构造各个哈希值序列:
    HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
    Figure PCTCN2018093342-appb-100013
    其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
    Figure PCTCN2018093342-appb-100014
    hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合,hashv m,n∈HashValueSet m,且hashv m,n≤hashv m,n+1,HashValueSet m为由第m个服务器的哈希值组成的集合;
    根据下式计算所述候选函数的均匀度:
    Figure PCTCN2018093342-appb-100015
    其中,HashMax为所述候选函数的最大函数值,η为预设的比例系数,EvenDeg为所述候选函数的均匀度;
    若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希 函数集合中删除,然后返回执行所述从预设的哈希函数集合中任意选取一个哈希函数作为候选函数的步骤;
    若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
  16. 一种服务器连接装置,其特征在于,包括:
    终端标识获取模块,用于获取终端设备的身份标识;
    第一哈希运算模块,用于使用预设的第一哈希函数对所述身份标识进行哈希运算,得到所述终端设备的哈希值;
    第一映射模块,用于将所述终端设备的哈希值映射至哈希环的第一节点,所述哈希环为由所述第一哈希函数的所有函数值按照从小到大的顺序顺时针或者逆时针依次连接所构成的圆环,每个节点均为构成所述哈希环的一个函数值,所述第一节点为所述哈希环上的任意一个节点;
    基准节点获取模块,用于获取所述哈希环上的各个基准节点,其中,每个基准节点均为所述哈希环上与一个服务器对应的节点;
    优选服务器确定模块,用于从所述第一节点开始顺时针或者逆时针查找所述基准节点,并将查找到的第一个基准节点所对应的服务器确定为优选服务器;
    通信连接建立模块,用于建立所述终端设备与所述优选服务器之间的通信连接。
  17. 根据权利要求16所述的服务器连接装置,其特征在于,还包括:
    服务器标识获取模块,用于获取各个服务器的身份标识;
    第二哈希运算模块,用于使用预设的第二哈希函数分别对各个服务器的身份标识进行哈希运算,得到各个服务器的哈希值,所述第二哈希函数的值域与所述第一哈希函数的值域一致;
    第二映射模块,用于将各个服务器的哈希值映射至所述哈希环上,得到各个所述基准节点。
  18. 根据权利要求16所述的服务器连接装置,其特征在于,还包括:
    身份标识扩展模块,用于根据下式计算各个服务器的扩展身份标识:
    Ext_ServerIDm,n=ExtFunc(ServerIDm,n)
    其中,m为服务器的序号,1≤m≤M,M为服务器的总数,ServerIDm为第m个服务器的身份标识,n为扩展身份标识的序号,1≤n≤Nm,Nm为第m个服务器的扩展身份标识的总数,Nm与第m个服务器的中央处理器的主频正相关,且与第m个服务器的内存容量正相关,ExtFunc为预设的函数,Ext_ServerIDm,n为第m个服务器的第n个扩展身份标识。
  19. 根据权利要求18所述的服务器连接装置,其特征在于,还包括:
    候选函数选取模块,用于从预设的哈希函数集合中任意选取一个哈希函数作为候选函数,所述哈希函数集合包括一个以上的哈希函数;
    哈希运算模块,用于使用所述候选函数分别对各个服务器的扩展身份标识进行哈希运算,得到各个服务器的哈希值;
    第一序列构造模块,用于根据下式构造哈希值序列:
    HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
    其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
    Figure PCTCN2018093342-appb-100016
    hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合;
    第一均匀度计算模块,用于根据下式计算所述候选函数的均匀度:
    Figure PCTCN2018093342-appb-100017
    其中,HashMax为所述候选函数的最大函数值,EvenDeg为所述候选函数的均匀度;
    候选函数删除模块,用于若所述候选函数的均匀度大于预设的均匀度阈值,则将所述候选函数从所述哈希函数集合中删除;
    函数确定模块,用于若所述候选函数的均匀度小于或等于预设的均匀度阈值,则将所述候选函数确定为第二哈希函数。
  20. 根据权利要求18所述的服务器连接装置,其特征在于,还包括:
    第二序列构造模块,用于根据下式构造各个哈希值序列:
    HashArrayT=(hashvt 1,hashvt 2,......,hashvt tn,......,hashvt TN)
    Figure PCTCN2018093342-appb-100018
    其中,1≤tn≤TN,TN为各个服务器的哈希值的总数,且
    Figure PCTCN2018093342-appb-100019
    hashvt tn∈HashValueSetT,且hashvt tn≤hashvt tn+1,HashValueSetT为由各个服务器的哈希值组成的集合,hashv m,n∈HashValueSet m,且hashv m,n≤hashv m,n+1,HashValueSet m为由第 m个服务器的哈希值组成的集合;
    第二均匀度计算模块,用于根据下式计算所述候选函数的均匀度:
    Figure PCTCN2018093342-appb-100020
    其中,HashMax为所述候选函数的最大函数值,η为预设的比例系数,EvenDeg为所述候选函数的均匀度。
PCT/CN2018/093342 2018-04-17 2018-06-28 服务器连接方法、计算机可读存储介质、终端设备及装置 Ceased WO2019200714A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810341964.0 2018-04-17
CN201810341964.0A CN108769111B (zh) 2018-04-17 2018-04-17 一种服务器连接方法、计算机可读存储介质及终端设备

Publications (1)

Publication Number Publication Date
WO2019200714A1 true WO2019200714A1 (zh) 2019-10-24

Family

ID=64010645

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/093342 Ceased WO2019200714A1 (zh) 2018-04-17 2018-06-28 服务器连接方法、计算机可读存储介质、终端设备及装置

Country Status (2)

Country Link
CN (1) CN108769111B (zh)
WO (1) WO2019200714A1 (zh)

Cited By (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111339088A (zh) * 2020-02-21 2020-06-26 苏宁云计算有限公司 数据库的分库分表方法、装置、介质及计算机设备
CN111580965A (zh) * 2020-04-30 2020-08-25 深圳壹账通智能科技有限公司 数据请求的处理方法及系统
CN111580948A (zh) * 2020-04-30 2020-08-25 中国平安财产保险股份有限公司 任务调度方法、装置及计算机设备
CN111614760A (zh) * 2020-05-20 2020-09-01 浩云科技股份有限公司 一种将物联网设备均衡分配接入的方法及装置
CN112486672A (zh) * 2020-11-17 2021-03-12 中国人寿保险股份有限公司 一种服务内存缓存调用方法和装置
CN112799978A (zh) * 2021-01-20 2021-05-14 网易(杭州)网络有限公司 缓存设计管理方法、装置、设备和计算机可读存储介质
CN112953981A (zh) * 2019-11-26 2021-06-11 北京沃东天骏信息技术有限公司 节点选择方法、区块链共识方法及装置、系统、设备
CN112948120A (zh) * 2021-03-18 2021-06-11 广东好太太智能家居有限公司 负载均衡方法、系统、装置和存储介质
CN113064720A (zh) * 2021-03-12 2021-07-02 北京达佳互联信息技术有限公司 对象分配方法、装置、服务器及存储介质
CN113542013A (zh) * 2021-06-24 2021-10-22 新华三大数据技术有限公司 虚拟化网络功能管理消息分配方法、装置及设备
CN114296869A (zh) * 2021-12-20 2022-04-08 云控智行科技有限公司 一种基于tcp长连接的服务器节点服役方法及装置
CN114385746A (zh) * 2020-10-21 2022-04-22 中国移动通信集团设计院有限公司 基于区块链技术的数据存储方法及装置
CN114446407A (zh) * 2022-03-03 2022-05-06 冰洲石生物科技(上海)有限公司 化学反应的反应模板提取方法、系统、介质及电子设备
CN114785795A (zh) * 2022-04-02 2022-07-22 北京蓝海在线科技有限公司 分布式存储方法、系统、设备、存储介质及信息处理终端
CN114866799A (zh) * 2022-05-11 2022-08-05 北京奇艺世纪科技有限公司 一种服务器调度方法及装置
CN115001969A (zh) * 2022-05-24 2022-09-02 中欣链证数字科技有限公司 一种数据存储节点部署方法、数据存储方法、装置及设备
CN115113997A (zh) * 2022-06-17 2022-09-27 云知声智能科技股份有限公司 一种任务调度方法、装置、电子设备及存储介质
CN115827197A (zh) * 2022-11-25 2023-03-21 北京百度网讯科技有限公司 分布式任务的调度方法、装置、系统及电子设备
CN117130793A (zh) * 2023-10-27 2023-11-28 乾健科技有限公司 一种大数据分析处理方法以及系统
CN120729812A (zh) * 2025-06-17 2025-09-30 深圳羽衡科技有限公司 一种系统消息队列处理方法、系统、计算机设备及介质

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109739433A (zh) * 2018-11-27 2019-05-10 中科恒运股份有限公司 数据处理的方法及终端设备
CN110083313B (zh) * 2019-05-06 2022-08-02 北京奇艺世纪科技有限公司 一种数据缓存方法及装置
CN110457128B (zh) * 2019-07-11 2023-12-22 创新先进技术有限公司 任务分配方法、装置和系统
CN111182043B (zh) * 2019-12-23 2022-08-12 南京亚信智网科技有限公司 哈希值的分配方法及装置
CN111314189B (zh) * 2020-01-17 2022-02-25 蚂蚁财富(上海)金融信息服务有限公司 一种业务消息的发送方法及装置
CN112650451B (zh) * 2020-12-28 2023-06-09 杭州趣链科技有限公司 查找网络服务器的优化方法、装置、计算机设备及存储介质
CN112667620B (zh) * 2020-12-31 2024-12-20 广州方硅信息技术有限公司 数据处理方法、装置、计算机设备及存储介质
CN116028196B (zh) * 2021-10-25 2025-11-21 腾讯科技(深圳)有限公司 数据处理方法、装置及存储介质
CN114373541A (zh) * 2022-01-14 2022-04-19 平安科技(深圳)有限公司 基于分布式的智能中医诊断方法、系统及存储介质

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8996607B1 (en) * 2010-06-04 2015-03-31 Amazon Technologies, Inc. Identity-based casting of network addresses
CN106972977A (zh) * 2017-05-24 2017-07-21 北京潘达互娱科技有限公司 一种长连接维护方法与装置
CN107171971A (zh) * 2017-05-11 2017-09-15 北京云端智度科技有限公司 利用一致性哈希策略实现网络流量负载均衡的方法
CN107317879A (zh) * 2017-08-02 2017-11-03 网宿科技股份有限公司 一种用户请求的分发方法及系统
CN107395767A (zh) * 2017-08-31 2017-11-24 北京奇虎科技有限公司 基于长连接的消息推送系统及方法
CN107797865A (zh) * 2017-10-20 2018-03-13 华为软件技术有限公司 用户任务处理方法及应用服务器

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100640057B1 (ko) * 2004-11-12 2006-11-01 삼성전자주식회사 브로드캐스트 암호화를 위한 사용자 키 관리 방법
US7821925B2 (en) * 2007-01-29 2010-10-26 Fulcrum Microsystems, Inc. Traffic distribution techniques utilizing initial and scrambled hash values
CN101494611B (zh) * 2009-02-20 2011-09-14 华为技术有限公司 一种负载分担调整方法和装置
CN103888499B (zh) * 2012-12-21 2018-08-14 中国科学院深圳先进技术研究院 一种分布式对象处理的方法及系统
CN104852934A (zh) * 2014-02-13 2015-08-19 阿里巴巴集团控股有限公司 基于前端调度实现流量分配的方法、装置和系统
CN106559448A (zh) * 2015-09-28 2017-04-05 北京国双科技有限公司 服务器负载均衡方法和装置
CN106789175A (zh) * 2016-11-30 2017-05-31 武汉长江通信智联技术有限公司 一种基于一致性哈希算法进行redis横向扩展的方法
CN106850581B (zh) * 2017-01-04 2020-06-23 网宿科技股份有限公司 互动直播流媒体数据的分发备份方法、系统及服务器
CN107070989A (zh) * 2017-03-06 2017-08-18 北京潘达互娱科技有限公司 通信方法和系统
CN107749887A (zh) * 2017-10-25 2018-03-02 暴风集团股份有限公司 一种cdn资源分配、定位方法和装置及cdn系统

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8996607B1 (en) * 2010-06-04 2015-03-31 Amazon Technologies, Inc. Identity-based casting of network addresses
CN107171971A (zh) * 2017-05-11 2017-09-15 北京云端智度科技有限公司 利用一致性哈希策略实现网络流量负载均衡的方法
CN106972977A (zh) * 2017-05-24 2017-07-21 北京潘达互娱科技有限公司 一种长连接维护方法与装置
CN107317879A (zh) * 2017-08-02 2017-11-03 网宿科技股份有限公司 一种用户请求的分发方法及系统
CN107395767A (zh) * 2017-08-31 2017-11-24 北京奇虎科技有限公司 基于长连接的消息推送系统及方法
CN107797865A (zh) * 2017-10-20 2018-03-13 华为软件技术有限公司 用户任务处理方法及应用服务器

Cited By (22)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112953981A (zh) * 2019-11-26 2021-06-11 北京沃东天骏信息技术有限公司 节点选择方法、区块链共识方法及装置、系统、设备
CN111339088A (zh) * 2020-02-21 2020-06-26 苏宁云计算有限公司 数据库的分库分表方法、装置、介质及计算机设备
CN111580965A (zh) * 2020-04-30 2020-08-25 深圳壹账通智能科技有限公司 数据请求的处理方法及系统
CN111580948A (zh) * 2020-04-30 2020-08-25 中国平安财产保险股份有限公司 任务调度方法、装置及计算机设备
CN111614760A (zh) * 2020-05-20 2020-09-01 浩云科技股份有限公司 一种将物联网设备均衡分配接入的方法及装置
CN114385746A (zh) * 2020-10-21 2022-04-22 中国移动通信集团设计院有限公司 基于区块链技术的数据存储方法及装置
CN112486672A (zh) * 2020-11-17 2021-03-12 中国人寿保险股份有限公司 一种服务内存缓存调用方法和装置
CN112799978A (zh) * 2021-01-20 2021-05-14 网易(杭州)网络有限公司 缓存设计管理方法、装置、设备和计算机可读存储介质
CN113064720B (zh) * 2021-03-12 2024-04-16 北京达佳互联信息技术有限公司 对象分配方法、装置、服务器及存储介质
CN113064720A (zh) * 2021-03-12 2021-07-02 北京达佳互联信息技术有限公司 对象分配方法、装置、服务器及存储介质
CN112948120A (zh) * 2021-03-18 2021-06-11 广东好太太智能家居有限公司 负载均衡方法、系统、装置和存储介质
CN113542013A (zh) * 2021-06-24 2021-10-22 新华三大数据技术有限公司 虚拟化网络功能管理消息分配方法、装置及设备
CN114296869A (zh) * 2021-12-20 2022-04-08 云控智行科技有限公司 一种基于tcp长连接的服务器节点服役方法及装置
CN114446407A (zh) * 2022-03-03 2022-05-06 冰洲石生物科技(上海)有限公司 化学反应的反应模板提取方法、系统、介质及电子设备
CN114785795A (zh) * 2022-04-02 2022-07-22 北京蓝海在线科技有限公司 分布式存储方法、系统、设备、存储介质及信息处理终端
CN114866799A (zh) * 2022-05-11 2022-08-05 北京奇艺世纪科技有限公司 一种服务器调度方法及装置
CN114866799B (zh) * 2022-05-11 2024-04-05 北京奇艺世纪科技有限公司 一种服务器调度方法及装置
CN115001969A (zh) * 2022-05-24 2022-09-02 中欣链证数字科技有限公司 一种数据存储节点部署方法、数据存储方法、装置及设备
CN115113997A (zh) * 2022-06-17 2022-09-27 云知声智能科技股份有限公司 一种任务调度方法、装置、电子设备及存储介质
CN115827197A (zh) * 2022-11-25 2023-03-21 北京百度网讯科技有限公司 分布式任务的调度方法、装置、系统及电子设备
CN117130793A (zh) * 2023-10-27 2023-11-28 乾健科技有限公司 一种大数据分析处理方法以及系统
CN120729812A (zh) * 2025-06-17 2025-09-30 深圳羽衡科技有限公司 一种系统消息队列处理方法、系统、计算机设备及介质

Also Published As

Publication number Publication date
CN108769111B (zh) 2020-01-24
CN108769111A (zh) 2018-11-06

Similar Documents

Publication Publication Date Title
WO2019200714A1 (zh) 服务器连接方法、计算机可读存储介质、终端设备及装置
CN107092667B (zh) 基于社交网络的群组查找方法和装置
US9104676B2 (en) Hash algorithm-based data storage method and system
CN110737663B (zh) 一种数据存储方法、装置、设备及存储介质
US10320937B2 (en) Community notification based on profile update
CN110168523A (zh) 改变监测跨图查询
JP2019504412A (ja) ショートリンクの処理方法、デバイス、及びサーバ
CN103380421A (zh) 用于图形数据的分布式缓存
CN104995870A (zh) 多目标服务器布局确定
CN104052651B (zh) 一种建立社交组的方法和装置
CN113282941A (zh) 获取对象标识的方法、装置、电子设备及存储介质
WO2020024446A1 (zh) 数据的存储方法及装置、存储介质、计算机设备
CN119071942A (zh) 会话关联方法、装置、计算机设备、可读存储介质和程序产品
CN114827159B (zh) 网络请求路径优化方法、装置、设备和存储介质
CN114756714B (zh) 一种图数据的处理方法、装置以及存储介质
CN104539538B (zh) 路由器的ip地址匹配方法和路由器的数据包转发方法
CN103414756B (zh) 一种任务分发方法、分发节点及系统
CN108241685A (zh) 数据查询的方法和查询客户端
CN104978327B (zh) 一种查询数据的方法、管理控制节点及目标数据节点
CN112817980A (zh) 一种数据索引处理方法、装置、设备及存储介质
CN105447141A (zh) 一种数据处理的方法及节点
CN108768735B (zh) 一种测试床拓扑结构的二分图采样方法及装置
CN118606357A (zh) 基于双层Raft一致性协议的云边协同分布式存储方法和装置
CN115567289B (zh) 加密dns协议下基于联邦图模型的恶意域名检测方法及系统
US12028240B2 (en) Method, electronic device, and computer program product for cross-regional data searching

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18915542

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 22.01.2021)

122 Ep: pct application non-entry in european phase

Ref document number: 18915542

Country of ref document: EP

Kind code of ref document: A1