Understanding the principle of UDP load balancer (by quqi99)

Source: Internet
Author: User

Zhang Hua posted: 2015-11-13
Copyright notice: Can be reproduced arbitrarily, please be sure to use hyperlinks in the form of the original source of the article and the author's information and this copyright notice
(http://blog.csdn.net/quqi99)

    • Four-tier load balancing is to determine which traffic needs to be load balanced by publishing a three-tier IP address (VIP), and then add a four-tier port number, to handle the traffic that needs to be processed, to forward to the backend server, and to record which server the TCP or UDP traffic is handled by, All subsequent traffic for this connection is also forwarded to the same server for processing. So the four-tier load balancer is more like a NAT router .
    • Seven-tier load balancing, on the basis of the four layer, and then consider the characteristics of the application layer, than like a Web server load balancing, in addition to the VIP plus 80 port to identify whether the traffic needs to be processed, but also according to the seven layer URL, browser category, language to determine whether to load balance. Load balancing if you want to really understand the content of the seven-tier application layer, you can only proxy the final server and the client to establish three handshake connections, it is possible to accept the client sends the real application layer content of the message, so the seven-tier load balancer is more like a proxy server .
As TCP becomes more and more complex, many applications, such as the DTLS Protocol (the UDP version of SSL) and OpenVPN, are from the row control complex system over UDP, such as self-processing connection states, data sequences, and so on. But UDP is usually come a request service is over, it can do you like TCP to maintain a connection pools use multi-CPU processing power?

A socket consists of a related five-tuple (protocol, local address, local port, remote address, remote port) that cannot destroy the uniqueness of the five-tuple.
    • SO_REUSEADDR only indicates that the client socket can reuse the local address, the local port, the entire related five-tuple or the only certainty. There is no way to determine whether a five-tuple is unique in the case of a UDP no-connection state through the "existing five-tuple connection that saves a new connection match." So it is simply based on the target IP and the target port to find the UDP socket list structure, find the first one to return. SO_REUSEADDR just reuses the local IP and port , so you can bind the same remote IP to the port's UDP connection in one process or multiple threads, but only the last (or other fixed location, depending on the algorithm) the UDP connection can receive the data.
    • So_reuseport, so, starting from the Linux3.9 kernel has so_reuseport this socket option, which supports multiple client sockets (multiple processes or threads) bound to the same port , This allows each thread to have its own server socket, which in turn does not compete for a lock on the server's nested word to improve performance. its algorithm in the search for UDP socket list structure, not only use the target IP and port, also use the source IP and port, so you will find multiple, and finally through the hash select one, so that the kernel level of load balancing . This creates multiple UDP sockets on the server and binds the same IP and port, and the client sockets for different source IPs and ports automatically load to different server sockets. In this way, if you want to take advantage of multi-CPU, you can pre-create multiple processes, each of which allocates a UDP socket to handle the sending and receiving of the data (the code implementation can pre-fork multiple processes in the main process, and each process only handles one UDP socket). If a UDP socket is dead, it will change the location of the socket list, so the method is to use the Cloexec parameter to ensure that UDP is not closed.
Haproxy currently does not support the UDP method above to start a UDP socket on each process to load balance the client. Corosync supports heartbeat checking between nodes using the Udpu method, but only if the host list is configured.


Reference:
1, http://kb.cnblogs.com/page/188170/
2, http://blog.csdn.net/dog250/article/details/17061277

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Understanding the principle of UDP load balancer (by quqi99)

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.