Home Backend Development PHP Tutorial Using Network Address Translation to Implement Multi-Server Load Balancing_PHP Tutorial

Using Network Address Translation to Implement Multi-Server Load Balancing_PHP Tutorial

Jul 21, 2016 pm 04:03 PM
use distributed address accomplish Discuss Summary server use network load Convert

Abstract: This article discusses the load balancing technology and load distribution strategy used by distributed network servers, and implements a load balancing gateway on FreeBSD based on network address translation, which is applied to our Internet network server to distribute the load to multiple servers. Sharing to solve the high load problem of CPU or I/O caused by a large number of concurrent accesses faced by Internet servers. In order to achieve the best load balancing effect, the load controller needs to allocate load according to the current CPU and I/O status of each server. This requires dynamically monitoring the load of the server and applying optimized load distribution strategies to achieve even load distribution. Purpose.

Keywords: Load balancing, network address translation, FreeBSD


1. Introduction

The rapid growth of the Internet has caused a rapid increase in the number of visits faced by multimedia network servers , the server needs to have the ability to provide a large number of concurrent access services, and the server's processing and I/O capabilities have become the bottleneck in providing services. Since the performance of a single server is always limited, multi-server and load balancing technology must be used to meet the needs of a large number of concurrent accesses.

The earliest load balancing technology is implemented through DNS. The same name is configured for multiple addresses in DNS, so the client querying this name will get one of the addresses, thus allowing different customers to access different servers to achieve load balancing [1]. DNS load balancing is a simple and effective method, but it cannot distinguish the differences between servers, nor can it reflect the current operating status of the server.

The reverse proxy server can forward requests to internal web servers. If the proxy server can forward requests evenly to multiple internal servers, load balancing can be achieved [2]. In the reverse proxy mode, an optimized load balancing strategy can be applied, and the most idle internal server is accessed each time to provide services. However, as the number of concurrent connections increases, the load on the proxy server itself becomes very large, and eventually the reverse proxy server itself will become a bottleneck of the service.

An address translation gateway that supports load balancing can map an external IP address to multiple internal IP addresses, and dynamically use one of the internal addresses for each TCP connection request to achieve load balancing [3]. Many hardware manufacturers integrate this technology into their switches as a function of their fourth layer switching. They generally use a load balancing strategy of random selection and selection based on the number of server connections or response time to distribute the load. However, the load controller implemented by hardware is not very flexible and cannot support more optimized load balancing strategies and more complex application protocols.

In addition to these three load balancing methods, some protocols internally support load balancing-related functions, such as redirection capabilities in the HTTP protocol, etc., but it depends on the specific protocol and therefore has a limited scope of use. Based on these existing load balancing technologies, we chose to use software to implement network address translation load balancing to make up for the inflexibility of the hardware load balancer, and applied optimized balancing strategies to achieve the best load sharing of back-end servers. Excellent status.


2. Load balancing strategy

In order to evenly distribute the load to multiple internal servers, a certain load balancing strategy needs to be applied. Traditional load balancing strategies do not take into account the different types of service requests, the different capabilities of the backend servers, and the uneven load distribution caused by random selection. In order to make the load distribution very even, it is necessary to apply a load balancing strategy that can correctly reflect the CPU and I/O status of each server [4].

There are various types of service requests initiated by customers. According to the resource requirements for processor, network and I/O, they can be simply divided into two different categories in order to apply different processing strategies. :



Static document request: such as ordinary text, images and other static multimedia data, which have little impact on the processor load, and the resulting disk I/O load is proportional to the size of the document. Proportional, mainly putting pressure on network I/O.


Dynamic document requests: More common requests often require pre-processing by the server, such as searching databases, compressing and decompressing multimedia files, etc. These requests require considerable processor and disk I/O resources. .


For static documents, each service process occupies roughly the same system resources, so the number of processes can be used to represent the system load. The dynamic document service requires additional processing, which occupies more system resources than processing static requests, so it needs to be represented by a weight. Such a simplest server load expression formula is:

where L is the load of the server, Ns is the number of static document service processes, Nd is the number of dynamic document service processes, and a is the relative number of each dynamic document service For the weight of static document service, you can choose between 10 and 100.

