Support soft load-balancing method and the system of the connection of magnanimity length
Technical field
The invention belongs to Internet software arts, particularly to a kind of soft load-balancing method supporting magnanimity length to connect and
System.
Background technology
For internet, applications, business development the most flourishing, then any active ues using business is the most, and server
The pressure born is the biggest.Even if when load pressure reach single server upgrading hardware also can not meet loading demand time
Waiting, load-balancing technique just arises at the historic moment.Load-balancing technique is that a kind of Internet service disposes conventional technology, and it is many
Station server forms a server set in a symmetrical manner, and every station server all has the status of equivalence, can be independent
Service is externally provided and without the auxiliary of other servers.By load-balancing technique, the access pressure of user is divided equally many
On station server, for arbitrary single server, the 1/N (N of the load pressure in the load pressure born simply set
For server number of units).Like this, the continuation development of business also can be supported smoothly.
Conventional load-balancing technique is to use load equalizer hardware (such as F5) or use soft load balancing work
Tool (such as Nginx, HAProxy) realizes.For the former, it is necessary to buying load equalizer hardware and the relevant network equipment,
Unified plan, the implementation cost of scheme is higher.And for the latter, in order to ensure the high availability of operation system, it will usually dispose
Two and above special server (such as Nginx server) undertake the function of load balancing, although this scheme is implemented
The former is lower in one-tenth this locality, the most economical, and performance also has bottleneck, in order to improving performance is necessary for adding more bearing
Carry equalization server node, it means that cost is higher.
Summary of the invention
[solving the technical problem that]
It is an object of the invention to provide a kind of soft load-balancing method supporting magnanimity length to connect and system, at least to solve
One of above technical problem.
[technical scheme]
The present invention is achieved by the following technical solutions.
Present invention firstly relates to a kind of soft SiteServer LBS supporting magnanimity length to connect, including client, service end body
Part Verification System, Erlang cluster.
Described client is configured to: use authority to initiate certification HTTP request to service end identity authorization system;Receive
After the public network IP address information of token Token and server node, token is used to initiate to the node that public network IP address is corresponding
Setting up the long request connected, this node verification token, if token is legal, then the length that node is made an appointment according to both sides connects association
Discuss and set up long connection with client.
Described service end identity authorization system is configured to: after receiving the certification HTTP request that client sends, checking
Authority, if authority is legal, is then generated a token Token and by HTTP request, token Token is sent to Erlang collection
Group, if authority is illegal, then the information that return authentication is failed;Wait the response message of Erlang cluster, when receiving
After the response message of Erlang, then the HTTP request of customer in response end, token Token and the long minimum server of number that connects are saved
The public network IP address of point sends to client.
Described Erlang cluster is configured to: the request of response service end identity authorization system, and according to the load of cluster
The long public network IP address connecting the minimum server node of number is returned to service end identity authorization system by situation.
As one preferred embodiment, described authority is facility information and/or user profile.
As another preferred embodiment, described facility information is equipment SN, equipment Mac address, equipment two dimension
One or more in code or equipment string number, described user profile is in user account name, account password, mailbox or cell-phone number
One or more.
As another preferred embodiment, described Erlang cluster includes Real-time and Dynamic table, described Real-time and Dynamic table
At least include Erlang service node name and port, client ip address and port, client identification information, set up long connection
Initial time, described Real-time and Dynamic table obtains real-time update and by all nodes sharing in whole Erlang cluster.
As another preferred embodiment, described long connection protocol is MQTT agreement, XMPP, WebSocket
Agreement, AMQP agreement, STOMP agreement, OpenWire agreement, JMS agreement or NMS agreement.
The invention still further relates to a kind of soft load-balancing method supporting magnanimity length to connect, comprise the following steps:
A, client use authority to initiate certification HTTP request to service end identity authorization system;
B, service end identity authorization system checking authority, if authority is legal, then generates a token Token and passes through
HTTP request sends token Token to Erlang cluster;If authority is illegal, then the information that return authentication is failed;
The request of C, Erlang cluster response service end identity authorization system, and according to the loading condition of cluster, length is connected
The public network IP address of the server node that number is minimum returns to service end identity authorization system;
D, the HTTP request of service end identity authorization system customer in response end, by minimum to token Token and long connection number
The public network IP address of server node sends to client;
After E, client receive the public network IP address information of token Token and server node, use token to public network
The node long request connected of initiation foundation that IP address is corresponding, this node verification token, if token is legal, then node is according to double
The long connection protocol that side makes an appointment is set up long connection with client.
As one preferred embodiment, described authority is facility information and/or user profile.
As another preferred embodiment, described facility information is equipment SN, equipment Mac address, equipment two dimension
One or more in code or equipment string number, described user profile is in user account name, account password, mailbox or cell-phone number
One or more.
As another preferred embodiment, the connection of the load of described Erlang cluster passes through Erlang cluster
Real-time and Dynamic table obtain, described Real-time and Dynamic table at least include Erlang service node name and port, client ip address and
Port, client identification information, set up the long initial time connected, described Real-time and Dynamic table real-time update and at whole Erlang
By all nodes sharing in cluster.
As another preferred embodiment, the long connection protocol in described step E be MQTT agreement, XMPP,
WebSocket agreement, AMQP agreement, STOMP agreement, OpenWire agreement, JMS agreement or NMS agreement.
[beneficial effect]
The technical scheme that the present invention proposes has the advantages that
The present invention, without using load equalizer and soft load-balanced server, therefore reduces the hardware cost of system,
Reduce the complexity of whole system, improve the reliability of whole system;And, the length in the present invention is connected to Erlang collection
Being uniformly distributed between group node, system can carry out extending transversely easily, therefore can realize magnanimity easily long
Connect.
Accompanying drawing explanation
The theory diagram of the soft SiteServer LBS that the support magnanimity length that Fig. 1 provides for embodiments of the invention one connects.
Detailed description of the invention
For making the object, technical solutions and advantages of the present invention clearer, below by the detailed description of the invention to the present invention
Carry out clear, complete description.
Embodiment one
The theory diagram of the soft SiteServer LBS that the support magnanimity length that Fig. 1 provides for the embodiment of the present invention one connects.As
Shown in Fig. 1, this system includes client 1, service end identity authorization system 2, Erlang cluster 3.
Client 1 is configured to: use authority to initiate certification HTTP request to service end identity authorization system 2;Receive
After the public network IP address information of token Token and server node, token is used to initiate to build to the node that public network IP address is corresponding
The vertical long request connected, this node verification token, if token is legal, then the long connection protocol that node is made an appointment according to both sides
Set up long connection with client.Wherein, authority is facility information and/or user profile, and facility information is equipment SN, equipment
One or more in Mac address, equipment Quick Response Code or equipment string number, user profile is user account name, account password, mailbox
Or one or more in cell-phone number.It addition, long connection protocol is MQTT agreement, XMPP, WebSocket agreement, AMQP
Agreement, STOMP agreement, OpenWire agreement, JMS agreement or NMS agreement.It addition, token Token be identity authorization system according to
Access information and authority, make a string random character string data being generated algorithmically by.Erlang cluster refers to use Erlang programming
The cluster of the server of the long Connection Service of support of language development, the application of Erlang language development or service, natural just support
Cluster, this is that the essence of Erlang language is determined.The cluster of Erlang Shi Quan UNICOM in default situations, namely when
The when that one node adding cluster, sponsor's (node) can recommend the joint that inside cluster, all of node actively comes and is newly added
Point sets up contact.Specifically, in the present embodiment, Erlang cluster includes that Real-time and Dynamic table, Real-time and Dynamic table include that Erlang takes
Business node name and port, client ip address and port, client identification information, the long initial time connected of foundation, move in real time
State table real-time update and in whole Erlang cluster by all nodes sharing.
Service end identity authorization system 2 is configured to: receive client 1 send certification HTTP request after, verify with
According to, if authority is legal, then generates a token Token and by HTTP request, token Token sent to Erlang cluster
3, if authority is illegal, then the information that return authentication is failed;The HTTP request of customer in response end, connects token Token and length
The public network IP address connecing several minimum server node sends to client 1.
Erlang cluster 3 is configured to: the request of response service end identity authorization system 2, and according to the load feelings of cluster
The long public network IP address connecting the minimum server node of number is returned to service end identity authorization system 2 by condition.
The soft load-balancing method that the support magnanimity length using the system in embodiment one to realize connects is referred to following
Concrete grammar embodiment.
Embodiment two
Embodiment two is a kind of soft load-balancing method supporting magnanimity length to connect, and this comprises the following steps:
(1), client uses authority to initiate certification HTTP request to service end identity authorization system.
(2), service end identity authorization system checking authority, if authority is legal, then generate a token Token passing through
HTTP request sends token Token to Erlang cluster;If authority is illegal, then the information that return authentication is failed.It addition,
Authority in this step is facility information and/or user profile, and facility information is equipment SN, equipment Mac address, equipment two dimension
One or more in code or equipment string number, user profile is the one in user account name, account password, mailbox or cell-phone number
Or it is multiple.It addition, token Token is identity authorization system according to access information and authority, make to be generated algorithmically by a string at random
String data.Erlang cluster refers to use the collection of the server of the long Connection Service of support of Erlang programming language exploitation
Group, the application of Erlang language development or service, natural just support cluster, this is that the essence of Erlang language is determined.
The cluster of Erlang Shi Quan UNICOM in default situations, namely when a node adds cluster when, sponsor's (joint
Point) node that is the most next and that be newly added of all of node inside cluster can be recommended to set up contact.Specifically, in the present embodiment,
Erlang cluster include Real-time and Dynamic table, Real-time and Dynamic table include Erlang service node name and port, client ip address and
Port, client identification information, set up the long initial time connected, Real-time and Dynamic table real-time update and at whole Erlang cluster
Middle can be had access to the information of Real-time and Dynamic table by all nodes sharing, i.e. each Erlang node..
(3), the request of Erlang cluster response service end identity authorization system, and according to the loading condition of cluster by length company
The public network IP address connecing several minimum server node returns to service end identity authorization system.
(4), the HTTP request of service end identity authorization system customer in response end, by token Token with long to connect number minimum
Server node public network IP address send to client.Step (1) and step (2) combine one complete
HTTP request and the process of response.It is to be appreciated that the type of request can be synchronization request, it is also possible to be Asynchronous Request, if
For Asynchronous Request, the response of Xiang Zeying is asynchronous response.
(5), after client receives the public network IP address information of token Token and server node, use token to public affairs
Node corresponding to net IP address initiates to set up the long request connected, this node verification token, if token is legal, then node according to
The long connection protocol that both sides make an appointment is set up long connection with client.Wherein, authority is facility information and/or user profile,
Facility information is one or more in equipment SN, equipment Mac address, equipment Quick Response Code or equipment string number, and user profile is
One or more in user account name, account password, mailbox or cell-phone number.It addition, long connection refers in a TCP connection
Multiple packet can be continuously transmitted, during TCP connects holding, send without packet, need both sides to send out detection bag
To maintain this to connect, long connection protocol be MQTT agreement, XMPP, WebSocket agreement, AMQP agreement, STOMP agreement,
OpenWire agreement, JMS agreement or NMS agreement.
As can be seen from the above embodiments, the embodiment of the present invention is without using load equalizer (such as F5) and soft load equal
Weighing apparatus server (such as Nginx server, HAProxy server etc.), therefore reduces the hardware cost of system, reduces whole
The complexity of system, improves the reliability of whole system;And, the length in the present invention is connected between Erlang clustered node
To being uniformly distributed, therefore system can carry out extending transversely easily, can realize magnanimity length further easily and connect.
It is to be appreciated that the embodiment of foregoing description is a part of embodiment of the present invention rather than whole embodiment, the most not
It it is limitation of the present invention.Based on embodiments of the invention, those of ordinary skill in the art are not paying creative work premise
Lower obtained every other embodiment, broadly falls into protection scope of the present invention.