Application of zookeeper in load balancing of cluster

Source: Internet
Author: User

Zookeeper itself is not to provide load balancing strategy, need to implement themselves, so here is exactly, in the load balancer applied to the zookeeper to do the coordination of the cluster.

For load balancing of HTTP requests, the mature solution is nginx (or haproxy) +keepalived. Where Niginx is responsible for proxy HTTP requests, through some kind of equalization policy to access the server in the cluster, keepalived is responsible for detecting the server operation in the cluster (the faulty machine is removed, the machine resumes work and re-joins)

For TCP layer load balancing, such as the use of Apache Mina network communication applications, the above scenario is obviously not suitable, because the network communication client and server to maintain a long connection

So to do load balancing for this kind of long connection, is generally based on the number of connections this equalization strategy, that is, when the first connection, the allocation of server IP, take the least number of current connections

Several servers in the cluster are running, the number of clients currently connected to each server, the maximum number of connections, and so on, which need to be recorded, and then allocated on the basis of this information each time the load is balanced, the first thought is to store this information in the database.

The simple practice is that when the server starts, the corresponding state in the database is changed to run, and when the client connects or disconnects, the number of connections is Addend or meiosis.

When the server shuts down, the problem is:

1, the server shut down, may be the data source has been shut down, unable to operate the database, the machine in the database has been running state

2, the server down, this problem is very deadly, this is even closed programs are not executed, let alone to operate the database

The solution is to use zookeeper to save the server's connection information

1. When the server is started, write data to Zookeeper node (node type is temporary node)

2. When the server shuts down, remove the corresponding node data from zookeeper

3, when the server down, zookeeper because no heartbeat detected, automatically remove the node, and notify other servers, other servers know that the machine has been down, in the allocation of connections, will not be assigned to this machine, this is the title said in the load balancer used to zookeeper reasons.

Compared to the way it was saved in the database, zookeeper is actually a database with a notification function, that is, when the node data changes, it notifies all of its clients (the client here refers to the server connected to zookeeper).

Application of zookeeper in load balancing of cluster

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.