The limitation of server hardware is not considered in this formula. When the hardware limit is reached, the load of the server will increase significantly due to resource constraints. For example, due to the limitation of server memory size, some processes must be swapped to the hard disk, causing the system load to increase rapidly.Taking into account the system hardware limitations, the server load can be expressed as:

The newly added parameter Ll represents the limit of the normal load of the server, which should be set according to the hardware capabilities of each server itself. And b represents the weight used to limit the allocation of server tasks when the normal load is exceeded. It should be set to a value greater than Ll to represent the effect of hardware limitations. Usually in a server cluster, the weight of the server with worse hardware settings should be set larger to avoid that when all servers are overloaded, the server with the worst hardware will have the highest load. Therefore, b is inversely proportional to the hardware limit Ll of this server, so b can be set as:

Llmax is the Ll value of the server with the highest hardware configuration in the server cluster. After the load of each server is determined, the central server that controls load distribution can correctly distribute the load to the idlest server, thus preventing uneven load distribution like other load distribution strategies.


3. Implementation method and experimental results

Our server system consists of multiple FreeBSD systems connected using Fast Ethernet. Each backend server runs a daemon process to dynamically obtain its own load status, and the central control gateway implemented using FreeBSD refreshes the load of each server through these daemon processes to perform correct load distribution.

3.1 Gateway that supports load balancing

Under the FreeBSD system, the divert interface is provided to support network address translation capabilities. IP data packets are sent to the divert interface through the ipfw filtering function of the system kernel, so that the external daemon natd can receive the original data packets, process them, and then send them back to the system kernel for normal IP distribution [5].

Therefore, according to the address translation structure of FreeBSD, you can create your own network address translation daemon to support the load balancing function, so that the FreeBSD system can be used as a gateway that supports load balancing. Because it is implemented in software, it can easily support non-standard protocols and apply optimized load balancing strategies, and has great flexibility.

3.2 Experiments and Analysis

To test the usability of this implementation, we conducted our test experiments on the most common HTTP protocols. In order to distinguish different request types, three different types of tests were designed to test different aspects of performance.



Dynamic document generated by CGI program: used to test the load balancing status of the server's processing capabilities.


Small static document: Use a smaller static document to test the load balancing status under frequent connections;


Large static document: Use a larger document , test the load balancing status of disk and network I/O;


The test results are based on the performance of a single server completing requests per second, showing the types of load balancing per second when using multiple servers The ratio of completed requests to the baseline number of requests.



Figure 1: Load balancing performance



The first curve a in the above figure is for processing dynamic document requests. As the number of servers increases, its performance increases exponentially; while the second curve b is for processing small-size static document requests, the performance improvement is not obvious when using three servers; while processing large-size static document requests The third curve c has almost no performance change. In order to find the reason why the load balancing system cannot reach the ideal state, we examined the utilization of server resources:

Table 1. Utilization of server resources


Processing type
Load Balancing Gateway
Server 1
Server 2
Server 3

a
53%
97%
95%
98%

b
76%
43%
39%
41%

c
94%
32%
31%
35%




As can be seen from this table, when processing dynamic document a, all three servers are running at full speed and the load is evenly distributed. This is an ideal state. When processing static document types b and c, although the load is evenly distributed among the three servers, each server is not running at full speed. Especially when processing large-size documents, the natd process in the load balancing device occupies most of the processing resources. Since all network traffic must be converted through it, the load on the natd process increases when the number of network traffic and concurrent connections is considerable. When using different numbers of backend servers in the experiment, the actual network bandwidth flowing through the load balancing gateway is:

Table 2: Bandwidth of the server cluster when serving large-size documents


servers Quantity
1 unit
2 units
3 units

Network speed (Kb/s)
10042.14
11015.10
11442.67




It can be seen that the bandwidth is limited to about 10MB/s. Obviously this is the bandwidth limit of the load balancing process used in this test. In fact, the program uses a linked list to maintain the status of network address translation, which greatly limits Its network performance can be further improved by improving hardware performance and improving algorithms.


4. Discussion

As can be seen from the above experiment, the load balancer based on network address translation can effectively solve the CPU and disk I/O load on the server side. However, The performance of the load balancer itself is limited by network I/O and has certain bandwidth limitations under certain hardware conditions. However, this bandwidth limit can be increased by improving the algorithm and improving the performance of the hardware running the load balancing program. It can also be seen that different service types occupy different server resources. The load measurement strategy we use is to use the same load for evaluation, which is suitable for most conditions. However, the best way is to target different Resources, such as CPU, disk I/O or network I/O, monitor server load respectively, and the central controller selects the most appropriate server to distribute customer requests. Our future work will start from these two aspects to improve this load balancing controller.


References:


[1] E.Kata, M.Butler, and R. McGrath. A scalable HTTP server: the ncsa prototype. Computer Networks and ISDN systems. 1994. Vol 27, P155-164

[2] Ralf S.Engelschall. Load Balancing Your Web Site. Web Techniques Magazine (http://www.WebTechniques.com), May 1998. vol. 3, iss.5

[3] CICSO. LocalDirector Documents. http://www.cisco.com, 1997

[4] H.Zhu. T.Yang, Q.Zheng , D.Watson, O.H.Ibarra, andT.Smith, Adaptive load sharing for clustered digital library servers. Technical Report, CS, UCSB, 1998.

[5] FreeBSD core team. natd and divert manual pages. http ://www.freebsd.org. 1995



Implement a load balancing gateway by NAT


Wang, Bo

NongYe Road 70 , ZhengZhou, 450002, P.R.China

wb@email.online.ha.cn


Abstract: This paper investigates load balancing techniques and strategies, and implements a load balancing gateway based NAT for our Internet servers. The Internet servers involve the high load of CPU and I/O by simultaneous access requests, the symmetrical clustered servers can distribute the server load to solve the problem. To balance the load in the best way, the gateway distributes the load according to the status of server's CPU and I/O. The gateway must monitor every server's load and apply the best scheme to deliver every request, so it can provide the high performance for Internet services.

Keywords: load balancing, NAT, FreeBSD

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316165.htmlTechArticleAbstract: This article explores the load balancing technology and load distribution strategy used by distributed network servers, and based on network addresses Conversion implements a load balancing gateway on FreeBSD, applied to me...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

Practical tips for converting full-width English letters into half-width form Practical tips for converting full-width English letters into half-width form Mar 26, 2024 am 09:54 AM

Practical tips for converting full-width English letters into half-width forms. In modern life, we often come into contact with English letters, and we often need to input English letters when using computers, mobile phones and other devices. However, sometimes we encounter full-width English letters, and we need to use the half-width form. So, how to convert full-width English letters to half-width form? Here are some practical tips for you. First of all, full-width English letters and numbers refer to characters that occupy a full-width position in the input method, while half-width English letters and numbers occupy a full-width position.

What's going on when the network can't connect to the wifi? What's going on when the network can't connect to the wifi? Apr 03, 2024 pm 12:11 PM

1. Check the wifi password: Make sure the wifi password you entered is correct and pay attention to case sensitivity. 2. Confirm whether the wifi is working properly: Check whether the wifi router is running normally. You can connect other devices to the same router to determine whether the problem lies with the device. 3. Restart the device and router: Sometimes, there is a malfunction or network problem with the device or router, and restarting the device and router may solve the problem. 4. Check the device settings: Make sure the wireless function of the device is turned on and the wifi function is not disabled.

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

How to use Xiaomi Auto app How to use Xiaomi Auto app Apr 01, 2024 pm 09:19 PM

Xiaomi car software provides remote car control functions, allowing users to remotely control the vehicle through mobile phones or computers, such as opening and closing the vehicle's doors and windows, starting the engine, controlling the vehicle's air conditioner and audio, etc. The following is the use and content of this software, let's learn about it together . Comprehensive list of Xiaomi Auto app functions and usage methods 1. The Xiaomi Auto app was launched on the Apple AppStore on March 25, and can now be downloaded from the app store on Android phones; Car purchase: Learn about the core highlights and technical parameters of Xiaomi Auto, and make an appointment for a test drive. Configure and order your Xiaomi car, and support online processing of car pickup to-do items. 3. Community: Understand Xiaomi Auto brand information, exchange car experience, and share wonderful car life; 4. Car control: The mobile phone is the remote control, remote control, real-time security, easy

See all articles